Skip to content

Commit 50c505d

Browse files
author
Alexander Regueiro
committed
Added WF checking for trait alias definitions.
1 parent e965837 commit 50c505d

9 files changed

+64
-71
lines changed

src/librustc_typeck/check/wfcheck.rs

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
153153
hir::ItemKind::Trait(..) => {
154154
check_trait(tcx, item);
155155
}
156+
hir::ItemKind::TraitAlias(..) => {
157+
check_trait(tcx, item);
158+
}
156159
_ => {}
157160
}
158161
}

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

-46
This file was deleted.

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

-19
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
#![feature(trait_alias)]
12+
13+
trait DefaultAlias = Default;
14+
15+
impl DefaultAlias for () {}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0404]: expected trait, found trait alias `DefaultAlias`
2+
--> $DIR/trait-alias-impl.rs:15:6
3+
|
4+
LL | impl DefaultAlias for () {}
5+
| ^^^^^^^^^^^^ not a trait
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0404`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0038]: the trait `EqAlias` cannot be made into an object
2+
--> $DIR/trait-alias-objects.rs:17:13
3+
|
4+
LL | let _: &dyn EqAlias = &123;
5+
| ^^^^^^^^^^^ the trait `EqAlias` cannot be made into an object
6+
|
7+
= note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
8+
9+
error[E0191]: the value of the associated type `Item` (from the trait `std::iter::Iterator`) must be specified
10+
--> $DIR/trait-alias-objects.rs:18:13
11+
|
12+
LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
13+
| ^^^^^^^^^^^^^^^^^ missing associated type `Item` value
14+
15+
error: aborting due to 2 previous errors
16+
17+
Some errors occurred: E0038, E0191.
18+
For more information about an error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 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,13 +10,8 @@
1010

1111
#![feature(trait_alias)]
1212

13-
trait CloneDefault<T> = Default where T: Clone;
14-
trait BoundedAlias<T: Clone = ()> = Default;
15-
1613
trait Foo {}
1714
trait A<T: Foo> {}
1815
trait B<T> = A<T>; // T cannot be unbounded
1916

20-
impl CloneDefault for () {}
21-
2217
fn main() {}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `T: Foo` is not satisfied
2+
--> $DIR/trait-alias-wf.rs:15:1
3+
|
4+
LL | trait B<T> = A<T>; // T cannot be unbounded
5+
| ^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
6+
|
7+
= help: consider adding a `where T: Foo` bound
8+
note: required by `A`
9+
--> $DIR/trait-alias-wf.rs:14:1
10+
|
11+
LL | trait A<T: Foo> {}
12+
| ^^^^^^^^^^^^^^^
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)