about summary refs log tree commit diff
path: root/compiler/rustc_infer
AgeCommit message (Collapse)AuthorLines
2024-05-24Remove `DefId` from `EarlyParamRegion` (tedium/diagnostics)Boxy-60/+182
2024-05-24Revert "Rollup merge of #123979 - oli-obk:define_opaque_types7, ↵Oli Scherer-15/+2
r=compiler-errors" This reverts commit f939d1ff4820844595d0f50f94038869f1445d08, reversing changes made to 183c706305d8c4e0ccb0967932381baf7e0c3611.
2024-05-24Use regular type equating instead of a custom queryOli Scherer-29/+7
2024-05-24Fail relating constants of different typesOli Scherer-8/+5
2024-05-23Rollup merge of #125210 - fmease:fix-up-some-diags, r=davidtwcoMatthias Krüger-2/+2
Cleanup: Fix up some diagnostics Several diagnostics contained their error code inside their primary message which is no bueno. This PR moves them out of the message and turns them into structured error codes. Also fixes another occurrence of `->` after a selector in a Fluent message which is not correct. I've fixed two other instances of this issue in #104345 (2022) but didn't update all instances as I've noted here: https://github.com/rust-lang/rust/pull/104345#issuecomment-1312705977 (“the future is now!”).
2024-05-23Handle `ReVar` in `note_and_explain_region`.Nicholas Nethercote-1/+4
PR #124918 made this path abort. The added test, from fuzzing, identified that it is reachable.
2024-05-22Cleanup: Fix up some diagnosticsLeón Orell Valerian Liehr-2/+2
2024-05-21Uplift OutlivesPredicate, remove a bunch of unnecessary associated types ↵Michael Goulet-5/+4
from Interner
2024-05-21Auto merge of #125284 - compiler-errors:uplift-misc, r=lcnrbors-98/+27
Uplift `RegionVid`, `TermKind` to `rustc_type_ir`, and `EagerResolver` to `rustc_next_trait_solver` - Uplift `RegionVid`. This was complicated due to the fact that we implement `polonius_engine::Atom` for `RegionVid` -- but I just separated that into `PoloniusRegionVid`, and added `From`/`Into` impls so it can be defined in `rustc_borrowck` separately. Coherence 😵 - Change `InferCtxtLike` to expose `opportunistically_resolve_{ty,ct,lt,int,float}_var` so that we can uplift `EagerResolver` for use in the canonicalization methods. - Uplift `TermKind` much like `GenericArgKind` All of this is miscellaneous dependencies for making more `EvalCtxt` methods generic.
2024-05-20Rework var resolution in InferCtxtLike, uplift EagerResolverMichael Goulet-98/+27
2024-05-20Rollup merge of #124682 - estebank:issue-40990, r=pnkfelixMatthias Krüger-35/+131
Suggest setting lifetime in borrowck error involving types with elided lifetimes ``` error: lifetime may not live long enough --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5 | LL | fn foo(mut x: Ref, y: Ref) { | ----- - has type `Ref<'_, '1>` | | | has type `Ref<'_, '2>` LL | x.b = y.b; | ^^^^^^^^^ assignment requires that `'1` must outlive `'2` | help: consider introducing a named lifetime parameter | LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) { | ++++ ++++++++ ++++++++ ``` As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following ``` help: consider introducing a named lifetime parameter | LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) { | ++++ ++++++++ ++++++++ ``` but I believe this to still be an improvement over the status quo. Fix #40990.
2024-05-19Auto merge of #125230 - compiler-errors:uplift-query-stuff, r=lcnrbors-9/+21
Uplift more query stuff - Uplift various query input/response internals - Uplift the `ProofTree` structures and make the `ProofTreeBuilder` stuff (mostly) generic over `Interner` - Stop using `TyCtxt::def_kind` in favor of `AliasTerm::kind` r? lcnr
2024-05-18Uplift GenericArgKind, CanonicalVarValues, QueryInputMichael Goulet-9/+21
and make NestedGoals generic
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-9/+7
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18(Mostly) revert "Account for type param from other item in `note_and_explain`"Michael Goulet-62/+43
This mostly reverts commit 7449478c2f6fd2d72c12a51d8562f1e6108facab. It also removes an `opt_param_at` that really is unnecessary given our ICE policy for malformed intrinsics.
2024-05-17Rename Unsafe to SafetySantiago Pastorino-9/+7
2024-05-17Detect when a lifetime is being reused in suggestionEsteban Küber-1/+5
2024-05-17Tweak suggested lifetimes to modify return type instead of `&self` receiverEsteban Küber-2/+8
Do not suggest constraining the `&self` param, but rather the return type. If that is wrong (because it is not sufficient), a follow up error will tell the user to fix it. This way we lower the chances of *over* constraining, but still get the cake of "correctly" contrained in two steps. This is a correct suggestion: ``` error: lifetime may not live long enough --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:9:9 | LL | fn foo<'a>(&self, x: &i32) -> &i32 { | - - let's call the lifetime of this reference `'1` | | | let's call the lifetime of this reference `'2` LL | x | ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | LL | fn foo<'a>(&self, x: &'a i32) -> &'a i32 { | ++ ++ ``` While this is incomplete because it should suggestino `&'a self` ``` error: lifetime may not live long enough --> $DIR/ex3-both-anon-regions-self-is-anon.rs:7:19 | LL | fn foo<'a>(&self, x: &Foo) -> &Foo { | - - let's call the lifetime of this reference `'1` | | | let's call the lifetime of this reference `'2` LL | if true { x } else { self } | ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | LL | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo { | ++ ++ ``` but the follow up error is ``` error: lifetime may not live long enough --> tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:7:30 | 6 | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo { | -- - let's call the lifetime of this reference `'1` | | | lifetime `'a` defined here 7 | if true { x } else { self } | ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | 6 | fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo { | ++ ```
2024-05-17Account for owning item lifetimes in suggestion and annotate tests as ↵Esteban Küber-3/+39
`run-rustfix` ``` error: lifetime may not live long enough --> $DIR/lt-ref-self.rs:12:9 | LL | fn ref_self(&self, f: &u32) -> &u32 { | - - let's call the lifetime of this reference `'1` | | | let's call the lifetime of this reference `'2` LL | f | ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | LL | fn ref_self<'b>(&'b self, f: &'b u32) -> &'b u32 { | ++++ ++ ++ ++ ```
2024-05-17Always constrain the return type in lifetime suggestionEsteban Küber-0/+5
``` error: lifetime may not live long enough --> f205.rs:8:16 | 7 | fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> { | - --------- has type `Option<Reference<'1>>` | | | let's call the lifetime of this reference `'2` 8 | return reference; | ^^^^^^^^^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter | 7 | fn resolve_symbolic_reference<'a>(&'a self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> { | ++++ ++ ++++ ++++ ``` The correct suggestion would be ``` help: consider introducing a named lifetime parameter | 7 | fn resolve_symbolic_reference<'a>(&self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> { | ++++ ++++ ++++ ``` but we are not doing the analysis to detect that yet. If we constrain `&'a self`, then the return type with a borrow will implicitly take its lifetime from `'a`, it is better to make it explicit in the suggestion, in case that `&self` *doesn't* need to be `'a`, but the return does.
2024-05-17Suggest setting lifetime in borrowck error involving types with elided lifetimesEsteban Küber-30/+75
``` error: lifetime may not live long enough --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5 | LL | fn foo(mut x: Ref, y: Ref) { | ----- - has type `Ref<'_, '1>` | | | has type `Ref<'_, '2>` LL | x.b = y.b; | ^^^^^^^^^ assignment requires that `'1` must outlive `'2` | help: consider introducing a named lifetime parameter | LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) { | ++++ ++++++++ ++++++++ ``` As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following ``` help: consider introducing a named lifetime parameter | LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) { | ++++ ++++++++ ++++++++ ``` but I believe this to still be an improvement over the status quo. CC #40990.
2024-05-17to_opt_poly_X_pred -> as_X_clauseMichael Goulet-1/+1
2024-05-16Remove trivial Binder::dummy callsMichael Goulet-1/+1
2024-05-16Uplift Goal to rustc_type_irMichael Goulet-11/+15
2024-05-16Make P parameter explicitMichael Goulet-8/+21
2024-05-16Rename ToPredicate for UpcastMichael Goulet-25/+21
2024-05-13Auto merge of #125076 - compiler-errors:alias-term, r=lcnrbors-23/+36
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
2024-05-13Apply nitsMichael Goulet-5/+8
2024-05-13split out AliasTy -> AliasTermMichael Goulet-18/+28
2024-05-13Remove `extern crate rustc_middle` from `rustc_infer`.Nicholas Nethercote-2/+21
2024-05-11Consolidate obligation cause codes for where clausesMichael Goulet-15/+25
2024-05-10Auto merge of #124982 - compiler-errors:uplift-trait-ref, r=lcnrbors-2/+2
Uplift `TraitRef` into `rustc_type_ir` Emotional rollercoaster r? lcnr
2024-05-10Lift `TraitRef` into `rustc_type_ir`Michael Goulet-2/+2
2024-05-10Name tweaksMichael Goulet-15/+15
2024-05-10More rename falloutMichael Goulet-17/+22
2024-05-10Rename some ObligationCauseCode variantsMichael Goulet-52/+43
2024-05-10Remove glob imports for ObligationCauseCodeMichael Goulet-62/+81
2024-05-10rename some variants in FulfillmentErrorCodeMichael Goulet-12/+12
2024-05-10Auto merge of #124961 - matthiaskrgr:rollup-1jj65p6, r=matthiaskrgrbors-119/+60
Rollup of 7 pull requests Successful merges: - #124551 (Add benchmarks for `impl Debug for str`) - #124915 (`rustc_target` cleanups) - #124918 (Eliminate some `FIXME(lcnr)` comments) - #124927 (opt-dist: use xz2 instead of xz crate) - #124936 (analyse visitor: build proof tree in probe) - #124943 (always use `GenericArgsRef`) - #124955 (Use fewer origins when creating type variables.) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-10Rollup merge of #124955 - nnethercote:next_ty_var, r=lcnrMatthias Krüger-103/+54
Use fewer origins when creating type variables. To reduce lots of repetitive boilerplate code. Details in the individual commit messages. r? ``@lcnr``
2024-05-09Rename Generics::params to Generics::own_paramsMichael Goulet-2/+2
2024-05-10Fix out-of-date comment.Nicholas Nethercote-2/+2
The type name has changed.
2024-05-10Use fewer origins when creating type variables.Nicholas Nethercote-83/+45
`InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements.
2024-05-10Inline and remove unused methods.Nicholas Nethercote-24/+13
`InferCtxt::next_{ty,const,int,float}_var_id` each have a single call site, in `InferCtt::next_{ty,const,int,float}_var` respectively. The only remaining method that creates a var_id is `InferCtxt::next_ty_var_id_in_universe`, which has one use outside the crate.
2024-05-09Fix up `DescriptionCtx::new`.Nicholas Nethercote-14/+4
The comment mentions that `ReBound` and `ReVar` aren't expected here. Experimentation with the full test suite indicates this is true, and that `ReErased` also doesn't occur. So the commit introduces `bug!` for those cases. (If any of them show up later on, at least we'll have a test case.) The commit also remove the first sentence in the comment. `RePlaceholder` is now handled in the match arm above this comment and nothing is printed for it, so that sentence is just wrong. Furthermore, issue #13998 was closed some time ago.
2024-05-07Rollup merge of #124827 - lcnr:generalize-incomplete, r=compiler-errorsMatthias Krüger-4/+40
generalize hr alias: avoid unconstrainable infer vars fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/108 see inline comments for more details r? `@compiler-errors` cc `@BoxyUwU`
2024-05-07generalize hr alias: avoid unconstrainable infer varslcnr-4/+40
2024-05-06borrowck: more eagerly prepopulate opaqueslcnr-0/+13
2024-05-02Use ObligationCtxt in favor of TraitEngine in many placesMichael Goulet-0/+12
2024-05-01Step bootstrap cfgsMark Rousskov-1/+0