From f333b4795c53991e513ec06f25f496c9d8075c88 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 28 Jun 2021 00:56:24 +0200 Subject: [PATCH] Fix garbled suggestion for missing lifetime specifier --- .../rustc_resolve/src/late/diagnostics.rs | 2 ++ src/test/ui/suggestions/issue-86667.rs | 16 +++++++++++ src/test/ui/suggestions/issue-86667.stderr | 27 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/test/ui/suggestions/issue-86667.rs create mode 100644 src/test/ui/suggestions/issue-86667.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 03b578d4adeec..76979ab50b9e6 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1962,6 +1962,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { hir::GenericParamKind::Type { synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), .. + } | hir::GenericParamKind::Lifetime { + kind: hir::LifetimeParamKind::Elided } ) }) { diff --git a/src/test/ui/suggestions/issue-86667.rs b/src/test/ui/suggestions/issue-86667.rs new file mode 100644 index 0000000000000..6aceb13746937 --- /dev/null +++ b/src/test/ui/suggestions/issue-86667.rs @@ -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() {} diff --git a/src/test/ui/suggestions/issue-86667.stderr b/src/test/ui/suggestions/issue-86667.stderr new file mode 100644 index 0000000000000..77f7f874a4e42 --- /dev/null +++ b/src/test/ui/suggestions/issue-86667.stderr @@ -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`.