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

Fix garbled suggestion for missing lifetime specifier #86678

Merged
merged 1 commit into from
Jun 29, 2021
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
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
hir::GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} | hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided
}
)
}) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/suggestions/issue-86667.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Regression test for #86667, where a garbled suggestion was issued for
// a missing named lifetime parameter.

// compile-flags: --edition 2018

async fn a(s1: &str, s2: &str) -> &str {
//~^ ERROR: missing lifetime specifier [E0106]
s1
}

fn b(s1: &str, s2: &str) -> &str {
//~^ ERROR: missing lifetime specifier [E0106]
s1
}

fn main() {}
27 changes: 27 additions & 0 deletions src/test/ui/suggestions/issue-86667.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0106]: missing lifetime specifier
--> $DIR/issue-86667.rs:6:35
|
LL | async fn a(s1: &str, s2: &str) -> &str {
| ---- ---- ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s1` or `s2`
help: consider introducing a named lifetime parameter
|
LL | async fn a<'a>(s1: &'a str, s2: &'a str) -> &'a str {
| ^^^^ ^^^^^^^ ^^^^^^^ ^^^

error[E0106]: missing lifetime specifier
--> $DIR/issue-86667.rs:11:29
|
LL | fn b(s1: &str, s2: &str) -> &str {
| ---- ---- ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `s1` or `s2`
help: consider introducing a named lifetime parameter
|
LL | fn b<'a>(s1: &'a str, s2: &'a str) -> &'a str {
| ^^^^ ^^^^^^^ ^^^^^^^ ^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0106`.