-
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
"late bound lifetime parameters" error should have a number and help text #80618
Comments
@cole-miller are you interested in adding the |
@jyn514 sure thing! While I'm waiting for |
Not too much harder I think :) See #76143 for an example of both. |
I agree this is needed no matter what.
I'm not sure this is the best solution though. If there are no early bound lifetimes, just leaving off the lifetime specifier (as implied by the lint) also works: let _ = f; // just leave off the lifetime specifier
let _: for<'a> fn() = f; // With type ascription In more complicated situations, the type ascription may be needed to specify the early bound lifetimes, but can sometimes still be used without forcing an early bound: struct Foo<'a, 'b> { a: &'a(), b: &'b () }
// There is an implicit late bound parameter due to &Foo; 'a and 'b are early bound
fn mixed<'a: 'a, 'b: 'b>(_: &Foo<'a, 'b>) -> Foo<'a, 'b> { todo!() }
// This happens to work but no lifetimes can be specified without lint or error
let _ = mixed;
// For example, this triggers the lint as a warning; specifying 1 or 3+ lifetimes triggers an error:
// let _ = mixed::<'static, 'static>;
// type ascription allows specifying the lifetimes without warning or error
let _: for<'a> fn(&'a Foo<'static, 'static>) -> Foo<'static, 'static> = mixed; However, it is sometimes necessary to force a lifetime to be early bound, as discussed in issue 42868 and friends. I don't know how tractable it is to detect when the force-early-bound workaround is or isn't required. On the third hand, if I understand the conversation in issue 42508, sometimes type ascription works where forcing an early bound does not.
Not quite: // These compiled with `mixed` defined as above. The first version fires the lint as a warning.
let _ = mixed::<'static, 'static>;
let _: for<'a> fn(&'a Foo<'static, 'static>) -> Foo<'static, 'static> = mixed;
// Apply the suggested hint:
fn mixed<'a: 'a, 'b: 'b, 'c: 'c>(_: &'c Foo<'a, 'b>) -> Foo<'a, 'b> { todo!() }
// This now fails: expected 3 lifetime arguments
let _ = mixed::<'static, 'static>;
// This now fails: one type is more general than the other
let _: for<'a> fn(&'a Foo<'static, 'static>) -> Foo<'static, 'static> = mixed; |
Hi, @cole-miller could you claim this? Then it's easier to see which issues are not yet being worked on. |
@rustbot claim |
Any work being done on this? I'd love to implement this as my first contribution. |
I never got around to working on this, feel free to claim it! @rustbot release-assignment |
Alright cool! Can I have an example of what it should maybe look like? |
@rustbot claim |
@rustbot claim |
Error code E0794 for late-bound lifetime parameter error. This PR addresses [rust-lang#80618](rust-lang#80618).
Error code E0794 for late-bound lifetime parameter error. This PR addresses [rust-lang#80618](rust-lang#80618).
Error code E0794 for late-bound lifetime parameter error. This PR addresses [#80618](rust-lang/rust#80618).
I think this can be closed now? |
Fixed by #107416. |
Currently (tested on stable and nightly) if you try to compile this code
you get this error message:
There is no error number (like E0208) to pass to
rustc --explain
. There's also no mention that you can fix this error without changing the meaning of the code at all by putting a vacuouswhere
clause in the signature off
, like this:See #42868 for background. (I'm not sure when that compatibility lint became a hard error; it seems to have happened without that tracking issue being updated. Maybe that has something to do with why the error has no number or
help
.)I think:
rustc --explain
text that discusses the early- vs. late-bound lifetime distinction and why specifying late-bound lifetime parameters explicitly is not allowedhelp
line that suggests addingwhere 'a: 'a
Here is the URLO thread that prompted this issue:
https://users.rust-lang.org/t/what-is-the-meaning-of-a-a-in-rust-lifetime-parameters/53570
cc @petrochenkov
The text was updated successfully, but these errors were encountered: