-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Error code E0794 for late-bound lifetime parameter error. #107416
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred in diagnostic error codes |
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.
Just a few small suggestions that, I think, make the explanation even clearer.
A lifetime parameter of a function definition is called *late-bound* if it both: | ||
|
||
1. appears in an argument type | ||
2. does not appear in a where clause |
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 would be better to talk about not appearing in "a generic type constraint" rather than in "a where clause", as the 'a
lifetime parameters in both fn<'a, T: Trait<'a>>(t: T)
and fn<'a>(t: impl Trait<'a>)
are early bound without there being any where
clause.
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.
Good point!
function of a concrete type by substituting concrete types for | ||
generic ones, you cannot specify a late-bound lifetime, because such lifetime | ||
parameters are resolved at the function's call site(s). |
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.
function of a concrete type by substituting concrete types for | |
generic ones, you cannot specify a late-bound lifetime, because such lifetime | |
parameters are resolved at the function's call site(s). | |
concrete instance of the generic function, you cannot specify any of | |
its late-bound lifetime parameters, because they are not resolved until | |
each call site(s). |
``` | ||
|
||
Lifetime parameters that are not late-bound are called *early-bound*. | ||
The confusion might stem from the fact that late-bound and early-bound |
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 confusion might stem from the fact that late-bound and early-bound | |
Confusion may arise from the fact that late-bound and early-bound |
In the definition of `bar`, the lifetime parameter `'a` is late-bound, while | ||
`'b` is early-bound. This is reflected in the type annotation for `bar_fn`, | ||
where `'a` is universally quantified and `'b` is substituted by a specific | ||
lifetime. |
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.
lifetime. | |
lifetime. It is not possible to explicitly specify early-bound lifetime | |
parameters when late-bound parameters are present, although the types | |
that are constrained by early-bound parameters can be specified (as in the | |
example above). |
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.
Is this what you mean? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c30a35a698a82969827f8260139c0f9d
It is possible in the sense that it just generates a warning, but warns about it being an error in the future.
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.
Apologies, only just saw your comment (the trials and tribulations of GitHub mobile!). Yes, _bar_fn2
in your playground is what I meant—a number of the tests output the error message "cannot specify lifetime arguments explicitly if late bound lifetime parameters are present"
, but I didn't appreciate they were only warnings (which compiletest denies/upgrades to errors); I think it'd still be helpful to make some reference to it?
That _bar_fn3
in your playground compiles is completely consistent with your existing explanation: no attempt was made to (erroneously) specify concrete lifetimes for late-bound parameters in a function reference, nor was the function reference cast to a pointer that would require explicit universal quantification; lifetime parameter 'b
is early-bound to the lifetime parameter of the second argument, whatever that ends up happening to be—it is existentially, not universally, quantified.
This comment has been minimized.
This comment has been minimized.
I think it's a shame to have lost the |
@eggyal I agree, but I was unsure whether it fit the error code template while not being too lengthy. |
☔ The latest upstream changes (presumably #102513) made this pull request unmergeable. Please resolve the merge conflicts. |
Looks good to me and it's ok to add it back even if it's lengthy. |
☔ The latest upstream changes (presumably #108488) made this pull request unmergeable. Please resolve the merge conflicts. |
Bump. Is anything more needed? @GuillaumeGomez @WaffleLapkin |
No nothing. Sorry, completely forgot about it. Thanks for working on this! @bors r+ rollup |
Error code E0794 for late-bound lifetime parameter error. This PR addresses [rust-lang#80618](rust-lang#80618).
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#107416 (Error code E0794 for late-bound lifetime parameter error.) - rust-lang#108772 (Speed up tidy quite a lot) - rust-lang#109193 (Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests) - rust-lang#109234 (Tweak implementation of overflow checking assertions) - rust-lang#109238 (Fix generics mismatch errors for RPITITs on -Zlower-impl-trait-in-trait-to-assoc-ty) - rust-lang#109283 (rustdoc: reduce allocations in `visibility_to_src_with_space`) - rust-lang#109287 (Use `size_of_val` instead of manual calculation) - rust-lang#109288 (Stabilise `unix_socket_abstract`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR addresses #80618.