From ef930a220042e63910f33f7d10da317635fb21cb Mon Sep 17 00:00:00 2001 From: stoozy Date: Thu, 29 Sep 2022 04:06:02 -0400 Subject: [PATCH] Emitting error regardless of new param suggestion --- compiler/rustc_resolve/src/late/lifetimes.rs | 66 ++++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 40d183bf1baca..16a819504953f 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1319,48 +1319,48 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { && !self.tcx.features().anonymous_lifetime_in_impl_trait { + + let mut diag = rustc_session::parse::feature_err( + &self.tcx.sess.parse_sess, + sym::anonymous_lifetime_in_impl_trait, + lifetime_ref.span, + "anonymous lifetimes in `impl Trait` are unstable", + ); + match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id) { Some(generics) => { - for i in 0..generics.params.len() { - if !generics.span.contains(generics.params[i].span) { + let mut new_param_sugg_tuple = None; - let mut diag = rustc_session::parse::feature_err( - &self.tcx.sess.parse_sess, - sym::anonymous_lifetime_in_impl_trait, - lifetime_ref.span, - "anonymous lifetimes in `impl Trait` are unstable", - ); - - 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()), - 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(); - - return; + for i in 0..generics.params.len() { + if !generics.span.contains(generics.params[i].span) { + new_param_sugg_tuple = match generics.span_for_param_suggestion() { + Some(_) => { + Some((self.tcx.sess.source_map().span_through_char(generics.span, '<').shrink_to_hi(), "'a, ".to_owned())) + }, + None => Some((generics.span, "<'a>".to_owned())) + } } } + + let mut multi_sugg_vec = vec![(lifetime_ref.span.shrink_to_hi(), "'a ".to_owned())]; + + if let Some(new_tuple) = new_param_sugg_tuple{ + multi_sugg_vec.push(new_tuple); + } + + diag.span_label(lifetime_ref.span, "expected named lifetime parameter"); + diag.multipart_suggestion("consider introducing a named lifetime parameter", + multi_sugg_vec, + rustc_errors::Applicability::MaybeIncorrect); + }, - None => { - rustc_session::parse::feature_err( - &self.tcx.sess.parse_sess, - sym::anonymous_lifetime_in_impl_trait, - lifetime_ref.span, - "anonymous lifetimes in `impl Trait` are unstable", - ).emit(); - return; - } + None => { continue; } } + diag.emit(); + return; + } scope = s; }