Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Nov 28, 2023
1 parent ff34750 commit 191576e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/ui/implied-bounds/from-trait-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Foo<Vec<X>> shouldn't imply X: 'static.
// We don't use region constraints from trait impls in implied bounds.

trait Trait {
type Assoc;
}

impl<X: 'static> Trait for Vec<X> {
type Assoc = ();
}

struct Foo<T: Trait>(T)
where
T::Assoc: 'static, // any predicate naming T::Assoc
;

fn foo<X>(_: Foo<Vec<X>>) {}
//~^ ERROR `X` may not live long enough
//~| ERROR `X` may not live long enough

fn main() {}
31 changes: 31 additions & 0 deletions tests/ui/implied-bounds/from-trait-impl.stderr
Original file line number Diff line number Diff line change
@@ -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<X>(_: Foo<Vec<X>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| 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<X: 'static>(_: Foo<Vec<X>>) {}
| +++++++++

error[E0310]: the parameter type `X` may not live long enough
--> $DIR/from-trait-impl.rs:17:14
|
LL | fn foo<X>(_: Foo<Vec<X>>) {}
| ^^^^^^^^^^^
| |
| 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<X: 'static>(_: Foo<Vec<X>>) {}
| +++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0310`.

0 comments on commit 191576e

Please sign in to comment.