diff options
| author | Alexander Regueiro <alexreg@me.com> | 2018-10-22 01:58:34 +0100 |
|---|---|---|
| committer | Alexander Regueiro <alexreg@me.com> | 2018-11-03 04:09:34 +0000 |
| commit | 4751953d5f2cd88243e3fac9a84271ed7a2636b4 (patch) | |
| tree | 0a1ccc463583f7d85f6423667282d2eeb57cd6ba | |
| parent | 90041d638b1363d3ed89dde8245563bac4c4062c (diff) | |
| download | rust-4751953d5f2cd88243e3fac9a84271ed7a2636b4.tar.gz rust-4751953d5f2cd88243e3fac9a84271ed7a2636b4.zip | |
Added tests.
| -rw-r--r-- | src/test/run-pass/traits/trait-alias-bounds.rs (renamed from src/test/ui/traits/trait-alias.rs) | 19 | ||||
| -rw-r--r-- | src/test/run-pass/traits/trait-alias-object-type.rs (renamed from src/test/run-pass/traits/trait-alias.rs) | 19 | ||||
| -rw-r--r-- | src/test/ui/codemap_tests/two_files.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-trait-alias.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-trait-alias.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/resolve/issue-3907.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/resolve/issue-5035.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/trait-alias-fail.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/traits/trait-alias-fail.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/traits/trait-alias-fail.stderr (renamed from src/test/ui/trait-alias-fail.stderr) | 26 | ||||
| -rw-r--r-- | src/test/ui/traits/trait-alias.stderr | 39 |
12 files changed, 82 insertions, 108 deletions
diff --git a/src/test/ui/traits/trait-alias.rs b/src/test/run-pass/traits/trait-alias-bounds.rs index 9ea211b4d7d..0d59c8e0bd1 100644 --- a/src/test/ui/traits/trait-alias.rs +++ b/src/test/run-pass/traits/trait-alias-bounds.rs @@ -1,4 +1,4 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,21 +10,23 @@ #![feature(trait_alias)] -trait SimpleAlias = Default; //~ERROR E0645 -trait GenericAlias<T> = Iterator<Item=T>; //~ERROR E0645 -trait Partial<T> = IntoIterator<Item=T>; //~ERROR E0645 +trait SimpleAlias = Default; +trait GenericAlias<T> = Iterator<Item=T>; +trait Partial<T> = IntoIterator<Item=T>; trait Things<T> {} trait Romeo {} +#[allow(dead_code)] struct The<T>(T); +#[allow(dead_code)] struct Fore<T>(T); impl<T, U> Things<T> for The<U> {} impl<T> Romeo for Fore<T> {} -trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo; //~ERROR E0645 -trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>; //~ERROR E0645 +trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo; +trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>; -trait CD = Clone + Default; //~ERROR E0645 +trait CD = Clone + Default; fn foo<T: CD>() -> (T, T) { let one = T::default(); @@ -33,11 +35,10 @@ fn foo<T: CD>() -> (T, T) { } fn main() { - let both = foo(); + let both = foo::<i32>(); assert_eq!(both.0, 0); assert_eq!(both.1, 0); let both: (i32, i32) = foo(); assert_eq!(both.0, 0); assert_eq!(both.1, 0); } - diff --git a/src/test/run-pass/traits/trait-alias.rs b/src/test/run-pass/traits/trait-alias-object-type.rs index 604344c93c2..3f0be573b28 100644 --- a/src/test/run-pass/traits/trait-alias.rs +++ b/src/test/run-pass/traits/trait-alias-object-type.rs @@ -10,19 +10,12 @@ #![feature(trait_alias)] -type Foo = std::fmt::Debug; -type Bar = Foo; - -fn foo<T: Foo>(v: &T) { - println!("{:?}", v); -} +trait Foo = PartialEq<i32> + Send; +trait Bar = Foo + Sync; pub fn main() { - foo(&12345); - - let bar1: &Bar = &54321; - println!("{:?}", bar1); - - let bar2 = Box::new(42) as Box<dyn Foo>; - println!("{:?}", bar2); + let a: &Bar = &123; + assert!(*a == 123); + let b = Box::new(456) as Box<dyn Foo>; + assert!(*b == 456); } diff --git a/src/test/ui/codemap_tests/two_files.stderr b/src/test/ui/codemap_tests/two_files.stderr index e247e86fbcb..f60f1dfcf37 100644 --- a/src/test/ui/codemap_tests/two_files.stderr +++ b/src/test/ui/codemap_tests/two_files.stderr @@ -2,7 +2,9 @@ error[E0404]: expected trait, found type alias `Bar` --> $DIR/two_files.rs:15:6 | LL | impl Bar for Baz { } //~ ERROR expected trait, found type alias - | ^^^ type aliases cannot be used for traits + | ^^^ type aliases cannot be used as traits + | + = note: did you mean to use a trait alias? error: aborting due to previous error diff --git a/src/test/ui/feature-gates/feature-gate-trait-alias.rs b/src/test/ui/feature-gates/feature-gate-trait-alias.rs new file mode 100644 index 00000000000..a2a183f80f9 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-trait-alias.rs @@ -0,0 +1,13 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo = Default; + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-trait-alias.stderr b/src/test/ui/feature-gates/feature-gate-trait-alias.stderr new file mode 100644 index 00000000000..e02dfe27805 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-trait-alias.stderr @@ -0,0 +1,11 @@ +error[E0658]: trait aliases are experimental (see issue #41517) + --> $DIR/feature-gate-trait-alias.rs:11:1 + | +LL | trait Foo = Default; + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(trait_alias)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/resolve/issue-3907.stderr b/src/test/ui/resolve/issue-3907.stderr index 3627c09b28f..3e330f9de65 100644 --- a/src/test/ui/resolve/issue-3907.stderr +++ b/src/test/ui/resolve/issue-3907.stderr @@ -2,7 +2,9 @@ error[E0404]: expected trait, found type alias `Foo` --> $DIR/issue-3907.rs:20:6 | LL | impl Foo for S { //~ ERROR expected trait, found type alias `Foo` - | ^^^ type aliases cannot be used for traits + | ^^^ type aliases cannot be used as traits + | + = note: did you mean to use a trait alias? help: possible better candidate is found in another module, you can import it into scope | LL | use issue_3907::Foo; diff --git a/src/test/ui/resolve/issue-5035.stderr b/src/test/ui/resolve/issue-5035.stderr index 353a0b1c3d9..0acc5c8a93e 100644 --- a/src/test/ui/resolve/issue-5035.stderr +++ b/src/test/ui/resolve/issue-5035.stderr @@ -11,7 +11,9 @@ LL | impl K for isize {} //~ ERROR expected trait, found type alias `K` | ^ | | | did you mean `I`? - | type aliases cannot be used for traits + | type aliases cannot be used as traits + | + = note: did you mean to use a trait alias? error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr b/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr index f32c5e9b2c6..d293a77392e 100644 --- a/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr +++ b/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr @@ -8,7 +8,9 @@ error[E0404]: expected trait, found type alias `Typedef` --> $DIR/unboxed-closure-sugar-nonexistent-trait.rs:16:8 | LL | fn g<F:Typedef(isize) -> isize>(x: F) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used for traits + | ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used as traits + | + = note: did you mean to use a trait alias? error: aborting due to 2 previous errors diff --git a/src/test/ui/trait-alias-fail.rs b/src/test/ui/trait-alias-fail.rs deleted file mode 100644 index 7aca227a76c..00000000000 --- a/src/test/ui/trait-alias-fail.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// gate-test-trait_alias - -trait Alias1<T> = Default where T: Clone; // ok - //~^ERROR trait aliases are not yet fully implemented -trait Alias2<T: Clone = ()> = Default; - //~^ERROR type parameters on the left side of a trait alias cannot be bounded - //~^^ERROR type parameters on the left side of a trait alias cannot have defaults - //~^^^ERROR trait aliases are not yet fully implemented - -impl Alias1 { //~ERROR expected type, found trait alias -} - -impl Alias1 for () { //~ERROR expected trait, found trait alias -} - -fn main() {} - diff --git a/src/test/ui/traits/trait-alias-fail.rs b/src/test/ui/traits/trait-alias-fail.rs new file mode 100644 index 00000000000..3a47593a8e1 --- /dev/null +++ b/src/test/ui/traits/trait-alias-fail.rs @@ -0,0 +1,20 @@ +// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// gate-test-trait_alias + +trait Alias1<T> = Default where T: Clone; +trait Alias2<T: Clone = ()> = Default; + +impl Alias1 {} + +impl Alias1 for () {} + +fn main() {} diff --git a/src/test/ui/trait-alias-fail.stderr b/src/test/ui/traits/trait-alias-fail.stderr index f7b144c06f8..829a316ccb8 100644 --- a/src/test/ui/trait-alias-fail.stderr +++ b/src/test/ui/traits/trait-alias-fail.stderr @@ -1,44 +1,38 @@ error: type parameters on the left side of a trait alias cannot be bounded - --> $DIR/trait-alias-fail.rs:15:14 + --> $DIR/trait-alias-fail.rs:14:14 | LL | trait Alias2<T: Clone = ()> = Default; | ^ error: type parameters on the left side of a trait alias cannot have defaults - --> $DIR/trait-alias-fail.rs:15:14 + --> $DIR/trait-alias-fail.rs:14:14 | LL | trait Alias2<T: Clone = ()> = Default; | ^ -error[E0573]: expected type, found trait alias `Alias1` - --> $DIR/trait-alias-fail.rs:20:6 - | -LL | impl Alias1 { //~ERROR expected type, found trait alias - | ^^^^^^ not a type - error[E0404]: expected trait, found trait alias `Alias1` - --> $DIR/trait-alias-fail.rs:23:6 + --> $DIR/trait-alias-fail.rs:18:6 | -LL | impl Alias1 for () { //~ERROR expected trait, found trait alias +LL | impl Alias1 for () {} | ^^^^^^ not a trait -error[E0658]: trait aliases are not yet fully implemented (see issue #41517) +error[E0658]: trait aliases are experimental (see issue #41517) --> $DIR/trait-alias-fail.rs:13:1 | -LL | trait Alias1<T> = Default where T: Clone; // ok +LL | trait Alias1<T> = Default where T: Clone; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(trait_alias)] to the crate attributes to enable -error[E0658]: trait aliases are not yet fully implemented (see issue #41517) - --> $DIR/trait-alias-fail.rs:15:1 +error[E0658]: trait aliases are experimental (see issue #41517) + --> $DIR/trait-alias-fail.rs:14:1 | LL | trait Alias2<T: Clone = ()> = Default; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(trait_alias)] to the crate attributes to enable -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors -Some errors occurred: E0404, E0573, E0658. +Some errors occurred: E0404, E0658. For more information about an error, try `rustc --explain E0404`. diff --git a/src/test/ui/traits/trait-alias.stderr b/src/test/ui/traits/trait-alias.stderr deleted file mode 100644 index 5d290e5c7fb..00000000000 --- a/src/test/ui/traits/trait-alias.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:13:1 - | -LL | trait SimpleAlias = Default; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:14:1 - | -LL | trait GenericAlias<T> = Iterator<Item=T>; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:15:1 - | -LL | trait Partial<T> = IntoIterator<Item=T>; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:24:1 - | -LL | trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:25:1 - | -LL | trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0645]: trait aliases are not yet implemented (see issue #41517) - --> $DIR/trait-alias.rs:27:1 - | -LL | trait CD = Clone + Default; //~ERROR E0645 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0645`. |
