Skip to content

Commit 1a3f0c1

Browse files
author
Alexander Regueiro
committed
Added tests.
1 parent 1c92ba7 commit 1a3f0c1

12 files changed

+82
-108
lines changed

src/test/ui/traits/trait-alias.rs renamed to src/test/run-pass/traits/trait-alias-bounds.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -10,21 +10,23 @@
1010

1111
#![feature(trait_alias)]
1212

13-
trait SimpleAlias = Default; //~ERROR E0645
14-
trait GenericAlias<T> = Iterator<Item=T>; //~ERROR E0645
15-
trait Partial<T> = IntoIterator<Item=T>; //~ERROR E0645
13+
trait SimpleAlias = Default;
14+
trait GenericAlias<T> = Iterator<Item=T>;
15+
trait Partial<T> = IntoIterator<Item=T>;
1616

1717
trait Things<T> {}
1818
trait Romeo {}
19+
#[allow(dead_code)]
1920
struct The<T>(T);
21+
#[allow(dead_code)]
2022
struct Fore<T>(T);
2123
impl<T, U> Things<T> for The<U> {}
2224
impl<T> Romeo for Fore<T> {}
2325

24-
trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo; //~ERROR E0645
25-
trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>; //~ERROR E0645
26+
trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo;
27+
trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>;
2628

27-
trait CD = Clone + Default; //~ERROR E0645
29+
trait CD = Clone + Default;
2830

2931
fn foo<T: CD>() -> (T, T) {
3032
let one = T::default();
@@ -33,11 +35,10 @@ fn foo<T: CD>() -> (T, T) {
3335
}
3436

3537
fn main() {
36-
let both = foo();
38+
let both = foo::<i32>();
3739
assert_eq!(both.0, 0);
3840
assert_eq!(both.1, 0);
3941
let both: (i32, i32) = foo();
4042
assert_eq!(both.0, 0);
4143
assert_eq!(both.1, 0);
4244
}
43-

src/test/run-pass/traits/trait-alias.rs renamed to src/test/run-pass/traits/trait-alias-object-type.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@
1010

1111
#![feature(trait_alias)]
1212

13-
type Foo = std::fmt::Debug;
14-
type Bar = Foo;
15-
16-
fn foo<T: Foo>(v: &T) {
17-
println!("{:?}", v);
18-
}
13+
trait Foo = PartialEq<i32> + Send;
14+
trait Bar = Foo + Sync;
1915

2016
pub fn main() {
21-
foo(&12345);
22-
23-
let bar1: &Bar = &54321;
24-
println!("{:?}", bar1);
25-
26-
let bar2 = Box::new(42) as Box<dyn Foo>;
27-
println!("{:?}", bar2);
17+
let a: &Bar = &123;
18+
assert!(*a == 123);
19+
let b = Box::new(456) as Box<dyn Foo>;
20+
assert!(*b == 456);
2821
}

src/test/ui/codemap_tests/two_files.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0404]: expected trait, found type alias `Bar`
22
--> $DIR/two_files.rs:15:6
33
|
44
LL | impl Bar for Baz { } //~ ERROR expected trait, found type alias
5-
| ^^^ type aliases cannot be used for traits
5+
| ^^^ type aliases cannot be used as traits
6+
|
7+
= note: did you mean to use a trait alias?
68

79
error: aborting due to previous error
810

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo = Default;
12+
13+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: trait aliases are experimental (see issue #41517)
2+
--> $DIR/feature-gate-trait-alias.rs:11:1
3+
|
4+
LL | trait Foo = Default;
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(trait_alias)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/resolve/issue-3907.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0404]: expected trait, found type alias `Foo`
22
--> $DIR/issue-3907.rs:20:6
33
|
44
LL | impl Foo for S { //~ ERROR expected trait, found type alias `Foo`
5-
| ^^^ type aliases cannot be used for traits
5+
| ^^^ type aliases cannot be used as traits
6+
|
7+
= note: did you mean to use a trait alias?
68
help: possible better candidate is found in another module, you can import it into scope
79
|
810
LL | use issue_3907::Foo;

src/test/ui/resolve/issue-5035.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ LL | impl K for isize {} //~ ERROR expected trait, found type alias `K`
1111
| ^
1212
| |
1313
| did you mean `I`?
14-
| type aliases cannot be used for traits
14+
| type aliases cannot be used as traits
15+
|
16+
= note: did you mean to use a trait alias?
1517

1618
error: aborting due to 2 previous errors
1719

src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ error[E0404]: expected trait, found type alias `Typedef`
88
--> $DIR/unboxed-closure-sugar-nonexistent-trait.rs:16:8
99
|
1010
LL | fn g<F:Typedef(isize) -> isize>(x: F) {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used for traits
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used as traits
12+
|
13+
= note: did you mean to use a trait alias?
1214

1315
error: aborting due to 2 previous errors
1416

src/test/ui/trait-alias-fail.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// gate-test-trait_alias
12+
13+
trait Alias1<T> = Default where T: Clone;
14+
trait Alias2<T: Clone = ()> = Default;
15+
16+
impl Alias1 {}
17+
18+
impl Alias1 for () {}
19+
20+
fn main() {}
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
error: type parameters on the left side of a trait alias cannot be bounded
2-
--> $DIR/trait-alias-fail.rs:15:14
2+
--> $DIR/trait-alias-fail.rs:14:14
33
|
44
LL | trait Alias2<T: Clone = ()> = Default;
55
| ^
66

77
error: type parameters on the left side of a trait alias cannot have defaults
8-
--> $DIR/trait-alias-fail.rs:15:14
8+
--> $DIR/trait-alias-fail.rs:14:14
99
|
1010
LL | trait Alias2<T: Clone = ()> = Default;
1111
| ^
1212

13-
error[E0573]: expected type, found trait alias `Alias1`
14-
--> $DIR/trait-alias-fail.rs:20:6
15-
|
16-
LL | impl Alias1 { //~ERROR expected type, found trait alias
17-
| ^^^^^^ not a type
18-
1913
error[E0404]: expected trait, found trait alias `Alias1`
20-
--> $DIR/trait-alias-fail.rs:23:6
14+
--> $DIR/trait-alias-fail.rs:18:6
2115
|
22-
LL | impl Alias1 for () { //~ERROR expected trait, found trait alias
16+
LL | impl Alias1 for () {}
2317
| ^^^^^^ not a trait
2418

25-
error[E0658]: trait aliases are not yet fully implemented (see issue #41517)
19+
error[E0658]: trait aliases are experimental (see issue #41517)
2620
--> $DIR/trait-alias-fail.rs:13:1
2721
|
28-
LL | trait Alias1<T> = Default where T: Clone; // ok
22+
LL | trait Alias1<T> = Default where T: Clone;
2923
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3024
|
3125
= help: add #![feature(trait_alias)] to the crate attributes to enable
3226

33-
error[E0658]: trait aliases are not yet fully implemented (see issue #41517)
34-
--> $DIR/trait-alias-fail.rs:15:1
27+
error[E0658]: trait aliases are experimental (see issue #41517)
28+
--> $DIR/trait-alias-fail.rs:14:1
3529
|
3630
LL | trait Alias2<T: Clone = ()> = Default;
3731
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3832
|
3933
= help: add #![feature(trait_alias)] to the crate attributes to enable
4034

41-
error: aborting due to 6 previous errors
35+
error: aborting due to 5 previous errors
4236

43-
Some errors occurred: E0404, E0573, E0658.
37+
Some errors occurred: E0404, E0658.
4438
For more information about an error, try `rustc --explain E0404`.

src/test/ui/traits/trait-alias.stderr

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)