Commit Graph

22220 Commits

Author SHA1 Message Date
Oli Scherer
1ab14ea7c2 Remove some unnecessary tcx-passing 2023-02-20 15:28:59 +00:00
Oli Scherer
acbcfaaf7b Stop passing in values that one can also get from the tcx lazily 2023-02-20 15:28:59 +00:00
Oli Scherer
c3522d0637 Move the resolver into a query 2023-02-20 15:28:59 +00:00
Oli Scherer
37e2f4f487 Make configure_and_expand "infalllible" by just aborting the compilation if it fails instead of bubbling out an error 2023-02-20 15:28:59 +00:00
Oli Scherer
63c8d00090 Use tcx queries instead of passing the values to configure_and_expand. 2023-02-20 15:28:59 +00:00
Oli Scherer
1202fce40e Remove definitions field that is only needed for one method 2023-02-20 15:28:59 +00:00
Oli Scherer
4953d70e2f Stuff a TyCtxt into the Resolver 2023-02-20 15:28:59 +00:00
Oli Scherer
9fb91b8742 Remove a redundant function argument 2023-02-20 15:28:58 +00:00
Oli Scherer
8f132d8549 Run the resolver after TyCtxt construction 2023-02-20 15:28:58 +00:00
Oli Scherer
6924e3c374 Make untracked.source_span lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Oli Scherer
ade3dceb38 Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Oli Scherer
054c76d658 Revert most of the custom place computation, it was unnecessary. 2023-02-20 14:56:44 +00:00
Oli Scherer
82f1e341a3 Remove commented out code 2023-02-20 14:11:38 +00:00
Oli Scherer
472059d854 Deduplicate some logic between dyn* and dyn 2023-02-20 14:11:38 +00:00
Ralf Jung
b2f58146b9 basic dyn* support for Miri 2023-02-20 15:08:05 +01:00
Matthias Krüger
e4dadd6416
Rollup merge of #108265 - lcnr:cg-error-msg, r=BoxyUwU
"`const` generic" -> "const parameter"
2023-02-20 14:32:56 +01:00
Matthias Krüger
133afeb6e3
Rollup merge of #108259 - fee1-dead-contrib:fixme-2, r=TaKO8Ki
remove FIXME that doesn't require fixing
2023-02-20 14:32:55 +01:00
Matthias Krüger
226ce31edd
Rollup merge of #108200 - jhpratt:restricted-damerau-levenshtein-distance, r=tmiasko
Use restricted Damerau-Levenshtein distance for diagnostics

This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a _restricted_ implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account.

This was first brought up [on IRLO](https://internals.rust-lang.org/t/18227) when it was noticed that the diagnostic for `prinltn!` (transposed L and T) was `print!` and not `println!`. Only a single existing UI test was effected, with the result being an objective improvement.

~~I have left the method name and various other references to the Levenshtein algorithm untouched, as the exact manner in which the edit distance is calculated should not be relevant to the caller.~~

r? ``@estebank``

``@rustbot`` label +A-diagnostics +C-enhancement
2023-02-20 14:32:55 +01:00
bors
267cd1d2c5 Auto merge of #107721 - megakorre:issue_105700, r=petrochenkov
create dummy placeholder crate to prevent compiler from panicing

This PR is to address the panic found in https://github.com/rust-lang/rust/issues/105700.

There are 2 separate things going on with this panic.
First the code could not generate a dummy response for crate fragment types when it hits the recursion limit.
This PR adds the method to the trait implementation for `DymmyResult` to be able to create a dummy crate node.
This stops the panic from happening.

The second thing that is not addressed (and maybe does not need addressing? 🤷🏻)
is that when you have multiple attributes it ends up treating attributes that follow another as being the result of expanding the former (maybe there is a better way to say that). So you end up hitting the recursion limit. Even though you would think there is no expansion happening here.

If you did not hit the recursion limit the compiler would output that `invalid_attribute` does not exists. But it currently exits before the resolution step when the recursion limit is reached here.
2023-02-20 13:23:47 +00:00
lcnr
2cbe583593 const generic -> const parameter in err msg 2023-02-20 12:58:11 +01:00
Oli Scherer
e8e227aec8 Prepare crate loader for LockGuard 2023-02-20 10:49:42 +00:00
Oli Scherer
d191de63f0 Prepare for adding a TyCtxt to Resolver 2023-02-20 10:38:48 +00:00
bors
e7eaed21d5 Auto merge of #107969 - b-naber:proj-relate-variance, r=lcnr
Use covariance on type relations of field projection types if possible

It's fine to use covariance here unless we're in a mutating context.

Fixes https://github.com/rust-lang/rust/issues/96514

Supersedes https://github.com/rust-lang/rust/pull/105958

r? `@lcnr`
2023-02-20 09:25:51 +00:00
Patrik Kårlin
0fd2a70b90
create dummy placeholder crate to prevent compiler 2023-02-20 10:20:57 +01:00
Deadbeef
be599f3cbe remove FIXME that doesn't require fixing 2023-02-20 06:31:26 +00:00
Deadbeef
255eb217e9 Remove old FIXME that no longer applies
it looks like Encodable was fallible at some point, but that was changed
which means that this FIXME is no longer applicable
2023-02-20 06:26:28 +00:00
Deadbeef
6b36c3078a Remove old FIXMEs referring to #19596 2023-02-20 06:12:56 +00:00
Nathan Fenner
fbcca2aaf0 Refine error span for trait error into borrowed expression 2023-02-19 21:27:04 -08:00
bors
7b552967b8 Auto merge of #105961 - fmease:iat-type-directed-probing, r=jackh726
Type-directed probing for inherent associated types

When probing for inherent associated types (IATs), equate the Self-type found in the projection with the Self-type of the relevant inherent impl blocks and check if all predicates are satisfied.
Previously, we didn't look at the Self-type or at the bounds and just picked the first inherent impl block containing an associated type with the name we were searching for which is obviously incorrect.

Regarding the implementation, I basically copied what we do during method probing (`assemble_inherent_impl_probe`, `consider_probe`). Unfortunately, I had to duplicate a lot of the diagnostic code found in `rustc_hir_typeck::method::suggest` which we don't have access to in `rustc_hir_analysis`. Not sure if there is a simple way to unify the error handling. Note that in the future, `rustc_hir_analysis::astconv` might not actually be the place where we resolve inherent associated types (see https://github.com/rust-lang/rust/pull/103621#issuecomment-1304309565) but `rustc_hir_typeck` (?) in which case the duplication may naturally just disappear. While inherent associated *constants* are currently resolved during "method" probing, I did not find a straightforward way to incorporate IAT lookup into it as types and values (functions & constants) are two separate entities for which distinct code paths are taken.

Fixes #104251 (incl. https://github.com/rust-lang/rust/issues/104251#issuecomment-1338501171).
Fixes #105305.
Fixes #107468.

`@rustbot` label T-types F-inherent_associated_types
r? types
2023-02-20 00:37:20 +00:00
Jacob Pratt
ab4c0dd137
Add test for precise algorithm used 2023-02-19 22:59:22 +00:00
b-naber
0725d0ceee add some cfgs back 2023-02-19 22:24:18 +00:00
b-naber
aefc5ec110 remove cfgs 2023-02-19 22:16:22 +00:00
b-naber
2d2bccf751 rebase 2023-02-19 22:13:07 +00:00
b-naber
46bd77aa80 some conditional imports 2023-02-19 22:12:12 +00:00
b-naber
e2bf960fe1 sccs info 2023-02-19 22:12:12 +00:00
b-naber
960ebaf899 collect existentials and placeholders 2023-02-19 22:12:09 +00:00
b-naber
2f79f73821 collect region contexts during mir renumbering 2023-02-19 22:11:27 +00:00
b-naber
cb35a7b481 add BorrowckInferCtxt 2023-02-19 22:07:17 +00:00
León Orell Valerian Liehr
f2253dad24
Add some FIXMEs for follow-up PRs 2023-02-19 22:54:47 +01:00
León Orell Valerian Liehr
00b976a138
Collect fulfillment errors across impls 2023-02-19 22:54:08 +01:00
bors
21e5b941e0 Auto merge of #108128 - clubby789:builtin-derived-attr, r=jackh726
Properly check for builtin derived code

Fixes #108122
2023-02-19 21:18:07 +00:00
bors
7aa413d592 Auto merge of #107921 - cjgillot:codegen-overflow-check, r=tmiasko
Make codegen choose whether to emit overflow checks

ConstProp and DataflowConstProp currently have a specific code path not to propagate constants when they overflow. This is meant to have the correct behaviour when inlining from a crate with overflow checks (like `core`) into a crate compiled without.

This PR shifts the behaviour change to the `Assert(Overflow*)` MIR terminators: if the crate is compiled without overflow checks, just skip emitting the assertions. This is already what happens with `OverflowNeg`.

This allows ConstProp and DataflowConstProp to transform `CheckedBinaryOp(Add, u8::MAX, 1)` into `const (0, true)`, and let codegen ignore the `true`.

 The interpreter is modified to conform to this behaviour.

Fixes #35310
2023-02-19 18:17:26 +00:00
León Orell Valerian Liehr
569ca2bad0
Deduplicate fresh_item_substs 2023-02-19 18:36:35 +01:00
León Orell Valerian Liehr
77ea90ec71
Fix substitution bug 2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
6065867a7e
Use InferCtxt::probe to properly detect ambiguous candidates 2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
3dc38fbc91
Switch from for-loop to filter_map 2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
b5e73bfe90
Groundwork for detecting ambiguous candidates
NB: Since we are using the same InferCtxt in each iteration,
we essentially *spoil* the inference variables and we only
ever get at most *one* applicable candidate (only the 1st candidate
has clean variables that can still unify correctly).
2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
cc65ebd0d2
Make use of ObligationCtxt 2023-02-19 18:35:34 +01:00
León Orell Valerian Liehr
aa7edf7073
Use the correct ParamEnv 2023-02-19 18:35:34 +01:00
León Orell Valerian Liehr
488d0c9efd
Type-directed probing for inherent associated types 2023-02-19 18:35:28 +01:00
Santiago Pastorino
5e763b6624
Document associated_item methods 2023-02-19 11:58:48 -03:00
Santiago Pastorino
45b0d9da6b
Make associated_items_for_impl_trait_in_trait handle impl traits on impls 2023-02-19 11:57:38 -03:00
Santiago Pastorino
b7dd609d9c
Add associated_item_for_impl_trait_in_trait query 2023-02-19 11:49:02 -03:00
Santiago Pastorino
4e703a2772
Add associated_items_for_impl_trait_in_trait query 2023-02-19 11:18:56 -03:00
Guillaume Gomez
d2aef58eb5
Rollup merge of #108203 - compiler-errors:rpitit-fix-defaults-2, r=jackh726
Fix RPITITs in default trait methods (by assuming projection predicates in param-env)

Instead of having special projection logic that allows us to turn `ProjectionTy(RPITIT, [Self#0, ...])` into `OpaqueTy(RPITIT, [Self#0, ...])`, we can instead augment the param-env of default trait method bodies to assume these as projection predicates. This should allow us to only project where we're allowed to!

In order to make this work without introducing a bunch of cycle errors, we additionally tweak the `OpaqueTypeExpander` used by `ParamEnv::with_reveal_all_normalized` to not normalize the right-hand side of projection predicates. This should be fine, because if we use the projection predicate to normalize some other projection type, we'll continue to normalize the opaque that it gets projected to.

This also makes it possible to support default trait methods with RPITITs in an associated-type based RPITIT lowering strategy without too much extra effort.

Fixes #107002
Alternative to #108142
2023-02-19 14:47:56 +01:00
Guillaume Gomez
bd63edc07a
Rollup merge of #108129 - GuillaumeGomez:correctly-handle-links-starting-with-whitespace, r=petrochenkov
Correctly handle links starting with whitespace

Part of https://github.com/rust-lang/rust/issues/107995.

I just got this issue, wrote a fix and then saw the issue. So here's the PR. ^^'

r? `@petrochenkov`
2023-02-19 14:47:55 +01:00
bors
eebdfb55fc Auto merge of #108228 - Dylan-DPC:rollup-i9t13qu, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #104659 (reflow the stack size story)
 - #106933 (Update documentation of select_nth_unstable and select_nth_unstable_by to state O(n^2) complexity)
 - #107783 (rustdoc: simplify DOM for `.item-table`)
 - #107951 (resolve: Fix doc links referring to other crates when documenting proc macro crates directly)
 - #108130 ("Basic usage" is redundant for there is just one example)
 - #108146 (rustdoc: hide `reference` methods in search index)
 - #108189 (Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-19 08:15:40 +00:00
Dylan DPC
c5d5c57666
Rollup merge of #108189 - compiler-errors:non_lifetime_binders-bound-stuff, r=jackh726
Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds

1. When assembling candidates for `for<T> T: Sized`, we can't ICE because the self-type is a bound type.
2. Fix an issue where, when canonicalizing in non-universe preserving mode, we don't actually set the universe for placeholders to the root even though we do the same for region vars.
3. Make `Placeholder("T")` format like `T` in error messages.

Fixes #108180
Fixes #108182

r? types
2023-02-19 13:03:42 +05:30
Dylan DPC
4a0f088f7c
Rollup merge of #107951 - petrochenkov:procmacdoc, r=jackh726
resolve: Fix doc links referring to other crates when documenting proc macro crates directly

Fixes https://github.com/rust-lang/rust/issues/107950
2023-02-19 13:03:41 +05:30
bors
73f40197ec Auto merge of #107772 - compiler-errors:dyn-star-backend-is-ptr, r=eholk
Make `dyn*`'s value backend type a pointer

One tweak on top of Ralf's commit should fix using `usize` as a `dyn*`-coercible type, and should fix when we're using various other pointer types when LLVM opaque pointers is disabled.

r? `@eholk` but feel free to reassign
cc https://github.com/rust-lang/rust/pull/107728#issuecomment-1421231823 `@RalfJung`
2023-02-19 05:35:03 +00:00
Jacob Pratt
20282c1b20
Reduce limit on macro_rules! diagnostic 2023-02-19 04:17:58 +00:00
Jacob Pratt
378c4ab9ab
Make public API, docs algorithm-agnostic 2023-02-19 04:11:10 +00:00
Jacob Pratt
ff052eec80
Use restricted Damerau-Levenshtein algorithm 2023-02-19 03:46:03 +00:00
bors
fcdbd1c07f Auto merge of #107867 - compiler-errors:new-solver-fn-trait-safety, r=lcnr
Check that built-in callable types validate their output type is `Sized` (in new solver)

Working on parity with old solver. Putting this up for consideration, it's not *really* needed or anything just yet. Maybe it's better to approach this from another direction (like always checking the item bounds when calling `consider_assumption`? we may need that for coinduction to be sound though?)

This basically implements #100096 for the new solver.
2023-02-19 02:42:10 +00:00
bors
f77f4d55bd Auto merge of #107542 - compiler-errors:param-envs-with-inference-vars-are-cursed, r=jackh726
Don't call `with_reveal_all_normalized` in const-eval when `param_env` has inference vars in it

**what:** This slightly shifts the order of operations from an existing hack:

5b6ed253c4/compiler/rustc_middle/src/ty/consts/kind.rs (L225-L230)

in order to avoid calling a tcx query (`TyCtxt::reveal_opaque_types_in_bounds`, via `ParamEnv::with_reveal_all_normalized`) when a param-env has inference variables in it.

**why:** This allows us to enable fingerprinting of query keys/values outside of incr-comp in deubg mode, to make sure we catch other places where we're passing infer vars and other bad things into query keys. Currently that (bbf33836b9) crashes because we introduce inference vars into a param-env in the blanket-impl finder in rustdoc 😓

5b6ed253c4/src/librustdoc/clean/blanket_impl.rs (L43)

See the CI failure here: https://github.com/rust-lang/rust/actions/runs/4058194838/jobs/6984834619
2023-02-18 23:43:42 +00:00
Guillaume Gomez
fd62036caa Correctly handle if a link starts with a whitespace 2023-02-18 23:24:58 +01:00
Camille GILLOT
9f6c1df872 Stop implementing _with_overflow intrinsics in codegen backends. 2023-02-18 22:06:29 +00:00
Camille GILLOT
7e795bdf03 Replace _with_overflow instrinsics in LowerIntrinsics. 2023-02-18 21:45:10 +00:00
Camille GILLOT
f79db59953 Adapt cg_clif. 2023-02-18 21:35:02 +00:00
Camille GILLOT
c1a0f8205c Rename checked_binop_checks_overflow. 2023-02-18 21:35:02 +00:00
Camille GILLOT
a5769193d1 Remove special case in rvalue codegen. 2023-02-18 21:35:02 +00:00
Camille GILLOT
e9c73ea502 Make name more explicit. 2023-02-18 21:35:02 +00:00
Camille GILLOT
4f13aa7f46 Comment codegen optimization. 2023-02-18 21:35:02 +00:00
Camille Gillot
328696ca17 Update compiler/rustc_middle/src/mir/syntax.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-02-18 21:35:02 +00:00
Camille GILLOT
fb1f7f747a Remove exception from MIR doc. 2023-02-18 21:35:02 +00:00
Camille GILLOT
085eaa7ee3 Adapt interpreter. 2023-02-18 21:35:02 +00:00
Camille GILLOT
7f36a3fcd7 Fix CTFE interpreter. 2023-02-18 21:35:02 +00:00
Camille GILLOT
4c93145b33 Remove outdated comment. 2023-02-18 21:35:02 +00:00
Camille GILLOT
7567f1f31d Adapt interpreter. 2023-02-18 21:35:02 +00:00
Camille GILLOT
1480b1c524 Correct comment. 2023-02-18 21:35:02 +00:00
Camille GILLOT
d0cc00f758 Add comment. 2023-02-18 21:35:02 +00:00
Camille GILLOT
e34caaf42d Remove overflow checks from ConstProp. 2023-02-18 21:35:02 +00:00
Camille GILLOT
4bd2ebc58b Do not codegen overflow check when not required. 2023-02-18 21:35:02 +00:00
Michael Goulet
d42a3fbd69 Assume we can normalize trait default method RPITITs in param-env instead 2023-02-18 20:36:39 +00:00
Michael Goulet
c13d5f1aeb Make sure test_type_match doesn't ICE with late-bound types 2023-02-18 20:16:51 +00:00
Michael Goulet
6f3706ea71 Pretty placeholders using their names 2023-02-18 19:49:40 +00:00
Michael Goulet
ec40b1a393 Collapse placeholders to root universe in canonicalizer if not preserving universes 2023-02-18 19:49:40 +00:00
Michael Goulet
f4a4a31479 Don't ICE on bound types in sized conditions 2023-02-18 19:49:40 +00:00
Michael Goulet
7f798c2b21 Emit the right types for vtable pointers when dropping dyn* 2023-02-18 19:47:34 +00:00
Michael Goulet
e82cc656c8 Make dyn* have the same scalar pair ABI as corresponding fat pointer 2023-02-18 19:47:34 +00:00
Michael Goulet
df52e2037a Use inttoptr to support usize as dyn* value, use pointercast to make sure pointers are compatible 2023-02-18 19:47:33 +00:00
Michael Goulet
6402c98621 Add consider_implied_clause 2023-02-18 19:45:02 +00:00
Michael Goulet
82b52056fe Check that built-in callable types validate their output type is Sized (in new solver) 2023-02-18 19:32:58 +00:00
Michael Goulet
be55ad53a1 Remove default trait RPITIT candidates 2023-02-18 19:25:07 +00:00
Ralf Jung
88e39ee314 make first component of dyn* use pointer layout+type, and adjust DynStar comment 2023-02-18 19:24:55 +00:00
y21
0610df9314 lint: don't suggest assume_init for uninhabited types 2023-02-18 19:05:44 +01:00
bors
53709aedba Auto merge of #108209 - petrochenkov:doclean, r=notriddle
rustdoc: Cleanup doc link extraction
2023-02-18 16:41:55 +00:00
Matthias Krüger
6c91efd6d7
Rollup merge of #108205 - tshepang:why-special-case, r=cjgillot
link to llvm changes that prompted the special cases
2023-02-18 13:26:48 +01:00
Matthias Krüger
d3d5163921
Rollup merge of #108186 - compiler-errors:closures-with-late-bound-types-r-bad, r=cjgillot
Deny non-lifetime bound vars in `for<..> ||` closure binders

Moves the check for illegal bound var types from astconv to resolve_bound_vars. If a binder is defined to have a type or const late-bound var that's not allowed, we'll resolve any usages to ty error or const error values, so we shouldn't ever see late-bound types or consts in places they aren't expected.

Fixes #108184
Fixes #108181
Fixes #108192
2023-02-18 13:26:47 +01:00
Matthias Krüger
7f9d9de82d
Rollup merge of #108162 - clubby789:issue-108155, r=Nilstrieb
Don't eagerly convert principal to string

Fixes #108155

~~I haven't yet been able to reproduce the ICE in a minimal example unfortunately.~~ Added a test
2023-02-18 13:26:47 +01:00