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
Show file tree
Hide file tree
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
Proper span for new generic param suggestion
  • Loading branch information
Stoozy committed Sep 28, 2022
commit e7cb6ad8ce382ded99be31c95562c8d91a635b24
9 changes: 7 additions & 2 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 10 additions & 2 deletions src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down