Skip to content

Commit c268798

Browse files
committed
Update tests for GATs
* 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
1 parent 0a5c91c commit c268798

File tree

61 files changed

+760
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+760
-546
lines changed

src/test/ui/feature-gates/feature-gate-generic_associated_types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use std::ops::Deref;
33
trait PointerFamily<U> {
44
type Pointer<T>: Deref<Target = T>;
55
//~^ ERROR generic associated types are unstable
6+
//~| ERROR type-generic associated types are not yet implemented
67
type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
78
//~^ ERROR generic associated types are unstable
89
//~| ERROR where clauses on associated types are unstable
10+
//~| ERROR type-generic associated types are not yet implemented
911
}
1012

1113
struct Foo;

src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr

+23-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | type Pointer<T>: Deref<Target = T>;
88
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
99

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

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

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

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

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

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

64-
error: aborting due to 7 previous errors
64+
error: type-generic associated types are not yet implemented
65+
--> $DIR/feature-gate-generic_associated_types.rs:4:5
66+
|
67+
LL | type Pointer<T>: Deref<Target = T>;
68+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
|
70+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
71+
72+
error: type-generic associated types are not yet implemented
73+
--> $DIR/feature-gate-generic_associated_types.rs:7:5
74+
|
75+
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
|
78+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
79+
80+
error: aborting due to 9 previous errors
6581

6682
For more information about this error, try `rustc --explain E0658`.

src/test/ui/rfc1598-generic-associated-types/collections.rs renamed to src/test/ui/generic-associated-types/collections.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
#![allow(incomplete_features)]
12
#![feature(generic_associated_types)]
2-
//~^ WARNING the feature `generic_associated_types` is incomplete
33
#![feature(associated_type_defaults)]
44

5-
// FIXME(#44265): "lifetime arguments are not allowed for this type" errors will be addressed in a
6-
// follow-up PR.
7-
85
// A Collection trait and collection families. Based on
96
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/
107
// associated-type-constructors-part-2-family-traits/
@@ -15,18 +12,18 @@ trait Collection<T> {
1512
// Test associated type defaults with parameters
1613
type Sibling<U>: Collection<U> =
1714
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
18-
//~^ ERROR type arguments are not allowed for this type [E0109]
15+
//~^^ ERROR type-generic associated types are not yet implemented
1916

2017
fn empty() -> Self;
2118

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

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

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

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

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

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

6863
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
69-
//~^ ERROR type arguments are not allowed for this type [E0109]
7064
where
7165
C: Collection<i32>,
7266
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: type-generic associated types are not yet implemented
2+
--> $DIR/collections.rs:13:5
3+
|
4+
LL | / type Sibling<U>: Collection<U> =
5+
LL | | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
6+
| |_________________________________________________________________________^
7+
|
8+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
9+
10+
error: type-generic associated types are not yet implemented
11+
--> $DIR/collections.rs:25:5
12+
|
13+
LL | type Member<T>: Collection<T, Family = Self>;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
17+
18+
error: aborting due to 2 previous errors
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_associated_types)]
3+
4+
// FIXME(#30472) normalize enough to handle this.
5+
6+
use std::ops::Deref;
7+
8+
trait Foo {
9+
type Bar<'a, 'b>;
10+
}
11+
12+
trait Baz {
13+
type Quux<'a>: Foo where Self: 'a;
14+
15+
// This weird type tests that we can use universal function call syntax to access the Item on
16+
type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>> where Self: 'a;
17+
}
18+
19+
impl<T> Baz for T where T: Foo {
20+
//~^ ERROR type mismatch resolving
21+
type Quux<'a> where T: 'a = T;
22+
23+
type Baa<'a> where T: 'a = &'a <T as Foo>::Bar<'a, 'static>;
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
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>`
2+
--> $DIR/construct_with_other_type.rs:19:9
3+
|
4+
LL | impl<T> Baz for T where T: Foo {
5+
| ^^^ expected type parameter `T`, found associated type
6+
|
7+
= note: expected associated type `<T as Foo>::Bar<'_, 'static>`
8+
found associated type `<<T as Baz>::Quux<'_> as Foo>::Bar<'_, 'static>`
9+
= note: you might be missing a type parameter or trait bound
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0271`.

src/test/ui/rfc1598-generic-associated-types/empty_generics.rs renamed to src/test/ui/generic-associated-types/empty_generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
#![allow(incomplete_features)]
12
#![feature(generic_associated_types)]
2-
//~^ WARNING the feature `generic_associated_types` is incomplete
33

44
trait Foo {
55
type Bar<,>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `>`, `const`, identifier, or lifetime, found `,`
2+
--> $DIR/empty_generics.rs:5:14
3+
|
4+
LL | type Bar<,>;
5+
| ^ expected one of `>`, `const`, identifier, or lifetime
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// rust-lang/rust#60654: Do not ICE on an attempt to use GATs that is
2+
// missing the feature gate.
3+
4+
struct Foo;
5+
6+
trait MyTrait {
7+
type Item<T>;
8+
//~^ ERROR generic associated types are unstable [E0658]
9+
//~| ERROR type-generic associated types are not yet implemented
10+
}
11+
12+
impl MyTrait for Foo {
13+
type Item<T> = T;
14+
//~^ ERROR generic associated types are unstable [E0658]
15+
}
16+
17+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0658]: generic associated types are unstable
2+
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:7:5
3+
|
4+
LL | type Item<T>;
5+
| ^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
8+
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
9+
10+
error[E0658]: generic associated types are unstable
11+
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:13:5
12+
|
13+
LL | type Item<T> = T;
14+
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
17+
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
18+
19+
error: type-generic associated types are not yet implemented
20+
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:7:5
21+
|
22+
LL | type Item<T>;
23+
| ^^^^^^^^^^^^^
24+
|
25+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
26+
27+
error: aborting due to 3 previous errors
28+
29+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/rfc1598-generic-associated-types/gat-dont-ice-on-absent-feature.rs renamed to src/test/ui/generic-associated-types/gat-dont-ice-on-absent-feature.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
struct Foo;
55

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

911
fn next(&mut self) -> Option<Self::Item> {
1012
None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0658]: generic associated types are unstable
2+
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:5
3+
|
4+
LL | type Item<'b> = &'b Foo;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
8+
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
9+
10+
error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
11+
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:14
12+
|
13+
LL | type Item<'b> = &'b Foo;
14+
| ^^^^ lifetimes do not match type in trait
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0195, E0658.
19+
For more information about an error, try `rustc --explain E0195`.

src/test/ui/rfc1598-generic-associated-types/generic-associated-types-where.rs renamed to src/test/ui/generic-associated-types/generic-associated-types-where.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![feature(generic_associated_types)] //~ WARN `generic_associated_types` is incomplete
1+
#![allow(incomplete_features)]
2+
#![feature(generic_associated_types)]
23

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

@@ -19,7 +23,7 @@ impl Foo for Bar {
1923
type Assoc = usize;
2024
type Assoc2<T> = Vec<T>;
2125
type Assoc3<T> where T: Iterator = Vec<T>;
22-
type WithDefault<'a, T> = &'a dyn Iterator<T>;
26+
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item=T>;
2327
type NoGenerics = ::std::cell::Cell<i32>;
2428
}
2529

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: type-generic associated types are not yet implemented
2+
--> $DIR/generic-associated-types-where.rs:11:5
3+
|
4+
LL | type Assoc2<T> where T: Display;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
8+
9+
error: type-generic associated types are not yet implemented
10+
--> $DIR/generic-associated-types-where.rs:13:5
11+
|
12+
LL | type Assoc3<T>;
13+
| ^^^^^^^^^^^^^^^
14+
|
15+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
16+
17+
error: type-generic associated types are not yet implemented
18+
--> $DIR/generic-associated-types-where.rs:15:5
19+
|
20+
LL | type WithDefault<'a, T: Debug + 'a> = dyn Iterator<Item=T>;
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
24+
25+
error: aborting due to 3 previous errors
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_associated_types)]
3+
4+
use std::ops::Deref;
5+
6+
trait Iterable {
7+
type Item<'a>;
8+
type Iter<'a>: Iterator<Item = Self::Item<'a>>
9+
+ Deref<Target = Self::Item<'b>>;
10+
//~^ ERROR undeclared lifetime
11+
12+
fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
13+
//~^ ERROR undeclared lifetime
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0261]: use of undeclared lifetime name `'b`
2+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:9:37
3+
|
4+
LL | + Deref<Target = Self::Item<'b>>;
5+
| ^^ undeclared lifetime
6+
7+
error[E0261]: use of undeclared lifetime name `'undeclared`
8+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:12:41
9+
|
10+
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
11+
| ^^^^^^^^^^^ undeclared lifetime
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)