diff options
| author | stoozy <stoozy@proton.me> | 2022-09-28 00:33:52 -0400 |
|---|---|---|
| committer | stoozy <stoozy@proton.me> | 2022-09-28 00:33:52 -0400 |
| commit | e7cb6ad8ce382ded99be31c95562c8d91a635b24 (patch) | |
| tree | dc015a2f6fb395d3638c45621020da4169d46f4c | |
| parent | 24c8e27a1d1693786a5ec0ddffedefeb01ff4fb4 (diff) | |
| download | rust-e7cb6ad8ce382ded99be31c95562c8d91a635b24.tar.gz rust-e7cb6ad8ce382ded99be31c95562c8d91a635b24.zip | |
Proper span for new generic param suggestion
| -rw-r--r-- | compiler/rustc_resolve/src/late/lifetimes.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr | 12 |
2 files changed, 17 insertions, 4 deletions
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 9b66c42651d..40d183bf1ba 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1333,11 +1333,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { ); diag.span_label(lifetime_ref.span, "expected named lifetime parameter"); - diag.multipart_suggestion("consider introducing a named lifetime parameter", vec![ (lifetime_ref.span.shrink_to_hi(), "'a ".to_owned()), - (generics.span, "<'a>".to_owned()) + match generics.span_for_param_suggestion() { + Some(_) => { + (self.tcx.sess.source_map().span_through_char(generics.span, '<').shrink_to_hi(), "'a, ".to_owned()) + } + None => (generics.span, "<'a>".to_owned()), + + } ], rustc_errors::Applicability::MaybeIncorrect); diag.emit(); diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr index e82a6f769e0..9833da13ffc 100644 --- a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr @@ -26,17 +26,25 @@ error[E0658]: anonymous lifetimes in `impl Trait` are unstable --> $DIR/impl-trait-missing-lifetime-gated.rs:5:31 | LL | fn f(_: impl Iterator<Item = &'_ ()>) {} - | ^^ + | ^^ expected named lifetime parameter | = help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable +help: consider introducing a named lifetime parameter + | +LL | fn f<'a>(_: impl Iterator<Item = &'_'a ()>) {} + | ++++ ++ error[E0658]: anonymous lifetimes in `impl Trait` are unstable --> $DIR/impl-trait-missing-lifetime-gated.rs:8:31 | LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } - | ^^ + | ^^ expected named lifetime parameter | = help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable +help: consider introducing a named lifetime parameter + | +LL | fn g<'a>(x: impl Iterator<Item = &'_'a ()>) -> Option<&'_ ()> { x.next() } + | ++++ ++ error: aborting due to 4 previous errors |
