-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add variance-related information to lifetime error messages #85343
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 0ee4fb25d9e8033977fef46a035e5eca3c832ae5 with merge 76be1e69fe41762f3f733a494530f4ea13eaaa20... |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
Queued 76be1e69fe41762f3f733a494530f4ea13eaaa20 with parent eac3c7c, future comparison URL. |
Finished benchmarking try commit (76be1e69fe41762f3f733a494530f4ea13eaaa20): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 1f59727a4560671bb299267a0beb00b7978ae31b with merge a5e251503d529369b35269793fdeed56b46e8561... |
☀️ Try build successful - checks-actions |
Queued a5e251503d529369b35269793fdeed56b46e8561 with parent fe72845, future comparison URL. |
Finished benchmarking try commit (a5e251503d529369b35269793fdeed56b46e8561): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
ty | ||
)); | ||
diag.note("mutable references/pointers are invariant over their type parameter"); | ||
diag.help("See <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diag.help("See <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance"); | |
diag.help("see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it might be even better to join this help with the note above. The length is not ideal, but we can rely on the user's cli reflow for text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to have this message as a distinct 'footer', which gets applied to all variance-related messages.
= help: consider adding the following bound: `'a: 'b` | ||
= note: requirement occurs because of a mutable reference/pointer to &i32 | ||
= note: mutable references/pointers are invariant over their type parameter | ||
= help: See <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we could use the new logic to trigger the existing lifetime bounding help
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure what you mean - are you saying that we would start emitting the 'consider adding the following bound' messages in new places, based on whether or not we have extra variance info available? We currently only add these extra notes in cases where a region error has already occurred, so I don't think that would currently be possible/useful.
This PR is now ready for review. r? @estebank |
☔ The latest upstream changes (presumably #85984) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ |
⌛ Testing commit 4844c4de7c2308788e2f1d186bcccd2d0eb3c60e with merge 52598462a66eeefd6c08837602666a94f4e9f421... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r=estebank |
📌 Commit fad2242 has been approved by |
☀️ Test successful - checks-actions |
This caused a regression in a number of benchmarks in the final merge run, which seems to have been mostly expected based on the PR runs done -- @Aaron1011 did we try to mitigate that? It looks like this is just tracking more information, so presumably the regression is mostly unavoidable? Looks like the most serious regression came from wg-grammar, which is interesting as the PR run reported a net win on that benchmark. It was ~22 days ago, though, so maybe something changed in this PR or on master since then? |
Make `relate_type_and_mut` public rust-lang#85343 improved diagnostics around `Relate` impls but made `relate_type_and_mut` private, which was accessible as `relate` previously. This makes it public so that we can use it on rust-semverver. r? `@Aaron1011`
Make `relate_type_and_mut` public rust-lang#85343 improved diagnostics around `Relate` impls but made `relate_type_and_mut` private, which was accessible as `relate` previously. This makes it public so that we can use it on rust-semverver. r? ``@Aaron1011``
Make `relate_type_and_mut` public rust-lang#85343 improved diagnostics around `Relate` impls but made `relate_type_and_mut` private, which was accessible as `relate` previously. This makes it public so that we can use it on rust-semverver. r? ```@Aaron1011```
I've opened #86670, which addresses some of the performance regressions for this PR. |
Make the lifetime accurate which is used in the region constraints part This PR fixes the FIXME about lifetime using in the region constraints part. We cannot write `<'graph, 'tcx, D>` because the definition of `Successors<'0, '1, D>` requires `'1 : '0`. We cannot add bound to `'graph` either because `'graph` is required to be an arbitrary value in the definition of `WithSuccessors` So the most accurate way is to use `<'s, 'tcx, D>`. cc `@Aaron1011` who added this FIXME in rust-lang#85343
This PR adds a basic framework for displaying variance-related information in error messages. For example:
The last three lines are new.
This is accomplished by adding a new struct
VarianceDiagInfo
, and passing it along through the various relation methods. When relating types that change the variance (e.g.&mut T
or*mut T
), we pass a more specificVarianceDiagInfo
storing information about the cause of the variance change. When an error, we use theVarianceDiagInfo
to add additional information to the error message.This PR doesn't change any variance-related computation or behavior - only diagnostic messages. Therefore, the implementation is quite incomplete - more detailed error messages can be filled in in subsequent PRs.
Limitations:
fn(fn(&'static u8))
). Since contravariance (AFAIK) is only used for function arguments, we can probably get away without a very fancy message for cases involving contravariance.VarianceDiagInfo
currently only handles mutable pointers/references. However, user-defined types (structs, enums, and unions) have the variance of their type parameters inferred, so it would be good to eventually display information about that. We'll want to try to find a balance between displaying too much and too little information about how the variance was inferred.#![feature(nll)]
/-Z borrowck=mir
is enabled. If issue NLL: turn off migration mode #58781 is not resolved relatively soon, then we might want to duplicate some of this logic in the 'current' (non-NLL) region/outlives handling code.