Rollup merge of #105859 - compiler-errors:hr-lifetime-add, r=davidtwco
Point out span where we could introduce higher-ranked lifetime Somewhat addresses #105422, but not really. We don't have that much useful information here since we're still in resolution :^( Maybe this suggestion isn't worth it. If the reviewer has an idea how we can get a more succinct binder information for a structured suggestion, it would be appreciated.
This commit is contained in:
commit
0c8d11b97c
7 changed files with 57 additions and 6 deletions
|
@ -1515,7 +1515,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
count: 1,
|
count: 1,
|
||||||
};
|
};
|
||||||
let elision_candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
|
let elision_candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
|
||||||
for rib in self.lifetime_ribs.iter().rev() {
|
for (i, rib) in self.lifetime_ribs.iter().enumerate().rev() {
|
||||||
debug!(?rib.kind);
|
debug!(?rib.kind);
|
||||||
match rib.kind {
|
match rib.kind {
|
||||||
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
|
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
|
||||||
|
@ -1532,16 +1532,31 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
} else {
|
} else {
|
||||||
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
||||||
};
|
};
|
||||||
rustc_errors::struct_span_err!(
|
let mut diag = rustc_errors::struct_span_err!(
|
||||||
self.r.session,
|
self.r.session,
|
||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
E0637,
|
E0637,
|
||||||
"{}",
|
"{}",
|
||||||
msg,
|
msg,
|
||||||
)
|
);
|
||||||
.span_label(lifetime.ident.span, note)
|
diag.span_label(lifetime.ident.span, note);
|
||||||
.emit();
|
if elided {
|
||||||
|
for rib in self.lifetime_ribs[i..].iter().rev() {
|
||||||
|
if let LifetimeRibKind::Generics {
|
||||||
|
span,
|
||||||
|
kind: LifetimeBinderKind::PolyTrait | LifetimeBinderKind::WhereBound,
|
||||||
|
..
|
||||||
|
} = &rib.kind
|
||||||
|
{
|
||||||
|
diag.span_help(
|
||||||
|
*span,
|
||||||
|
"consider introducing a higher-ranked lifetime here with `for<'a>`",
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diag.emit();
|
||||||
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
|
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | T: Into<&u32>,
|
LL | T: Into<&u32>,
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/E0637.rs:13:8
|
||||||
|
|
|
||||||
|
LL | T: Into<&u32>,
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | fn should_error<T>() where T : Into<&u32> {}
|
LL | fn should_error<T>() where T : Into<&u32> {}
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:5:32
|
||||||
|
|
|
||||||
|
LL | fn should_error<T>() where T : Into<&u32> {}
|
||||||
|
| ^
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0106]: missing lifetime specifier
|
||||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:20
|
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:20
|
||||||
|
|
|
@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | T: WithType<&u32>
|
LL | T: WithType<&u32>
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
|
||||||
|
|
|
||||||
|
LL | T: WithType<&u32>
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | T: WithType<&u32>
|
LL | T: WithType<&u32>
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
|
||||||
|
|
|
||||||
|
LL | T: WithType<&u32>
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | T: WithType<&u32>
|
LL | T: WithType<&u32>
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/where-clause-trait-impl-region.rs:11:8
|
||||||
|
|
|
||||||
|
LL | T: WithType<&u32>
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||||
|
|
|
|
||||||
LL | T: WithType<&u32>
|
LL | T: WithType<&u32>
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
|
||||||
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
|
||||||
|
--> $DIR/where-clause-trait-impl-region.rs:11:8
|
||||||
|
|
|
||||||
|
LL | T: WithType<&u32>
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue