Closed
Description
Given this code:
type Lt<'lt> = *mut &'lt u8;
fn outlives<'lt, T: 'lt>(_: T, _: Lt<'lt>) {}
pub fn test<A>(arg: A, lt: Lt<'_>, _: &str) {
outlives(arg, lt);
//~^ ERROR the parameter type `A` may not live long enough
}
The current error message is this: (note the invalid suggestion)
error[[E0311]](https://doc.rust-lang.org/nightly/error_codes/E0311.html): the parameter type `A` may not live long enough
--> src/lib.rs:6:5
|
6 | outlives(arg, lt);
| ^^^^^^^^^^^^^^^^^
|
note: the parameter type `A` must be valid for the anonymous lifetime defined here...
--> src/lib.rs:5:28
|
5 | pub fn test<A>(arg: A, lt: Lt<'_>, _: &str) {
| ^^^^^^
note: ...so that the type `A` will meet its required lifetime bounds
--> src/lib.rs:6:5
|
6 | outlives(arg, lt);
| ^^^^^^^^^^^^^^^^^
help: consider adding an explicit lifetime bound...
|
5 | pub fn test<'a, A: 'a>(arg: A, lt: Lt<'_<'a>>, _: &'a str) {
| +++ ++++ ++++ ++
For more information about this error, try `rustc --explain E0311`.
Two problems with this suggestion:
- the last argument of type
&str
should not be touched by the suggestion. - the anonymous lifetime
'_
should be correctly replaced by the named lifetime'a
.
The fixed suggestion should be:
help: consider adding an explicit lifetime bound...
|
5 | pub fn test<'a, A: 'a>(arg: A, lt: Lt<'a>, _: &str) {
| +++ ++++ ++
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerArea: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.