Emitting error regardless of new param suggestion
This commit is contained in:
parent
e7cb6ad8ce
commit
ef930a2200
@ -1319,48 +1319,48 @@ fn resolve_lifetime_ref(
|
|||||||
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
&& !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) {
|
match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id) {
|
||||||
Some(generics) => {
|
Some(generics) => {
|
||||||
|
|
||||||
|
let mut new_param_sugg_tuple = None;
|
||||||
|
|
||||||
for i in 0..generics.params.len() {
|
for i in 0..generics.params.len() {
|
||||||
|
|
||||||
if !generics.span.contains(generics.params[i].span) {
|
if !generics.span.contains(generics.params[i].span) {
|
||||||
|
new_param_sugg_tuple = match generics.span_for_param_suggestion() {
|
||||||
let mut diag = rustc_session::parse::feature_err(
|
Some(_) => {
|
||||||
&self.tcx.sess.parse_sess,
|
Some((self.tcx.sess.source_map().span_through_char(generics.span, '<').shrink_to_hi(), "'a, ".to_owned()))
|
||||||
sym::anonymous_lifetime_in_impl_trait,
|
},
|
||||||
lifetime_ref.span,
|
None => Some((generics.span, "<'a>".to_owned()))
|
||||||
"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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 => {
|
None => { continue; }
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diag.emit();
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user