Update tests.
This commit is contained in:
parent
aea954b74d
commit
fd7c253acc
@ -6,7 +6,7 @@ LL | let _: &I32Iterator<Item = u32> = &vec![42].into_iter();
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found type `i32`
|
||||
= note: required for the cast to the object type `dyn I32Iterator<Item = u32, Item = i32>`
|
||||
= note: required for the cast to the object type `dyn std::iter::Iterator<Item = u32, Item = i32>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,7 +2,9 @@ error[E0225]: only auto traits can be used as additional traits in a trait objec
|
||||
--> $DIR/bad-sized.rs:4:24
|
||||
|
|
||||
LL | let x: Vec<Trait + Sized> = Vec::new();
|
||||
| ^^^^^ non-auto additional trait
|
||||
| ----- ^^^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time
|
||||
--> $DIR/bad-sized.rs:4:12
|
||||
|
@ -2,16 +2,20 @@ error[E0225]: only auto traits can be used as additional traits in a trait objec
|
||||
--> $DIR/E0225.rs:6:32
|
||||
|
|
||||
LL | let _: Box<std::io::Read + std::io::Write>;
|
||||
| ^^^^^^^^^^^^^^ non-auto additional trait
|
||||
| ------------- ^^^^^^^^^^^^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/E0225.rs:8:16
|
||||
|
|
||||
LL | trait Foo = std::io::Read + std::io::Write;
|
||||
| -------------- non-auto additional trait
|
||||
| ------------- -------------- additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | let _: Box<Foo>;
|
||||
| ^^^ expanded from this alias
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -1,3 +1,11 @@
|
||||
error[E0393]: the type parameter `Rhs` must be explicitly specified
|
||||
--> $DIR/issue-22560.rs:6:13
|
||||
|
|
||||
LL | Sub;
|
||||
| ^^^ missing reference to `Rhs`
|
||||
|
|
||||
= note: because of the default `Self` reference, type parameters must be specified on object types
|
||||
|
||||
error[E0393]: the type parameter `Rhs` must be explicitly specified
|
||||
--> $DIR/issue-22560.rs:3:13
|
||||
|
|
||||
@ -6,29 +14,29 @@ LL | type Test = Add +
|
||||
|
|
||||
= note: because of the default `Self` reference, type parameters must be specified on object types
|
||||
|
||||
error[E0393]: the type parameter `Rhs` must be explicitly specified
|
||||
--> $DIR/issue-22560.rs:6:13
|
||||
|
|
||||
LL | Sub;
|
||||
| ^^^ missing reference to `Rhs`
|
||||
|
|
||||
= note: because of the default `Self` reference, type parameters must be specified on object types
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/issue-22560.rs:6:13
|
||||
|
|
||||
LL | type Test = Add +
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | Sub;
|
||||
| ^^^ non-auto additional trait
|
||||
| ^^^ additional non-auto trait
|
||||
|
||||
error[E0191]: the value of the associated type `Output` (from the trait `std::ops::Add`) must be specified
|
||||
error[E0191]: the value of the associated types `Output` (from the trait `std::ops::Add`), `Output` (from the trait `std::ops::Sub`) must be specified
|
||||
--> $DIR/issue-22560.rs:3:13
|
||||
|
|
||||
LL | type Test = Add +
|
||||
| _____________^
|
||||
| |_____________|
|
||||
| |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Sub;
|
||||
| |_______________^ associated type `Output` must be specified
|
||||
| | ^
|
||||
| |_______________|
|
||||
| |_______________associated type `Output` must be specified
|
||||
| associated type `Output` must be specified
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -2,7 +2,9 @@ error[E0225]: only auto traits can be used as additional traits in a trait objec
|
||||
--> $DIR/issue-32963.rs:8:25
|
||||
|
|
||||
LL | size_of_copy::<Misc+Copy>();
|
||||
| ^^^^ non-auto additional trait
|
||||
| ---- ^^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0277]: the trait bound `dyn Misc: std::marker::Copy` is not satisfied
|
||||
--> $DIR/issue-32963.rs:8:5
|
||||
|
@ -1,6 +1,6 @@
|
||||
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
|
||||
|
||||
type A1 = Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
|
||||
type A2 = for<'a> Tr + (?Sized); //~ ERROR `?Trait` is not permitted in trait object types
|
||||
type A1 = Tr + (?Sized);
|
||||
type A2 = for<'a> Tr + (?Sized);
|
||||
|
||||
fn main() {}
|
||||
|
@ -6,17 +6,5 @@ LL | trait Tr: ?Sized {}
|
||||
|
|
||||
= note: traits are `?Sized` by default
|
||||
|
||||
error: `?Trait` is not permitted in trait object types
|
||||
--> $DIR/maybe-bounds.rs:3:16
|
||||
|
|
||||
LL | type A1 = Tr + (?Sized);
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?Trait` is not permitted in trait object types
|
||||
--> $DIR/maybe-bounds.rs:4:24
|
||||
|
|
||||
LL | type A2 = for<'a> Tr + (?Sized);
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,9 +4,7 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {}
|
||||
|
||||
fn main() {
|
||||
let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
|
||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
||||
let _: Box<(?Sized) + (for<'a> Trait<'a>) + (Copy)>;
|
||||
let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
|
||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
||||
//~| ERROR use of undeclared lifetime name `'a`
|
||||
//~^ ERROR use of undeclared lifetime name `'a`
|
||||
}
|
||||
|
@ -1,21 +1,9 @@
|
||||
error: `?Trait` is not permitted in trait object types
|
||||
--> $DIR/trait-object-trait-parens.rs:6:25
|
||||
|
|
||||
LL | let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `?Trait` is not permitted in trait object types
|
||||
--> $DIR/trait-object-trait-parens.rs:9:47
|
||||
|
|
||||
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
|
||||
| ^^^^^^^^
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'a`
|
||||
--> $DIR/trait-object-trait-parens.rs:9:31
|
||||
--> $DIR/trait-object-trait-parens.rs:8:31
|
||||
|
|
||||
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
|
||||
| ^^ undeclared lifetime
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0261`.
|
||||
|
@ -1,9 +0,0 @@
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait EqAlias = Eq;
|
||||
trait IteratorAlias = Iterator;
|
||||
|
||||
fn main() {
|
||||
let _: &dyn EqAlias = &123; //~ ERROR `EqAlias` cannot be made into an object
|
||||
let _: &dyn IteratorAlias = &vec![123].into_iter(); //~ ERROR must be specified
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
use std::marker::PhantomData;
|
27
src/test/ui/traits/trait-alias/trait-alias-maybe-bound.rs
Normal file
27
src/test/ui/traits/trait-alias/trait-alias-maybe-bound.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Test that `dyn ... + ?Sized + ...` resulting from the expansion of trait aliases is okay.
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait S = ?Sized;
|
||||
|
||||
// Nest a couple of levels deep:
|
||||
trait _0 = S;
|
||||
trait _1 = _0;
|
||||
|
||||
// Straight list expansion:
|
||||
type _T0 = dyn _1;
|
||||
//~^ ERROR at least one non-builtin trait is required for an object type [E0224]
|
||||
|
||||
// In second position:
|
||||
type _T1 = dyn Copy + _1;
|
||||
|
||||
// ... and with an auto trait:
|
||||
type _T2 = dyn Copy + Send + _1;
|
||||
|
||||
// Twice:
|
||||
trait _2 = _1 + _1;
|
||||
|
||||
type _T3 = dyn _2;
|
||||
//~^ ERROR at least one non-builtin trait is required for an object type [E0224]
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,14 @@
|
||||
error[E0224]: at least one non-builtin trait is required for an object type
|
||||
--> $DIR/trait-alias-maybe-bound.rs:12:12
|
||||
|
|
||||
LL | type _T0 = dyn _1;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0224]: at least one non-builtin trait is required for an object type
|
||||
--> $DIR/trait-alias-maybe-bound.rs:24:12
|
||||
|
|
||||
LL | type _T3 = dyn _2;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
126
src/test/ui/traits/trait-alias/trait-alias-no-duplicates.rs
Normal file
126
src/test/ui/traits/trait-alias/trait-alias-no-duplicates.rs
Normal file
@ -0,0 +1,126 @@
|
||||
// The purpose of this test is to demonstrate that duplicating object safe traits
|
||||
// that are not auto traits is rejected with trait aliases even though one could
|
||||
// reasonably accept this.
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
use std::marker::Unpin;
|
||||
|
||||
// Some arbitray object-safe trait:
|
||||
trait Obj {}
|
||||
|
||||
// Nest a few levels deep:
|
||||
trait _0 = Obj;
|
||||
trait _1 = _0;
|
||||
|
||||
type _T00 = dyn _0 + _0;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T01 = dyn _1 + _0;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T02 = dyn _1 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T03 = dyn Obj + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T04 = dyn _1 + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Nest some more and in weird ways:
|
||||
|
||||
trait _2 = _0 + _1;
|
||||
trait _3 = Obj;
|
||||
trait _4 = _3;
|
||||
|
||||
type _T10 = dyn _2 + _3;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T11 = dyn _3 + _2;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T12 = dyn Obj + _2;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T13 = dyn _2 + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T14 = dyn _1 + _3;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T15 = dyn _3 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T16 = dyn _1 + _4;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T17 = dyn _4 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Include auto traits:
|
||||
|
||||
trait _5 = Obj + Send;
|
||||
|
||||
type _T20 = dyn _5 + _5;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T21 = dyn Obj + _5;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T22 = dyn _5 + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T23 = dyn _5 + Send + Sync + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Also nest:
|
||||
|
||||
trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
|
||||
|
||||
type _T30 = dyn _6;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T31 = dyn _6 + Send;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T32 = dyn Send + _6;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Nest some more:
|
||||
|
||||
trait _7 = _5 + Sync;
|
||||
trait _8 = Unpin + _7;
|
||||
|
||||
type _T40 = dyn _8 + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T41 = dyn Obj + _8;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T42 = dyn _8 + _4;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T43 = dyn _4 + _8;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T44 = dyn _4 + Send + Sync + _8;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Take higher ranked types into account.
|
||||
|
||||
// Note that `'a` and `'b` are intentionally different to make sure we consider
|
||||
// them semantically the same.
|
||||
trait ObjL<'l> {}
|
||||
trait _9 = for<'a> ObjL<'a>;
|
||||
trait _10 = for<'b> ObjL<'b>;
|
||||
type _T50 = _9 + _10;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
trait ObjT<T> {}
|
||||
trait _11 = ObjT<for<'a> fn(&'a u8)>;
|
||||
trait _12 = ObjT<for<'b> fn(&'b u8)>;
|
||||
type _T60 = _11 + _12;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
fn main() {}
|
358
src/test/ui/traits/trait-alias/trait-alias-no-duplicates.stderr
Normal file
358
src/test/ui/traits/trait-alias/trait-alias-no-duplicates.stderr
Normal file
@ -0,0 +1,358 @@
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:16:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | type _T00 = dyn _0 + _0;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:19:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | type _T01 = dyn _1 + _0;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:22:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T02 = dyn _1 + _1;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:25:23
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T03 = dyn Obj + _1;
|
||||
| --- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:28:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T04 = dyn _1 + Obj;
|
||||
| ^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:37:17
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _2 = _0 + _1;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T10 = dyn _2 + _3;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:40:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | trait _2 = _0 + _1;
|
||||
| -- referenced here
|
||||
LL | trait _3 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T11 = dyn _3 + _2;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:43:23
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | trait _2 = _0 + _1;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T12 = dyn Obj + _2;
|
||||
| --- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:46:17
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _2 = _0 + _1;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T13 = dyn _2 + Obj;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:49:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | trait _3 = Obj;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | type _T14 = dyn _1 + _3;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:52:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _3 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T15 = dyn _3 + _1;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:55:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | trait _3 = Obj;
|
||||
| --- additional non-auto trait
|
||||
LL | trait _4 = _3;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T16 = dyn _1 + _4;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:58:22
|
||||
|
|
||||
LL | trait _0 = Obj;
|
||||
| --- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _3 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T17 = dyn _4 + _1;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:65:22
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL |
|
||||
LL | type _T20 = dyn _5 + _5;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:68:23
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | type _T21 = dyn Obj + _5;
|
||||
| --- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:71:22
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T22 = dyn _5 + Obj;
|
||||
| ^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:74:36
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T23 = dyn _5 + Send + Sync + Obj;
|
||||
| ^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:81:17
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
|
||||
| -- referenced here
|
||||
LL |
|
||||
LL | type _T30 = dyn _6;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:84:17
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T31 = dyn _6 + Send;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:87:24
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| ---
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T32 = dyn Send + _6;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:95:22
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T40 = dyn _8 + Obj;
|
||||
| ^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:98:23
|
||||
|
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | trait _7 = _5 + Sync;
|
||||
| -- referenced here
|
||||
LL | trait _8 = Unpin + _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T41 = dyn Obj + _8;
|
||||
| --- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:101:22
|
||||
|
|
||||
LL | trait _3 = Obj;
|
||||
| --- additional non-auto trait
|
||||
LL | trait _4 = _3;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | type _T42 = dyn _8 + _4;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:104:22
|
||||
|
|
||||
LL | trait _3 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | trait _7 = _5 + Sync;
|
||||
| -- referenced here
|
||||
LL | trait _8 = Unpin + _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T43 = dyn _4 + _8;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:107:36
|
||||
|
|
||||
LL | trait _3 = Obj;
|
||||
| --- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Obj + Send;
|
||||
| --- additional non-auto trait
|
||||
...
|
||||
LL | trait _7 = _5 + Sync;
|
||||
| -- referenced here
|
||||
LL | trait _8 = Unpin + _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T44 = dyn _4 + Send + Sync + _8;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:117:18
|
||||
|
|
||||
LL | trait _9 = for<'a> ObjL<'a>;
|
||||
| ---------------- first non-auto trait
|
||||
LL | trait _10 = for<'b> ObjL<'b>;
|
||||
| ---------------- additional non-auto trait
|
||||
LL | type _T50 = _9 + _10;
|
||||
| ^^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-duplicates.rs:123:19
|
||||
|
|
||||
LL | trait _11 = ObjT<for<'a> fn(&'a u8)>;
|
||||
| ------------------------ first non-auto trait
|
||||
LL | trait _12 = ObjT<for<'b> fn(&'b u8)>;
|
||||
| ------------------------ additional non-auto trait
|
||||
LL | type _T60 = _11 + _12;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0225`.
|
121
src/test/ui/traits/trait-alias/trait-alias-no-extra-traits.rs
Normal file
121
src/test/ui/traits/trait-alias/trait-alias-no-extra-traits.rs
Normal file
@ -0,0 +1,121 @@
|
||||
// The purpose of this test is to demonstrate that trait alias expansion
|
||||
// preserves the rule that `dyn Trait` may only reference one non-auto trait.
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
use std::marker::Unpin;
|
||||
|
||||
// Some arbitray object-safe traits:
|
||||
trait ObjA {}
|
||||
trait ObjB {}
|
||||
|
||||
// Nest a few levels deep:
|
||||
trait _0 = ObjA;
|
||||
trait _1 = _0;
|
||||
|
||||
type _T00 = dyn _0 + ObjB;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T01 = dyn ObjB + _0;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T02 = dyn ObjB + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T03 = dyn _1 + ObjB;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Nest some more and in weird ways:
|
||||
|
||||
trait _2 = ObjB;
|
||||
trait _3 = _2;
|
||||
trait _4 = _3;
|
||||
|
||||
type _T10 = dyn _2 + _3;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T11 = dyn _3 + _2;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T12 = dyn _2 + _4;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T13 = dyn _4 + _2;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Include auto traits:
|
||||
|
||||
trait _5 = Sync + ObjB + Send;
|
||||
|
||||
type _T20 = dyn _5 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T21 = dyn _1 + _5;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T22 = dyn _5 + ObjA;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T23 = dyn ObjA + _5;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T24 = dyn Send + _5 + _1 + Sync;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T25 = dyn _1 + Sync + _5 + Send;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T26 = dyn Sync + Send + _5 + ObjA;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T27 = dyn Send + Sync + ObjA + _5;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Also nest:
|
||||
|
||||
trait _6 = _1 + _5;
|
||||
trait _7 = _6;
|
||||
trait _8 = _7;
|
||||
|
||||
type _T30 = dyn _6;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T31 = dyn _6 + Send;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T32 = dyn Send + _6;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T33 = dyn _8;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T34 = dyn _8 + Send;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T35 = dyn Send + _8;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Nest some more:
|
||||
|
||||
trait _9 = _5 + Sync;
|
||||
trait _10 = Unpin + _9;
|
||||
|
||||
type _T40 = dyn _10 + ObjA;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T41 = dyn ObjA + _10;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T42 = dyn _10 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T43 = dyn Send + _10 + Sync + ObjA;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T44 = dyn ObjA + _10 + Send + Sync;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _T45 = dyn Sync + Send + _10 + _1;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,371 @@
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:16:22
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T00 = dyn _0 + ObjB;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:19:24
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | type _T01 = dyn ObjB + _0;
|
||||
| ---- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:22:24
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T02 = dyn ObjB + _1;
|
||||
| ---- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:25:22
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T03 = dyn _1 + ObjB;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:34:22
|
||||
|
|
||||
LL | trait _2 = ObjB;
|
||||
| ----
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL | trait _3 = _2;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T10 = dyn _2 + _3;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:37:22
|
||||
|
|
||||
LL | trait _2 = ObjB;
|
||||
| ----
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | type _T11 = dyn _3 + _2;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:40:22
|
||||
|
|
||||
LL | trait _2 = ObjB;
|
||||
| ----
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
LL | trait _3 = _2;
|
||||
| -- referenced here
|
||||
LL | trait _4 = _3;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T12 = dyn _2 + _4;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:43:22
|
||||
|
|
||||
LL | trait _2 = ObjB;
|
||||
| ----
|
||||
| |
|
||||
| additional non-auto trait
|
||||
| first non-auto trait
|
||||
...
|
||||
LL | type _T13 = dyn _4 + _2;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:50:22
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
LL |
|
||||
LL | type _T20 = dyn _5 + _1;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:53:22
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | type _T21 = dyn _1 + _5;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:56:22
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T22 = dyn _5 + ObjA;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:59:24
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | type _T23 = dyn ObjA + _5;
|
||||
| ---- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:62:29
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T24 = dyn Send + _5 + _1 + Sync;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:65:29
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | type _T25 = dyn _1 + Sync + _5 + Send;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:68:36
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T26 = dyn Sync + Send + _5 + ObjA;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:71:38
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | type _T27 = dyn Send + Sync + ObjA + _5;
|
||||
| ---- ^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:80:17
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T30 = dyn _6;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:83:17
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T31 = dyn _6 + Send;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:86:24
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T32 = dyn Send + _6;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:89:17
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
LL | trait _7 = _6;
|
||||
| -- referenced here
|
||||
LL | trait _8 = _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T33 = dyn _8;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:92:17
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
LL | trait _7 = _6;
|
||||
| -- referenced here
|
||||
LL | trait _8 = _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T34 = dyn _8 + Send;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:95:24
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _6 = _1 + _5;
|
||||
| -- referenced here
|
||||
LL | trait _7 = _6;
|
||||
| -- referenced here
|
||||
LL | trait _8 = _7;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T35 = dyn Send + _8;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:103:23
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T40 = dyn _10 + ObjA;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:106:24
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _9 = _5 + Sync;
|
||||
| -- referenced here
|
||||
LL | trait _10 = Unpin + _9;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T41 = dyn ObjA + _10;
|
||||
| ---- ^^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:109:23
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T42 = dyn _10 + _1;
|
||||
| ^^
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:112:37
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T43 = dyn Send + _10 + Sync + ObjA;
|
||||
| ^^^^ additional non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:115:24
|
||||
|
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- additional non-auto trait
|
||||
...
|
||||
LL | trait _9 = _5 + Sync;
|
||||
| -- referenced here
|
||||
LL | trait _10 = Unpin + _9;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | type _T44 = dyn ObjA + _10 + Send + Sync;
|
||||
| ---- ^^^
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/trait-alias-no-extra-traits.rs:118:37
|
||||
|
|
||||
LL | trait _0 = ObjA;
|
||||
| ---- additional non-auto trait
|
||||
LL | trait _1 = _0;
|
||||
| -- referenced here
|
||||
...
|
||||
LL | trait _5 = Sync + ObjB + Send;
|
||||
| ---- first non-auto trait
|
||||
...
|
||||
LL | type _T45 = dyn Sync + Send + _10 + _1;
|
||||
| ^^
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0225`.
|
11
src/test/ui/traits/trait-alias/trait-alias-object-fail.rs
Normal file
11
src/test/ui/traits/trait-alias/trait-alias-object-fail.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait EqAlias = Eq;
|
||||
trait IteratorAlias = Iterator;
|
||||
|
||||
fn main() {
|
||||
let _: &dyn EqAlias = &123;
|
||||
//~^ ERROR the trait `std::cmp::Eq` cannot be made into an object [E0038]
|
||||
let _: &dyn IteratorAlias = &vec![123].into_iter();
|
||||
//~^ ERROR must be specified
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
error[E0038]: the trait `EqAlias` cannot be made into an object
|
||||
--> $DIR/trait-alias-object.rs:7:13
|
||||
error[E0038]: the trait `std::cmp::Eq` cannot be made into an object
|
||||
--> $DIR/trait-alias-object-fail.rs:7:13
|
||||
|
|
||||
LL | let _: &dyn EqAlias = &123;
|
||||
| ^^^^^^^^^^^ the trait `EqAlias` cannot be made into an object
|
||||
| ^^^^^^^^^^^ the trait `std::cmp::Eq` cannot be made into an object
|
||||
|
|
||||
= note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
|
||||
|
||||
error[E0191]: the value of the associated type `Item` (from the trait `std::iter::Iterator`) must be specified
|
||||
--> $DIR/trait-alias-object.rs:8:13
|
||||
--> $DIR/trait-alias-object-fail.rs:9:13
|
||||
|
|
||||
LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
|
||||
| ^^^^^^^^^^^^^^^^^ associated type `Item` must be specified
|
71
src/test/ui/traits/trait-alias/trait-alias-object-wf.rs
Normal file
71
src/test/ui/traits/trait-alias/trait-alias-object-wf.rs
Normal file
@ -0,0 +1,71 @@
|
||||
// run-pass
|
||||
|
||||
// This test checks that trait objects involving trait aliases are well-formed.
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait Obj {}
|
||||
|
||||
trait _0 = Send + Sync;
|
||||
|
||||
// Just auto traits:
|
||||
|
||||
trait _1 = _0 + Send + Sync;
|
||||
|
||||
use std::marker::Unpin;
|
||||
|
||||
type _T01 = dyn _0;
|
||||
type _T02 = dyn _1;
|
||||
type _T03 = dyn Unpin + _1 + Send + Sync;
|
||||
|
||||
// Include object safe traits:
|
||||
|
||||
type _T10 = dyn Obj + _0;
|
||||
type _T11 = dyn Obj + _1;
|
||||
type _T12 = dyn Obj + _1 + _0;
|
||||
|
||||
// And when the object safe trait is in a trait alias:
|
||||
|
||||
trait _2 = Obj;
|
||||
|
||||
type _T20 = dyn _2 + _0;
|
||||
type _T21 = dyn _2 + _1;
|
||||
type _T22 = dyn _2 + _1 + _0;
|
||||
|
||||
// And it should also work when that trait is has auto traits to the right of it.
|
||||
|
||||
trait _3 = Obj + Unpin;
|
||||
|
||||
type _T30 = dyn _3 + _0;
|
||||
type _T31 = dyn _3 + _1;
|
||||
type _T32 = dyn _3 + _1 + _0;
|
||||
|
||||
// Nest the trait deeply:
|
||||
|
||||
trait _4 = _3;
|
||||
trait _5 = _4 + Sync + _0 + Send;
|
||||
trait _6 = _5 + Send + _1 + Sync;
|
||||
|
||||
type _T60 = dyn _6 + _0;
|
||||
type _T61 = dyn _6 + _1;
|
||||
type _T62 = dyn _6 + _1 + _0;
|
||||
|
||||
// Just nest the trait alone:
|
||||
|
||||
trait _7 = _2;
|
||||
trait _8 = _7;
|
||||
trait _9 = _8;
|
||||
|
||||
type _T9 = dyn _9;
|
||||
|
||||
// First bound is auto trait:
|
||||
|
||||
trait _10 = Send + Obj;
|
||||
trait _11 = Obj + Send;
|
||||
trait _12 = Sync + _11;
|
||||
trait _13 = Send + _12;
|
||||
|
||||
type _T70 = dyn _0;
|
||||
type _T71 = dyn _3;
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait Foo = PartialEq<i32> + Send;
|
@ -1,11 +1,11 @@
|
||||
error: trait aliases cannot be `auto`
|
||||
--> $DIR/trait-alias-syntax.rs:4:19
|
||||
--> $DIR/trait-alias-syntax-fail.rs:4:19
|
||||
|
|
||||
LL | auto trait A = Foo;
|
||||
| ^ trait aliases cannot be `auto`
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-syntax.rs:5:21
|
||||
--> $DIR/trait-alias-syntax-fail.rs:5:21
|
||||
|
|
||||
LL | unsafe trait B = Foo;
|
||||
| ^ trait aliases cannot be `unsafe`
|
@ -1,3 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
trait SimpleAlias = Default;
|
@ -1,4 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
pub trait Foo {}
|
13
src/test/ui/traits/wf-trait-object-maybe-bound.rs
Normal file
13
src/test/ui/traits/wf-trait-object-maybe-bound.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// The purpose of this test is to demonstrate that `?Sized` is allowed in trait objects
|
||||
// (thought it has no effect).
|
||||
|
||||
type _0 = dyn ?Sized;
|
||||
//~^ ERROR at least one non-builtin trait is required for an object type [E0224]
|
||||
|
||||
type _1 = dyn Clone + ?Sized;
|
||||
|
||||
type _2 = dyn Clone + ?Sized + ?Sized;
|
||||
|
||||
type _3 = dyn ?Sized + Clone;
|
||||
|
||||
fn main() {}
|
8
src/test/ui/traits/wf-trait-object-maybe-bound.stderr
Normal file
8
src/test/ui/traits/wf-trait-object-maybe-bound.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error[E0224]: at least one non-builtin trait is required for an object type
|
||||
--> $DIR/wf-trait-object-maybe-bound.rs:4:11
|
||||
|
|
||||
LL | type _0 = dyn ?Sized;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
33
src/test/ui/traits/wf-trait-object-no-duplicates.rs
Normal file
33
src/test/ui/traits/wf-trait-object-no-duplicates.rs
Normal file
@ -0,0 +1,33 @@
|
||||
// The purpose of this test is to demonstrate that duplicating object safe traits
|
||||
// that are not auto-traits is rejected even though one could reasonably accept this.
|
||||
|
||||
// Some arbitray object-safe trait:
|
||||
trait Obj {}
|
||||
|
||||
// Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior:
|
||||
type _0 = dyn Obj + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
// Some variations:
|
||||
|
||||
type _1 = dyn Send + Obj + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _2 = dyn Obj + Send + Obj;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
type _3 = dyn Obj + Send + Send; // But it is OK to duplicate auto traits.
|
||||
|
||||
// Take higher ranked types into account.
|
||||
|
||||
// Note that `'a` and `'b` are intentionally different to make sure we consider
|
||||
// them semantically the same.
|
||||
trait ObjL<'l> {}
|
||||
type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
trait ObjT<T> {}
|
||||
type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
|
||||
//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
|
||||
|
||||
fn main() {}
|
43
src/test/ui/traits/wf-trait-object-no-duplicates.stderr
Normal file
43
src/test/ui/traits/wf-trait-object-no-duplicates.stderr
Normal file
@ -0,0 +1,43 @@
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/wf-trait-object-no-duplicates.rs:8:21
|
||||
|
|
||||
LL | type _0 = dyn Obj + Obj;
|
||||
| --- ^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/wf-trait-object-no-duplicates.rs:13:28
|
||||
|
|
||||
LL | type _1 = dyn Send + Obj + Obj;
|
||||
| --- ^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/wf-trait-object-no-duplicates.rs:16:28
|
||||
|
|
||||
LL | type _2 = dyn Obj + Send + Obj;
|
||||
| --- ^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/wf-trait-object-no-duplicates.rs:26:34
|
||||
|
|
||||
LL | type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
|
||||
| ---------------- ^^^^^^^^^^^^^^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error[E0225]: only auto traits can be used as additional traits in a trait object
|
||||
--> $DIR/wf-trait-object-no-duplicates.rs:30:42
|
||||
|
|
||||
LL | type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
|
||||
| ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^ additional non-auto trait
|
||||
| |
|
||||
| first non-auto trait
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0225`.
|
15
src/test/ui/traits/wf-trait-object-reverse-order.rs
Normal file
15
src/test/ui/traits/wf-trait-object-reverse-order.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// run-pass
|
||||
|
||||
// Ensure that `dyn $($AutoTrait) + ObjSafe` is well-formed.
|
||||
|
||||
use std::marker::Unpin;
|
||||
|
||||
// Some arbitray object-safe trait:
|
||||
trait Obj {}
|
||||
|
||||
type _0 = Unpin;
|
||||
type _1 = Send + Obj;
|
||||
type _2 = Send + Unpin + Obj;
|
||||
type _3 = Send + Unpin + Sync + Obj;
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user