Skip to content

Commit

Permalink
Update tests for GATs
Browse files Browse the repository at this point in the history
* Make some run-pass or check-pass
* Use `#![allow(incomplete_features)]`
* Update FIXMEs now that some of the issues have been addressed
* Add regression tests
  • Loading branch information
matthewjasper committed Dec 21, 2019
1 parent 0a5c91c commit c268798
Show file tree
Hide file tree
Showing 61 changed files with 760 additions and 546 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::ops::Deref;
trait PointerFamily<U> {
type Pointer<T>: Deref<Target = T>;
//~^ ERROR generic associated types are unstable
//~| ERROR type-generic associated types are not yet implemented
type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
//~^ ERROR generic associated types are unstable
//~| ERROR where clauses on associated types are unstable
//~| ERROR type-generic associated types are not yet implemented
}

struct Foo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | type Pointer<T>: Deref<Target = T>;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:6:5
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:6:5
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -26,7 +26,7 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:14:5
--> $DIR/feature-gate-generic_associated_types.rs:16:5
|
LL | type Pointer<Usize> = Box<Usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -35,7 +35,7 @@ LL | type Pointer<Usize> = Box<Usize>;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:16:5
--> $DIR/feature-gate-generic_associated_types.rs:18:5
|
LL | type Pointer2<U32> = Box<U32>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -44,7 +44,7 @@ LL | type Pointer2<U32> = Box<U32>;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:21:5
--> $DIR/feature-gate-generic_associated_types.rs:23:5
|
LL | type Assoc where Self: Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -53,14 +53,30 @@ LL | type Assoc where Self: Sized;
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: where clauses on associated types are unstable
--> $DIR/feature-gate-generic_associated_types.rs:26:5
--> $DIR/feature-gate-generic_associated_types.rs:28:5
|
LL | type Assoc where Self: Sized = Foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error: aborting due to 7 previous errors
error: type-generic associated types are not yet implemented
--> $DIR/feature-gate-generic_associated_types.rs:4:5
|
LL | type Pointer<T>: Deref<Target = T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: type-generic associated types are not yet implemented
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
#![feature(associated_type_defaults)]

// FIXME(#44265): "lifetime arguments are not allowed for this type" errors will be addressed in a
// follow-up PR.

// A Collection trait and collection families. Based on
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/
// associated-type-constructors-part-2-family-traits/
Expand All @@ -15,18 +12,18 @@ trait Collection<T> {
// Test associated type defaults with parameters
type Sibling<U>: Collection<U> =
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^^ ERROR type-generic associated types are not yet implemented

fn empty() -> Self;

fn add(&mut self, value: T);

fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
//~^ ERROR lifetime arguments are not allowed for this type [E0109]
}

trait CollectionFamily {
type Member<T>: Collection<T, Family = Self>;
//~^ ERROR type-generic associated types are not yet implemented
}

struct VecFamily;
Expand All @@ -48,13 +45,11 @@ impl<T> Collection<T> for Vec<T> {
}

fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
//~^ ERROR lifetime arguments are not allowed for this type [E0109]
self.iter()
}
}

fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
//~^ ERROR type arguments are not allowed for this type [E0109]
where
C: Collection<i32>,
{
Expand All @@ -66,7 +61,6 @@ where
}

fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
//~^ ERROR type arguments are not allowed for this type [E0109]
where
C: Collection<i32>,
{
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/collections.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: type-generic associated types are not yet implemented
--> $DIR/collections.rs:13:5
|
LL | / type Sibling<U>: Collection<U> =
LL | | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
| |_________________________________________________________________________^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: type-generic associated types are not yet implemented
--> $DIR/collections.rs:25:5
|
LL | type Member<T>: Collection<T, Family = Self>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: aborting due to 2 previous errors

26 changes: 26 additions & 0 deletions src/test/ui/generic-associated-types/construct_with_other_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

// FIXME(#30472) normalize enough to handle this.

use std::ops::Deref;

trait Foo {
type Bar<'a, 'b>;
}

trait Baz {
type Quux<'a>: Foo where Self: 'a;

// This weird type tests that we can use universal function call syntax to access the Item on
type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>> where Self: 'a;
}

impl<T> Baz for T where T: Foo {
//~^ ERROR type mismatch resolving
type Quux<'a> where T: 'a = T;

type Baa<'a> where T: 'a = &'a <T as Foo>::Bar<'a, 'static>;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0271]: type mismatch resolving `for<'a> <<T as Baz>::Baa<'a> as std::ops::Deref>::Target == <<T as Baz>::Quux<'a> as Foo>::Bar<'a, 'static>`
--> $DIR/construct_with_other_type.rs:19:9
|
LL | impl<T> Baz for T where T: Foo {
| ^^^ expected type parameter `T`, found associated type
|
= note: expected associated type `<T as Foo>::Bar<'_, 'static>`
found associated type `<<T as Baz>::Quux<'_> as Foo>::Bar<'_, 'static>`
= note: you might be missing a type parameter or trait bound

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete

trait Foo {
type Bar<,>;
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/generic-associated-types/empty_generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected one of `>`, `const`, identifier, or lifetime, found `,`
--> $DIR/empty_generics.rs:5:14
|
LL | type Bar<,>;
| ^ expected one of `>`, `const`, identifier, or lifetime

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// rust-lang/rust#60654: Do not ICE on an attempt to use GATs that is
// missing the feature gate.

struct Foo;

trait MyTrait {
type Item<T>;
//~^ ERROR generic associated types are unstable [E0658]
//~| ERROR type-generic associated types are not yet implemented
}

impl MyTrait for Foo {
type Item<T> = T;
//~^ ERROR generic associated types are unstable [E0658]
}

fn main() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0658]: generic associated types are unstable
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:7:5
|
LL | type Item<T>;
| ^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0658]: generic associated types are unstable
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:13:5
|
LL | type Item<T> = T;
| ^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error: type-generic associated types are not yet implemented
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:7:5
|
LL | type Item<T>;
| ^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
struct Foo;

impl Iterator for Foo {
type Item<'b> = &'b Foo; //~ ERROR generic associated types are unstable [E0658]
type Item<'b> = &'b Foo;
//~^ ERROR generic associated types are unstable [E0658]
//~| ERROR lifetime parameters or bounds on type `Item` do not match the trait declaration

fn next(&mut self) -> Option<Self::Item> {
None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0658]: generic associated types are unstable
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:5
|
LL | type Item<'b> = &'b Foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:14
|
LL | type Item<'b> = &'b Foo;
| ^^^^ lifetimes do not match type in trait

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0195, E0658.
For more information about an error, try `rustc --explain E0195`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(generic_associated_types)] //~ WARN `generic_associated_types` is incomplete
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

// Checking the interaction with this other feature
#![feature(associated_type_defaults)]
Expand All @@ -8,8 +9,11 @@ use std::fmt::{Display, Debug};
trait Foo {
type Assoc where Self: Sized;
type Assoc2<T> where T: Display;
//~^ ERROR type-generic associated types are not yet implemented
type Assoc3<T>;
type WithDefault<T> where T: Debug = dyn Iterator<Item=T>;
//~^ ERROR type-generic associated types are not yet implemented
type WithDefault<'a, T: Debug + 'a> = dyn Iterator<Item=T>;
//~^ ERROR type-generic associated types are not yet implemented
type NoGenerics;
}

Expand All @@ -19,7 +23,7 @@ impl Foo for Bar {
type Assoc = usize;
type Assoc2<T> = Vec<T>;
type Assoc3<T> where T: Iterator = Vec<T>;
type WithDefault<'a, T> = &'a dyn Iterator<T>;
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item=T>;
type NoGenerics = ::std::cell::Cell<i32>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: type-generic associated types are not yet implemented
--> $DIR/generic-associated-types-where.rs:11:5
|
LL | type Assoc2<T> where T: Display;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: type-generic associated types are not yet implemented
--> $DIR/generic-associated-types-where.rs:13:5
|
LL | type Assoc3<T>;
| ^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: type-generic associated types are not yet implemented
--> $DIR/generic-associated-types-where.rs:15:5
|
LL | type WithDefault<'a, T: Debug + 'a> = dyn Iterator<Item=T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

use std::ops::Deref;

trait Iterable {
type Item<'a>;
type Iter<'a>: Iterator<Item = Self::Item<'a>>
+ Deref<Target = Self::Item<'b>>;
//~^ ERROR undeclared lifetime

fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
//~^ ERROR undeclared lifetime
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:9:37
|
LL | + Deref<Target = Self::Item<'b>>;
| ^^ undeclared lifetime

error[E0261]: use of undeclared lifetime name `'undeclared`
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:12:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
| ^^^^^^^^^^^ undeclared lifetime

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.
Loading

0 comments on commit c268798

Please sign in to comment.