Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #102867

Merged
merged 18 commits into from
Oct 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Emitting error regardless of new param suggestion
  • Loading branch information
Stoozy committed Sep 29, 2022
commit ef930a220042e63910f33f7d10da317635fb21cb
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