Skip to content
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

Point out span where we could introduce higher-ranked lifetime #105859

Merged
merged 1 commit into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
count: 1,
};
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);
match rib.kind {
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
Expand All @@ -1529,16 +1529,31 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
} else {
("`'_` 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,
lifetime.ident.span,
E0637,
"{}",
msg,
)
.span_label(lifetime.ident.span, note)
.emit();

);
diag.span_label(lifetime.ident.span, note);
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);
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | T: Into<&u32>,
| ^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | fn should_error<T>() where T : Into<&u32> {}
| ^ 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
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | T: WithType<&u32>
| ^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | T: WithType<&u32>
| ^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | T: WithType<&u32>
| ^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
LL | T: WithType<&u32>
| ^ 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

Expand Down