Move /src/test to /tests

This commit is contained in:
Albert Larsan
2023-01-05 09:13:28 +01:00
parent ca855e6e42
commit cf2dff2b1e
27592 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, T> { //~ ERROR rustc_outlives
bar: std::slice::IterMut<'a, T>
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/cross-crate.rs:4:1
|
LL | struct Foo<'a, T> {
| ^^^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,12 @@
/*
* We don't infer `T: 'static` outlives relationships.
*/
struct Foo<U> {
bar: Bar<U> //~ ERROR the parameter type `U` may not live long enough [E0310]
}
struct Bar<T: 'static> {
x: T,
}
fn main() {}

View File

@@ -0,0 +1,19 @@
error[E0310]: the parameter type `U` may not live long enough
--> $DIR/dont-infer-static.rs:6:10
|
LL | bar: Bar<U>
| ^^^^^^ ...so that the type `U` will meet its required lifetime bounds...
|
note: ...that is required by this bound
--> $DIR/dont-infer-static.rs:8:15
|
LL | struct Bar<T: 'static> {
| ^^^^^^^
help: consider adding an explicit lifetime bound...
|
LL | struct Foo<U: 'static> {
| +++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0310`.

View File

@@ -0,0 +1,27 @@
#![feature(rustc_attrs)]
// Needs an explicit where clause stating outlives condition. (RFC 2093)
// Type T needs to outlive lifetime 'a.
#[rustc_outlives]
enum Foo<'a, T> { //~ ERROR rustc_outlives
One(Bar<'a, T>)
}
// Type U needs to outlive lifetime 'b
#[rustc_outlives]
struct Bar<'b, U> { //~ ERROR rustc_outlives
field2: &'b U
}
// Type K needs to outlive lifetime 'c.
#[rustc_outlives]
enum Ying<'c, K> { //~ ERROR rustc_outlives
One(&'c Yang<K>)
}
struct Yang<V> {
field2: V
}
fn main() {}

View File

@@ -0,0 +1,26 @@
error: rustc_outlives
--> $DIR/enum.rs:7:1
|
LL | enum Foo<'a, T> {
| ^^^^^^^^^^^^^^^
|
= note: T: 'a
error: rustc_outlives
--> $DIR/enum.rs:13:1
|
LL | struct Bar<'b, U> {
| ^^^^^^^^^^^^^^^^^
|
= note: U: 'b
error: rustc_outlives
--> $DIR/enum.rs:19:1
|
LL | enum Ying<'c, K> {
| ^^^^^^^^^^^^^^^^
|
= note: K: 'c
error: aborting due to 3 previous errors

View File

@@ -0,0 +1,12 @@
#![feature(rustc_attrs)]
trait Trait<'x, T> where T: 'x {
}
#[rustc_outlives]
struct Foo<'a, A> //~ ERROR rustc_outlives
{
foo: Box<dyn Trait<'a, A>>
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/explicit-dyn.rs:7:1
|
LL | struct Foo<'a, A>
| ^^^^^^^^^^^^^^^^^
|
= note: A: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
enum Foo<'a, U> { //~ ERROR rustc_outlives
One(Bar<'a, U>)
}
struct Bar<'x, T> where T: 'x {
x: &'x (),
y: T,
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/explicit-enum.rs:4:1
|
LL | enum Foo<'a, U> {
| ^^^^^^^^^^^^^^^
|
= note: U: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
trait Trait<'x, T> where T: 'x {
type Type;
}
#[rustc_outlives]
struct Foo<'a, A, B> where A: Trait<'a, B> //~ ERROR rustc_outlives
{
foo: <A as Trait<'a, B>>::Type
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/explicit-projection.rs:8:1
|
LL | struct Foo<'a, A, B> where A: Trait<'a, B>
| ^^^^^^^^^^^^^^^^^^^^
|
= note: B: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'b, U> { //~ ERROR rustc_outlives
bar: Bar<'b, U>
}
struct Bar<'a, T> where T: 'a {
x: &'a (),
y: T,
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/explicit-struct.rs:4:1
|
LL | struct Foo<'b, U> {
| ^^^^^^^^^^^^^^^^^
|
= note: U: 'b
error: aborting due to previous error

View File

@@ -0,0 +1,14 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
union Foo<'b, U: Copy> { //~ ERROR rustc_outlives
bar: Bar<'b, U>
}
#[derive(Clone, Copy)]
union Bar<'a, T: Copy> where T: 'a {
x: &'a (),
y: T,
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/explicit-union.rs:4:1
|
LL | union Foo<'b, U: Copy> {
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: U: 'b
error: aborting due to previous error

View File

@@ -0,0 +1,17 @@
// Regression test for #54467:
//
// Here, the trait object has an "inferred outlives" requirement that
// `<Self as MyIterator<'a>>::Item: 'a`; but since we don't know what
// `Self` is, we were (incorrectly) messing things up, leading to
// strange errors. This test ensures that we do not give compilation
// errors.
//
// check-pass
trait MyIterator<'a>: Iterator where Self::Item: 'a { }
struct MyStruct<'a, A> {
item: Box<dyn MyIterator<'a, Item = A>>
}
fn main() { }

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
enum Foo<'a, T> { //~ ERROR rustc_outlives
One(Bar<'a, T>)
}
struct Bar<'b, U> {
field2: &'b U
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/nested-enum.rs:4:1
|
LL | enum Foo<'a, T> {
| ^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,8 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, 'b, T> { //~ ERROR rustc_outlives
x: &'a &'b T
}
fn main() {}

View File

@@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/nested-regions.rs:4:1
|
LL | struct Foo<'a, 'b, T> {
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: 'b: 'a
= note: T: 'a
= note: T: 'b
error: aborting due to previous error

View File

@@ -0,0 +1,12 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, T> { //~ ERROR rustc_outlives
field1: Bar<'a, T>
}
struct Bar<'b, U> {
field2: &'b U
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/nested-structs.rs:4:1
|
LL | struct Foo<'a, T> {
| ^^^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,14 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
union Foo<'a, T: Copy> { //~ ERROR rustc_outlives
field1: Bar<'a, T>
}
// Type U needs to outlive lifetime 'b
#[derive(Clone, Copy)]
union Bar<'b, U: Copy> {
field2: &'b U
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/nested-union.rs:4:1
|
LL | union Foo<'a, T: Copy> {
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,20 @@
// Test that we do not get a privacy error here. Initially, we did,
// because we inferred an outlives predciate of `<Foo<'a> as
// Private>::Out: 'a`, but the private trait is -- well -- private,
// and hence it was not something that a pub trait could refer to.
//
// run-pass
#![allow(dead_code)]
pub struct Foo<'a> {
field: Option<&'a <Foo<'a> as Private>::Out>
}
trait Private {
type Out: ?Sized;
}
impl<T: ?Sized> Private for T { type Out = Self; }
fn main() { }

View File

@@ -0,0 +1,8 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, T: Iterator> { //~ ERROR rustc_outlives
bar: &'a T::Item
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/projection.rs:4:1
|
LL | struct Foo<'a, T: Iterator> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: <T as Iterator>::Item: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,8 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, T> { //~ ERROR rustc_outlives
bar: &'a T,
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/reference.rs:4:1
|
LL | struct Foo<'a, T> {
| ^^^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,39 @@
// Various examples of structs whose fields are not well-formed.
#![allow(dead_code)]
trait Dummy<'a> {
type Out;
}
impl<'a, T> Dummy<'a> for T
where
T: 'a,
{
type Out = ();
}
type RequireOutlives<'a, T> = <T as Dummy<'a>>::Out;
enum Ref1<'a, T> {
Ref1Variant1(RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough
}
enum Ref2<'a, T> {
Ref2Variant1,
Ref2Variant2(isize, RequireOutlives<'a, T>), //~ ERROR the parameter type `T` may not live long enough
}
enum RefOk<'a, T: 'a> {
RefOkVariant1(&'a T),
}
// This is now well formed. RFC 2093
enum RefIndirect<'a, T> {
RefIndirectVariant1(isize, RefOk<'a, T>),
}
enum RefDouble<'a, 'b, T> {
RefDoubleVariant1(&'a RequireOutlives<'b, T>),
//~^ the parameter type `T` may not live long enough [E0309]
}
fn main() {}

View File

@@ -0,0 +1,36 @@
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/regions-enum-not-wf.rs:17:18
|
LL | Ref1Variant1(RequireOutlives<'a, T>),
| ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | enum Ref1<'a, T: 'a> {
| ++++
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/regions-enum-not-wf.rs:22:25
|
LL | Ref2Variant2(isize, RequireOutlives<'a, T>),
| ^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | enum Ref2<'a, T: 'a> {
| ++++
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/regions-enum-not-wf.rs:35:23
|
LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | enum RefDouble<'a, 'b, T: 'b> {
| ++++
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0309`.

View File

@@ -0,0 +1,22 @@
// Test that a nominal type (like `Foo<'a>`) outlives `'b` if its
// arguments (like `'a`) outlive `'b`.
//
// Rule OutlivesNominalType from RFC 1214.
#![allow(dead_code)]
mod rev_variant_struct_region {
struct Foo<'a> {
x: fn(&'a i32),
}
trait Trait<'a, 'b> {
type Out;
}
impl<'a, 'b> Trait<'a, 'b> for usize {
type Out = &'a Foo<'b>; //~ ERROR reference has a longer lifetime
}
}
fn main() { }

View File

@@ -0,0 +1,20 @@
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:20
|
LL | type Out = &'a Foo<'b>;
| ^^^^^^^^^^^
|
note: the pointer is valid for the lifetime `'a` as defined here
--> $DIR/regions-outlives-nominal-type-region-rev.rs:16:10
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
note: but the referenced data is only valid for the lifetime `'b` as defined here
--> $DIR/regions-outlives-nominal-type-region-rev.rs:16:14
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.

View File

@@ -0,0 +1,22 @@
// Test that a nominal type (like `Foo<'a>`) outlives `'b` if its
// arguments (like `'a`) outlive `'b`.
//
// Rule OutlivesNominalType from RFC 1214.
#![allow(dead_code)]
mod variant_struct_region {
struct Foo<'a> {
x: &'a i32,
}
trait Trait<'a, 'b> {
type Out;
}
impl<'a, 'b> Trait<'a, 'b> for usize {
type Out = &'a Foo<'b>; //~ ERROR reference has a longer lifetime
}
}
fn main() { }

View File

@@ -0,0 +1,20 @@
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
--> $DIR/regions-outlives-nominal-type-region.rs:17:20
|
LL | type Out = &'a Foo<'b>;
| ^^^^^^^^^^^
|
note: the pointer is valid for the lifetime `'a` as defined here
--> $DIR/regions-outlives-nominal-type-region.rs:16:10
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
note: but the referenced data is only valid for the lifetime `'b` as defined here
--> $DIR/regions-outlives-nominal-type-region.rs:16:14
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.

View File

@@ -0,0 +1,22 @@
// Test that a nominal type (like `Foo<'a>`) outlives `'b` if its
// arguments (like `'a`) outlive `'b`.
//
// Rule OutlivesNominalType from RFC 1214.
#![allow(dead_code)]
mod variant_struct_type {
struct Foo<T> {
x: fn(T)
}
trait Trait<'a, 'b> {
type Out;
}
impl<'a, 'b> Trait<'a, 'b> for usize {
type Out = &'a Foo<&'b i32>; //~ ERROR reference has a longer lifetime
}
}
fn main() { }

View File

@@ -0,0 +1,20 @@
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:20
|
LL | type Out = &'a Foo<&'b i32>;
| ^^^^^^^^^^^^^^^^
|
note: the pointer is valid for the lifetime `'a` as defined here
--> $DIR/regions-outlives-nominal-type-type-rev.rs:16:10
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
note: but the referenced data is only valid for the lifetime `'b` as defined here
--> $DIR/regions-outlives-nominal-type-type-rev.rs:16:14
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.

View File

@@ -0,0 +1,22 @@
// Test that a nominal type (like `Foo<'a>`) outlives `'b` if its
// arguments (like `'a`) outlive `'b`.
//
// Rule OutlivesNominalType from RFC 1214.
#![allow(dead_code)]
mod variant_struct_type {
struct Foo<T> {
x: T
}
trait Trait<'a, 'b> {
type Out;
}
impl<'a, 'b> Trait<'a, 'b> for usize {
type Out = &'a Foo<&'b i32>; //~ ERROR reference has a longer lifetime
}
}
fn main() { }

View File

@@ -0,0 +1,20 @@
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
--> $DIR/regions-outlives-nominal-type-type.rs:17:20
|
LL | type Out = &'a Foo<&'b i32>;
| ^^^^^^^^^^^^^^^^
|
note: the pointer is valid for the lifetime `'a` as defined here
--> $DIR/regions-outlives-nominal-type-type.rs:16:10
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
note: but the referenced data is only valid for the lifetime `'b` as defined here
--> $DIR/regions-outlives-nominal-type-type.rs:16:14
|
LL | impl<'a, 'b> Trait<'a, 'b> for usize {
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.

View File

@@ -0,0 +1,28 @@
// Various examples of structs whose fields are not well-formed.
#![allow(dead_code)]
trait Trait<'a, T> {
type Out;
}
trait Trait1<'a, 'b, T> {
type Out;
}
impl<'a, T> Trait<'a, T> for usize {
type Out = &'a T; //~ ERROR `T` may not live long enough
}
struct RefOk<'a, T:'a> {
field: &'a T
}
impl<'a, T> Trait<'a, T> for u32 {
type Out = RefOk<'a, T>; //~ ERROR `T` may not live long enough
}
impl<'a, 'b, T> Trait1<'a, 'b, T> for u32 {
type Out = &'a &'b T; //~ ERROR reference has a longer lifetime than the data
}
fn main() { }

View File

@@ -0,0 +1,48 @@
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/regions-struct-not-wf.rs:13:16
|
LL | type Out = &'a T;
| ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound...
|
LL | impl<'a, T: 'a> Trait<'a, T> for usize {
| ++++
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/regions-struct-not-wf.rs:21:16
|
LL | type Out = RefOk<'a, T>;
| ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
|
note: ...that is required by this bound
--> $DIR/regions-struct-not-wf.rs:16:20
|
LL | struct RefOk<'a, T:'a> {
| ^^
help: consider adding an explicit lifetime bound...
|
LL | impl<'a, T: 'a> Trait<'a, T> for u32 {
| ++++
error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data it references
--> $DIR/regions-struct-not-wf.rs:25:16
|
LL | type Out = &'a &'b T;
| ^^^^^^^^^
|
note: the pointer is valid for the lifetime `'a` as defined here
--> $DIR/regions-struct-not-wf.rs:24:6
|
LL | impl<'a, 'b, T> Trait1<'a, 'b, T> for u32 {
| ^^
note: but the referenced data is only valid for the lifetime `'b` as defined here
--> $DIR/regions-struct-not-wf.rs:24:10
|
LL | impl<'a, 'b, T> Trait1<'a, 'b, T> for u32 {
| ^^
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0309, E0491.
For more information about an error, try `rustc --explain E0309`.

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
trait Trait<'x, 's, T> where T: 'x,
's: {
}
#[rustc_outlives]
struct Foo<'a, 'b, A> //~ ERROR rustc_outlives
{
foo: Box<dyn Trait<'a, 'b, A>>
}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/self-dyn.rs:8:1
|
LL | struct Foo<'a, 'b, A>
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: A: 'a
error: aborting due to previous error

View File

@@ -0,0 +1,13 @@
#![feature(rustc_attrs)]
#[rustc_outlives]
struct Foo<'a, 'b, T> { //~ ERROR rustc_outlives
field1: dyn Bar<'a, 'b, T>
}
trait Bar<'x, 's, U>
where U: 'x,
Self:'s
{}
fn main() {}

View File

@@ -0,0 +1,10 @@
error: rustc_outlives
--> $DIR/self-structs.rs:4:1
|
LL | struct Foo<'a, 'b, T> {
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: T: 'a
error: aborting due to previous error