diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-06-29 08:46:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-29 08:46:16 +0900 |
| commit | a89c6be16ecdb9584d2aa921bd094d83ebd3c9c7 (patch) | |
| tree | bc36fa7c7e93f5429eb16a35e48aefd912d6f24f | |
| parent | af3c1544e2e2be7142a6f6adcdbcfaa17014b515 (diff) | |
| parent | f333b4795c53991e513ec06f25f496c9d8075c88 (diff) | |
| download | rust-a89c6be16ecdb9584d2aa921bd094d83ebd3c9c7.tar.gz rust-a89c6be16ecdb9584d2aa921bd094d83ebd3c9c7.zip | |
Rollup merge of #86678 - FabianWolff:issue-86667, r=jackh726
Fix garbled suggestion for missing lifetime specifier This PR fixes #86667. The suggestion code currently checks whether there is a generic parameter that is not a synthetic `impl Trait` parameter and, if so, suggests to insert a new lifetime `'a` before that generic parameter. However, it does not make sense to insert `'a` in front of an elided lifetime parameter, since these are synthetic as well, which leads to the garbled suggestion in #86667.
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-86667.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-86667.stderr | 27 |
3 files changed, 45 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 03b578d4ade..76979ab50b9 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 00000000000..6aceb137469 --- /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 00000000000..77f7f874a4e --- /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`. |
