From 4b323e62ba785812fbb5d6b77f2564a59dce2171 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 1 Sep 2022 15:41:13 +0000 Subject: [PATCH] Reproduce sad diagnostic --- .../ui/impl-trait/unactionable_diagnostic.rs | 23 +++++++++++++++++++ .../impl-trait/unactionable_diagnostic.stderr | 12 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/test/ui/impl-trait/unactionable_diagnostic.rs create mode 100644 src/test/ui/impl-trait/unactionable_diagnostic.stderr diff --git a/src/test/ui/impl-trait/unactionable_diagnostic.rs b/src/test/ui/impl-trait/unactionable_diagnostic.rs new file mode 100644 index 00000000000..de482e0370c --- /dev/null +++ b/src/test/ui/impl-trait/unactionable_diagnostic.rs @@ -0,0 +1,23 @@ +trait Trait {} + +struct Foo; + +impl Trait for Foo {} + +fn foo<'t, P>( + post: P, + x: &'t Foo, +) -> &'t impl Trait { + x +} + +fn bar<'t, T>( + post: T, + x: &'t Foo, +) -> &'t impl Trait { + foo(post, x) + //~^ ERROR: the opaque type `foo::{opaque#0}` may not live long enough + //~| HELP: consider adding an explicit lifetime bound `foo::{opaque#0}: 't` +} + +fn main() {} diff --git a/src/test/ui/impl-trait/unactionable_diagnostic.stderr b/src/test/ui/impl-trait/unactionable_diagnostic.stderr new file mode 100644 index 00000000000..fe6fef5815d --- /dev/null +++ b/src/test/ui/impl-trait/unactionable_diagnostic.stderr @@ -0,0 +1,12 @@ +error[E0309]: the opaque type `foo::{opaque#0}` may not live long enough + --> $DIR/unactionable_diagnostic.rs:18:5 + | +LL | foo(post, x) + | ^^^^^^^^^^^^ + | + = help: consider adding an explicit lifetime bound `foo::{opaque#0}: 't`... + = note: ...so that the type `impl Trait` will meet its required lifetime bounds + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0309`.