Proper span for new generic param suggestion
This commit is contained in:
parent
24c8e27a1d
commit
e7cb6ad8ce
@ -1333,11 +1333,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
diag.span_label(lifetime_ref.span, "expected named lifetime parameter");
|
diag.span_label(lifetime_ref.span, "expected named lifetime parameter");
|
||||||
|
|
||||||
diag.multipart_suggestion("consider introducing a named lifetime parameter",
|
diag.multipart_suggestion("consider introducing a named lifetime parameter",
|
||||||
vec![
|
vec![
|
||||||
(lifetime_ref.span.shrink_to_hi(), "'a ".to_owned()),
|
(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);
|
], rustc_errors::Applicability::MaybeIncorrect);
|
||||||
diag.emit();
|
diag.emit();
|
||||||
|
|
||||||
|
@ -26,17 +26,25 @@ error[E0658]: anonymous lifetimes in `impl Trait` are unstable
|
|||||||
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31
|
||||||
|
|
|
|
||||||
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
|
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: 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
|
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
|
||||||
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31
|
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31
|
||||||
|
|
|
|
||||||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
|
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: 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
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user