From 191576e259b2536661e5cca62bd8083d036b3867 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Thu, 23 Mar 2023 05:20:57 +0300 Subject: [PATCH] add test --- tests/ui/implied-bounds/from-trait-impl.rs | 21 +++++++++++++ .../ui/implied-bounds/from-trait-impl.stderr | 31 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/ui/implied-bounds/from-trait-impl.rs create mode 100644 tests/ui/implied-bounds/from-trait-impl.stderr diff --git a/tests/ui/implied-bounds/from-trait-impl.rs b/tests/ui/implied-bounds/from-trait-impl.rs new file mode 100644 index 0000000000000..770c47d9d2077 --- /dev/null +++ b/tests/ui/implied-bounds/from-trait-impl.rs @@ -0,0 +1,21 @@ +// Foo> shouldn't imply X: 'static. +// We don't use region constraints from trait impls in implied bounds. + +trait Trait { + type Assoc; +} + +impl Trait for Vec { + type Assoc = (); +} + +struct Foo(T) +where + T::Assoc: 'static, // any predicate naming T::Assoc +; + +fn foo(_: Foo>) {} +//~^ ERROR `X` may not live long enough +//~| ERROR `X` may not live long enough + +fn main() {} diff --git a/tests/ui/implied-bounds/from-trait-impl.stderr b/tests/ui/implied-bounds/from-trait-impl.stderr new file mode 100644 index 0000000000000..bf5ce6d3a0166 --- /dev/null +++ b/tests/ui/implied-bounds/from-trait-impl.stderr @@ -0,0 +1,31 @@ +error[E0310]: the parameter type `X` may not live long enough + --> $DIR/from-trait-impl.rs:17:1 + | +LL | fn foo(_: Foo>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the parameter type `X` must be valid for the static lifetime... + | ...so that the type `X` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound + | +LL | fn foo(_: Foo>) {} + | +++++++++ + +error[E0310]: the parameter type `X` may not live long enough + --> $DIR/from-trait-impl.rs:17:14 + | +LL | fn foo(_: Foo>) {} + | ^^^^^^^^^^^ + | | + | the parameter type `X` must be valid for the static lifetime... + | ...so that the type `X` will meet its required lifetime bounds + | +help: consider adding an explicit lifetime bound + | +LL | fn foo(_: Foo>) {} + | +++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0310`.