diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-08-10 12:30:31 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-08-11 11:06:17 -0700 |
| commit | 0f7205f2020ff5acefac83e354acea4c69f2ea0e (patch) | |
| tree | 841d3ae27a659944a9d6438b6a4d2f596290c3ec /src | |
| parent | 4b9ac5161781ca6a376daab3d3b2f2623d8f3789 (diff) | |
| download | rust-0f7205f2020ff5acefac83e354acea4c69f2ea0e.tar.gz rust-0f7205f2020ff5acefac83e354acea4c69f2ea0e.zip | |
Fix suggestion to use lifetime in type
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_resolve/late/diagnostics.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index c57c0e51941..c9e83864a93 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -1349,7 +1349,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { suggest_new(err, "'a"); } (0, _, Some(snippet)) if !snippet.ends_with('>') && count == 1 => { - suggest_new(err, &format!("{}<'a>", snippet)); + if snippet == "" { + // This happens when we have `type Bar<'a> = Foo<T>` where we point at the space + // before `T`. We will suggest `type Bar<'a> = Foo<'a, T>`. + suggest_new(err, "'a, "); + } else { + suggest_new(err, &format!("{}<'a>", snippet)); + } } (n, ..) if n > 1 => { let spans: Vec<Span> = lifetime_names.iter().map(|lt| lt.span).collect(); diff --git a/src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr b/src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr index da3056eac90..d260addef48 100644 --- a/src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr +++ b/src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr @@ -6,8 +6,8 @@ LL | type Item = IteratorChunk<T, S>; | help: consider introducing a named lifetime parameter | -LL | type Item<'a> = IteratorChunk<<'a>T, S>; - | ^^^^ ^^^^ +LL | type Item<'a> = IteratorChunk<'a, T, S>; + | ^^^^ ^^^ error: `impl` item signature doesn't match `trait` item signature --> $DIR/issue-74918-missing-lifetime.rs:11:5 |
