forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#49423 - gavento:gavento-dev, r=nikomatsakis
Extend tests for RFC1598 (GAT) More GAT tests, namely some usage for `Iterable` and `StreamingIterator`, shadowing (lifetimes and type params), `Collection<T>` and `CollectionFamily` from [the series](http://smallcultfollowing.com/babysteps/blog/2016/11/03/associated-type-constructors-part-2-family-traits/) with default associated types. Tracking issue: rust-lang#44265 r? @nikomatsakis Wrong GAT argument numbers / kinds and default values are next.
- Loading branch information
Showing
12 changed files
with
401 additions
and
16 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/test/ui/rfc1598-generic-associated-types/collections.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2012 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(generic_associated_types)] | ||
#![feature(associated_type_defaults)] | ||
|
||
//FIXME(#44265): "lifetime parameters are not allowed on 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/ | ||
|
||
trait Collection<T> { | ||
type Iter<'iter>: Iterator<Item=&'iter T>; | ||
type Family: CollectionFamily; | ||
// Test associated type defaults with parameters | ||
type Sibling<U>: Collection<U> = | ||
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>; | ||
//~^ ERROR type parameters are not allowed on this type [E0109] | ||
|
||
fn empty() -> Self; | ||
|
||
fn add(&mut self, value: T); | ||
|
||
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; | ||
//~^ ERROR lifetime parameters are not allowed on this type [E0110] | ||
} | ||
|
||
trait CollectionFamily { | ||
type Member<T>: Collection<T, Family = Self>; | ||
} | ||
|
||
struct VecFamily; | ||
|
||
impl CollectionFamily for VecFamily { | ||
type Member<T> = Vec<T>; | ||
} | ||
|
||
impl<T> Collection<T> for Vec<T> { | ||
type Iter<'iter> = std::slice::Iter<'iter, T>; | ||
type Family = VecFamily; | ||
|
||
fn empty() -> Self { | ||
Vec::new() | ||
} | ||
|
||
fn add(&mut self, value: T) { | ||
self.push(value) | ||
} | ||
|
||
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> { | ||
//~^ ERROR lifetime parameters are not allowed on this type [E0110] | ||
self.iter() | ||
} | ||
} | ||
|
||
fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32> | ||
//~^ ERROR type parameters are not allowed on this type [E0109] | ||
where | ||
C: Collection<i32>, | ||
{ | ||
let mut res = C::Family::Member::<f32>::empty(); | ||
for &v in ints.iterate() { | ||
res.add(v as f32); | ||
} | ||
res | ||
} | ||
|
||
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32> | ||
//~^ ERROR type parameters are not allowed on this type [E0109] | ||
where | ||
C: Collection<i32>, | ||
{ | ||
let mut res = C::Family::Member::<f32>::empty(); | ||
for &v in ints.iterate() { | ||
res.add(v as f32); | ||
} | ||
res | ||
} | ||
|
||
fn use_floatify() { | ||
let a = vec![1i32, 2, 3]; | ||
let b = floatify(a); | ||
println!("{}", b.iterate().next()); | ||
let c = floatify_sibling(a); | ||
println!("{}", c.iterate().next()); | ||
} | ||
|
||
fn main() {} |
34 changes: 34 additions & 0 deletions
34
src/test/ui/rfc1598-generic-associated-types/collections.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
error[E0109]: type parameters are not allowed on this type | ||
--> $DIR/collections.rs:65:90 | ||
| | ||
LL | fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32> | ||
| ^^^ type parameter not allowed | ||
|
||
error[E0109]: type parameters are not allowed on this type | ||
--> $DIR/collections.rs:77:69 | ||
| | ||
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32> | ||
| ^^^ type parameter not allowed | ||
|
||
error[E0109]: type parameters are not allowed on this type | ||
--> $DIR/collections.rs:26:71 | ||
| | ||
LL | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>; | ||
| ^ type parameter not allowed | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/collections.rs:33:50 | ||
| | ||
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; | ||
| ^^^^^ lifetime parameter not allowed on this type | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/collections.rs:59:50 | ||
| | ||
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> { | ||
| ^^^^^ lifetime parameter not allowed on this type | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors occurred: E0109, E0110. | ||
For more information about an error, try `rustc --explain E0109`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 16 additions & 4 deletions
20
src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/construct_with_other_type.rs:25:37 | ||
--> $DIR/construct_with_other_type.rs:26:46 | ||
| | ||
LL | type Quux<'a> = <T as Foo>::Bar<'a, 'static>; | ||
| ^^ lifetime parameter not allowed on this type | ||
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>; | ||
| ^^ lifetime parameter not allowed on this type | ||
|
||
error: aborting due to previous error | ||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/construct_with_other_type.rs:26:63 | ||
| | ||
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>; | ||
| ^^ lifetime parameter not allowed on this type | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/construct_with_other_type.rs:34:40 | ||
| | ||
LL | type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>; | ||
| ^^ lifetime parameter not allowed on this type | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0110`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2012 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(generic_associated_types)] | ||
#![feature(associated_type_defaults)] | ||
|
||
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a | ||
//follow-up PR | ||
|
||
//FIXME(#44265): Update expected errors once E110 is resolved, now does not get past `trait Foo` | ||
|
||
trait Foo { | ||
type A<'a>; | ||
type B<'a, 'b>; | ||
type C; | ||
type D<T>; | ||
type E<'a, T>; | ||
// Test parameters in default values | ||
type FOk<T> = Self::E<'static, T>; | ||
//~^ ERROR type parameters are not allowed on this type [E0109] | ||
//~| ERROR lifetime parameters are not allowed on this type [E0110] | ||
type FErr1 = Self::E<'static, 'static>; // Error | ||
//~^ ERROR lifetime parameters are not allowed on this type [E0110] | ||
type FErr2<T> = Self::E<'static, T, u32>; // Error | ||
//~^ ERROR type parameters are not allowed on this type [E0109] | ||
//~| ERROR lifetime parameters are not allowed on this type [E0110] | ||
} | ||
|
||
struct Fooy; | ||
|
||
impl Foo for Fooy { | ||
type A = u32; // Error: parameter expected | ||
type B<'a, T> = Vec<T>; // Error: lifetime param expected | ||
type C<'a> = u32; // Error: no param expected | ||
type D<'a> = u32; // Error: type param expected | ||
type E<T, U> = u32; // Error: lifetime expected as the first param | ||
} | ||
|
||
struct Fooer; | ||
|
||
impl Foo for Fooer { | ||
type A<T> = u32; // Error: lifetime parameter expected | ||
type B<'a> = u32; // Error: another lifetime param expected | ||
type C<T> = T; // Error: no param expected | ||
type D<'b, T> = u32; // Error: unexpected lifetime param | ||
type E<'a, 'b> = u32; // Error: type expected as the second param | ||
} | ||
|
||
fn main() {} |
34 changes: 34 additions & 0 deletions
34
src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
error[E0109]: type parameters are not allowed on this type | ||
--> $DIR/parameter_number_and_kind.rs:26:36 | ||
| | ||
LL | type FOk<T> = Self::E<'static, T>; | ||
| ^ type parameter not allowed | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/parameter_number_and_kind.rs:26:27 | ||
| | ||
LL | type FOk<T> = Self::E<'static, T>; | ||
| ^^^^^^^ lifetime parameter not allowed on this type | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/parameter_number_and_kind.rs:29:26 | ||
| | ||
LL | type FErr1 = Self::E<'static, 'static>; // Error | ||
| ^^^^^^^ lifetime parameter not allowed on this type | ||
|
||
error[E0109]: type parameters are not allowed on this type | ||
--> $DIR/parameter_number_and_kind.rs:31:38 | ||
| | ||
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error | ||
| ^ type parameter not allowed | ||
|
||
error[E0110]: lifetime parameters are not allowed on this type | ||
--> $DIR/parameter_number_and_kind.rs:31:29 | ||
| | ||
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error | ||
| ^^^^^^^ lifetime parameter not allowed on this type | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors occurred: E0109, E0110. | ||
For more information about an error, try `rustc --explain E0109`. |
Oops, something went wrong.