Added WF checking for trait alias definitions.

This commit is contained in:
Alexander Regueiro 2018-11-01 18:17:58 +00:00
parent a62d0785a6
commit c04559fe9e
9 changed files with 64 additions and 71 deletions

View File

@ -153,6 +153,9 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
hir::ItemKind::Trait(..) => {
check_trait(tcx, item);
}
hir::ItemKind::TraitAlias(..) => {
check_trait(tcx, item);
}
_ => {}
}
}

View File

@ -1,46 +0,0 @@
error: type parameters on the left side of a trait alias cannot be bounded
--> $DIR/trait-alias-fail1.rs:14:20
|
LL | trait BoundedAlias<T: Clone = ()> = Default;
| ^
error: type parameters on the left side of a trait alias cannot have defaults
--> $DIR/trait-alias-fail1.rs:14:20
|
LL | trait BoundedAlias<T: Clone = ()> = Default;
| ^
error[E0404]: expected trait, found trait alias `CloneDefault`
--> $DIR/trait-alias-fail1.rs:19:6
|
LL | impl CloneDefault for () {}
| ^^^^^^^^^^^^ not a trait
error[E0658]: trait aliases are experimental (see issue #41517)
--> $DIR/trait-alias-fail1.rs:13:1
|
LL | trait CloneDefault<T> = Default where T: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trait_alias)] to the crate attributes to enable
error[E0658]: trait aliases are experimental (see issue #41517)
--> $DIR/trait-alias-fail1.rs:14:1
|
LL | trait BoundedAlias<T: Clone = ()> = Default;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trait_alias)] to the crate attributes to enable
error[E0658]: trait aliases are experimental (see issue #41517)
--> $DIR/trait-alias-fail1.rs:17:1
|
LL | trait B<T> = A<T>; // FIXME: parameter T should need a bound here, or semantics should be changed
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trait_alias)] to the crate attributes to enable
error: aborting due to 6 previous errors
Some errors occurred: E0404, E0658.
For more information about an error, try `rustc --explain E0404`.

View File

@ -1,19 +0,0 @@
error[E0658]: trait aliases are experimental (see issue #41517)
--> $DIR/trait-alias-fail2.rs:13:1
|
LL | trait EqAlias = Eq;
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trait_alias)] to the crate attributes to enable
error[E0658]: trait aliases are experimental (see issue #41517)
--> $DIR/trait-alias-fail2.rs:14:1
|
LL | trait IteratorAlias = Iterator;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trait_alias)] to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -0,0 +1,17 @@
// 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.
#![feature(trait_alias)]
trait DefaultAlias = Default;
impl DefaultAlias for () {}
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0404]: expected trait, found trait alias `DefaultAlias`
--> $DIR/trait-alias-impl.rs:15:6
|
LL | impl DefaultAlias for () {}
| ^^^^^^^^^^^^ not a trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0404`.

View File

@ -0,0 +1,18 @@
error[E0038]: the trait `EqAlias` cannot be made into an object
--> $DIR/trait-alias-objects.rs:17:13
|
LL | let _: &dyn EqAlias = &123;
| ^^^^^^^^^^^ the trait `EqAlias` 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-objects.rs:18:13
|
LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
| ^^^^^^^^^^^^^^^^^ missing associated type `Item` value
error: aborting due to 2 previous errors
Some errors occurred: E0038, E0191.
For more information about an error, try `rustc --explain E0038`.

View File

@ -1,4 +1,4 @@
// Copyright 2017-2018 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@ -10,13 +10,8 @@
#![feature(trait_alias)]
trait CloneDefault<T> = Default where T: Clone;
trait BoundedAlias<T: Clone = ()> = Default;
trait Foo {}
trait A<T: Foo> {}
trait B<T> = A<T>; // T cannot be unbounded
impl CloneDefault for () {}
fn main() {}

View File

@ -0,0 +1,16 @@
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/trait-alias-wf.rs:15:1
|
LL | trait B<T> = A<T>; // T cannot be unbounded
| ^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
= help: consider adding a `where T: Foo` bound
note: required by `A`
--> $DIR/trait-alias-wf.rs:14:1
|
LL | trait A<T: Foo> {}
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.