From 0f7205f2020ff5acefac83e354acea4c69f2ea0e Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 10 Aug 2020 12:30:31 -0700 Subject: Fix suggestion to use lifetime in type --- src/librustc_resolve/late/diagnostics.rs | 8 +++++++- src/test/ui/mismatched_types/issue-74918-missing-lifetime.stderr | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') 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` 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 = 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; | 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 -- cgit 1.4.1-3-g733a5