Skip to content

Commit

Permalink
Emitting error regardless of new param suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoozy committed Sep 29, 2022
1 parent e7cb6ad commit ef930a2
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ef930a2

Please sign in to comment.