Skip to content

Commit 0f7205f

Browse files
committed
Fix suggestion to use lifetime in type
1 parent 4b9ac51 commit 0f7205f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/librustc_resolve/late/diagnostics.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
13491349
suggest_new(err, "'a");
13501350
}
13511351
(0, _, Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
1352-
suggest_new(err, &format!("{}<'a>", snippet));
1352+
if snippet == "" {
1353+
// This happens when we have `type Bar<'a> = Foo<T>` where we point at the space
1354+
// before `T`. We will suggest `type Bar<'a> = Foo<'a, T>`.
1355+
suggest_new(err, "'a, ");
1356+
} else {
1357+
suggest_new(err, &format!("{}<'a>", snippet));
1358+
}
13531359
}
13541360
(n, ..) if n > 1 => {
13551361
let spans: Vec<Span> = lifetime_names.iter().map(|lt| lt.span).collect();

src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | type Item = IteratorChunk<T, S>;
66
|
77
help: consider introducing a named lifetime parameter
88
|
9-
LL | type Item<'a> = IteratorChunk<<'a>T, S>;
10-
| ^^^^ ^^^^
9+
LL | type Item<'a> = IteratorChunk<'a, T, S>;
10+
| ^^^^ ^^^
1111

1212
error: `impl` item signature doesn't match `trait` item signature
1313
--> $DIR/issue-74918-missing-lifetime.rs:11:5

0 commit comments

Comments
 (0)