Add tests related to normalization in implied bounds
This commit is contained in:
parent
5ea62560f2
commit
287c77e921
24
tests/ui/implied-bounds/from-trait-impl.rs
Normal file
24
tests/ui/implied-bounds/from-trait-impl.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// check-pass
|
||||||
|
// known-bug: #109628
|
||||||
|
|
||||||
|
trait Trait {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<X: 'static> Trait for (X,) {
|
||||||
|
type Assoc = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo<T: Trait>(T)
|
||||||
|
where
|
||||||
|
T::Assoc: Clone; // any predicate using `T::Assoc` works here
|
||||||
|
|
||||||
|
fn func1(foo: Foo<(&str,)>) {
|
||||||
|
let _: &'static str = foo.0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait TestTrait {}
|
||||||
|
|
||||||
|
impl<X> TestTrait for [Foo<(X,)>; 1] {}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -1,11 +1,11 @@
|
|||||||
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
|
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
|
||||||
--> $DIR/normalization-nested.rs:35:20
|
--> $DIR/normalization-nested.rs:35:28
|
||||||
|
|
|
|
||||||
LL | pub fn test<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
|
LL | pub fn test_wfcheck<'x>(_: Map<Vec<&'x ()>>) {}
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| this data with lifetime `'x`...
|
| this data with lifetime `'x`...
|
||||||
| ...is used and required to live as long as `'static` here
|
| ...is used and required to live as long as `'static` here
|
||||||
|
|
|
|
||||||
note: `'static` lifetime requirement introduced by this bound
|
note: `'static` lifetime requirement introduced by this bound
|
||||||
--> $DIR/normalization-nested.rs:33:14
|
--> $DIR/normalization-nested.rs:33:14
|
||||||
@ -13,6 +13,21 @@ note: `'static` lifetime requirement introduced by this bound
|
|||||||
LL | I::Item: 'static;
|
LL | I::Item: 'static;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
|
||||||
|
--> $DIR/normalization-nested.rs:37:29
|
||||||
|
|
|
||||||
|
LL | pub fn test_borrowck<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| this data with lifetime `'x`...
|
||||||
|
| ...is used and required to live as long as `'static` here
|
||||||
|
|
|
||||||
|
note: `'static` lifetime requirement introduced by this bound
|
||||||
|
--> $DIR/normalization-nested.rs:33:14
|
||||||
|
|
|
||||||
|
LL | I::Item: 'static;
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0759`.
|
For more information about this error, try `rustc --explain E0759`.
|
||||||
|
@ -32,7 +32,9 @@ pub struct Map<I>(I)
|
|||||||
I: Iter,
|
I: Iter,
|
||||||
I::Item: 'static;
|
I::Item: 'static;
|
||||||
|
|
||||||
pub fn test<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
|
pub fn test_wfcheck<'x>(_: Map<Vec<&'x ()>>) {}
|
||||||
|
|
||||||
|
pub fn test_borrowck<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
error: lifetime may not live long enough
|
||||||
|
--> $DIR/normalization-preserve-equality.rs:24:1
|
||||||
|
|
|
||||||
|
LL | fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) {
|
||||||
|
| ^^^^^^^^^^^^^^^^^--^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
| | | |
|
||||||
|
| | | lifetime `'b` defined here
|
||||||
|
| | lifetime `'a` defined here
|
||||||
|
| requires that `'a` must outlive `'b`
|
||||||
|
|
|
||||||
|
= help: consider adding the following bound: `'a: 'b`
|
||||||
|
|
||||||
|
error: lifetime may not live long enough
|
||||||
|
--> $DIR/normalization-preserve-equality.rs:24:1
|
||||||
|
|
|
||||||
|
LL | fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) {
|
||||||
|
| ^^^^^^^^^^^^^^^^^--^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
| | | |
|
||||||
|
| | | lifetime `'b` defined here
|
||||||
|
| | lifetime `'a` defined here
|
||||||
|
| requires that `'b` must outlive `'a`
|
||||||
|
|
|
||||||
|
= help: consider adding the following bound: `'b: 'a`
|
||||||
|
|
||||||
|
help: `'a` and `'b` must be the same: replace one with the other
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
28
tests/ui/implied-bounds/normalization-preserve-equality.rs
Normal file
28
tests/ui/implied-bounds/normalization-preserve-equality.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Both revisions should pass. `borrowck` revision is a bug!
|
||||||
|
//
|
||||||
|
// revisions: wfcheck borrowck
|
||||||
|
// [wfcheck] check-pass
|
||||||
|
// [borrowck] check-fail
|
||||||
|
// [borrowck] known-bug: #106569
|
||||||
|
|
||||||
|
struct Equal<'a, 'b>(&'a &'b (), &'b &'a ()); // implies 'a == 'b
|
||||||
|
|
||||||
|
trait Trait {
|
||||||
|
type Ty;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'x> Trait for Equal<'x, 'x> {
|
||||||
|
type Ty = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
trait WfCheckTrait {}
|
||||||
|
|
||||||
|
#[cfg(wfcheck)]
|
||||||
|
impl<'a, 'b> WfCheckTrait for (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>) {}
|
||||||
|
|
||||||
|
#[cfg(borrowck)]
|
||||||
|
fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) {
|
||||||
|
let _ = None::<Equal<'a, 'b>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user