-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Better error message for late/early lifetime param mismatch #140523
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
base: master
Are you sure you want to change the base?
Better error message for late/early lifetime param mismatch #140523
Conversation
@@ -17,11 +17,11 @@ pub trait Foo<'a, 't> { | |||
|
|||
impl<'a, 't> Foo<'a, 't> for &'a isize { | |||
fn no_bound<'b:'a>(self, b: Inv<'b>) { | |||
//~^ ERROR lifetime parameters or bounds on method `no_bound` do not match | |||
//~^ ERROR lifetime parameters do not match the trait definition, since they differ in late-boundedness |
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.
Hmm, brief thought as I skim this, but how often do we actually use the terminology "late-bound"/"early-bound" in error mesasges? In general, "late-boundedness" is kind of weird.
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.
no idea, but also we do need a precise term here. hiding this detail feels like we're obscuring the whole fact that this error arises.
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.
AFAIK (I've once grepped for this) in diagnostics we only ever mention boundedness when a user tries to bind a late-bound var early:
fn main() { fn f<'a>() {} f::<'static>; }
//~^ ERROR cannot specify lifetime arguments explicitly if late bound lifetime parameters are present [E0794]
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.
The reference also uses the terms without any definition 💀 https://github.com/rust-lang/reference/blob/48ad733ce25b71385e917cab0383ed3407603490/src/types/function-item.md?plain=1#L10
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 kind of think that maybe just exclude the "since they differ in late-boundedness" part in the main error text.
We could also just kind of "lie" a bit and state that the reason there is an error is because of the mismatched bounds (which is true, but not precise).
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'll move it down to a note, but I'd rather keep the early and late in the labels so that people can at least google it. Not really sure how to reword the main message, though, in that case.
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.
Yeah, having "late-bound" and "early-bound" in the note is fine because of googleability, but something about the "lateboundedness" term rubs me the wrong way - this is mostly just bikeshedding, because I don't immediately have a better answer.
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.
Reworded this to just say "lifetime parameters do not match the trait definition", and added a note saying "lifetime parameters differ in whether they are early- or late-bound".
daec806
to
7ccc65b
Compare
Thanks for putting up with my bikeshedding - I think this is clearly an improvement. @bors r+ rollup |
Wait I didn't remove all instances of late-boundedness @bors r- |
7ccc65b
to
d2b22cf
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
Rework the way we report early-/late-bound lifetime param mismatches to equate the trait and impl signatures using region variables, so that we can detect when a late-bound param is present in the signature in place of an early-bound param, or vice versa.
The diagnostic is a bit more technical, but it's more obviously clear to see what the problem is, even if it's not great at explaining how to fix it. I think this could be improved further, but I still think it's much better than what exists today.
Note to reviewer(s): I'd appreciate if we didn't bikeshed too much about this verbiage, b/c I hope it's clear that the old message sucked a lot. I'm happy to file bugs for interested new contributors to improve the messaging further.
Edit(fmease): Fixes #33624.