Skip to content

Commit e7cb6ad

Browse files
committed
Proper span for new generic param suggestion
1 parent 24c8e27 commit e7cb6ad

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1333,11 +1333,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13331333
);
13341334

13351335
diag.span_label(lifetime_ref.span, "expected named lifetime parameter");
1336-
13371336
diag.multipart_suggestion("consider introducing a named lifetime parameter",
13381337
vec![
13391338
(lifetime_ref.span.shrink_to_hi(), "'a ".to_owned()),
1340-
(generics.span, "<'a>".to_owned())
1339+
match generics.span_for_param_suggestion() {
1340+
Some(_) => {
1341+
(self.tcx.sess.source_map().span_through_char(generics.span, '<').shrink_to_hi(), "'a, ".to_owned())
1342+
}
1343+
None => (generics.span, "<'a>".to_owned()),
1344+
1345+
}
13411346
], rustc_errors::Applicability::MaybeIncorrect);
13421347
diag.emit();
13431348

src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ error[E0658]: anonymous lifetimes in `impl Trait` are unstable
2626
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31
2727
|
2828
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
29-
| ^^
29+
| ^^ expected named lifetime parameter
3030
|
3131
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
32+
help: consider introducing a named lifetime parameter
33+
|
34+
LL | fn f<'a>(_: impl Iterator<Item = &'_'a ()>) {}
35+
| ++++ ++
3236

3337
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
3438
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31
3539
|
3640
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
37-
| ^^
41+
| ^^ expected named lifetime parameter
3842
|
3943
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
44+
help: consider introducing a named lifetime parameter
45+
|
46+
LL | fn g<'a>(x: impl Iterator<Item = &'_'a ()>) -> Option<&'_ ()> { x.next() }
47+
| ++++ ++
4048

4149
error: aborting due to 4 previous errors
4250

0 commit comments

Comments
 (0)