From b0fcb5f4408d59a0dcea4427394a04e72ab5aeff Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 27 Mar 2018 19:45:44 +0200 Subject: [PATCH 1/7] Extend tests for RFC1598 (GAT) --- .../collections.rs | 85 +++++++++++++++++++ .../collections.stderr | 34 ++++++++ .../iterable.rs | 34 ++++++++ .../iterable.stderr | 26 +++++- .../shadowing.rs | 44 ++++++++++ .../shadowing.stdout | 0 .../streaming_iterator.rs | 44 ++++++++++ .../streaming_iterator.stderr | 14 ++- 8 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/rfc1598-generic-associated-types/collections.rs create mode 100644 src/test/ui/rfc1598-generic-associated-types/collections.stderr create mode 100644 src/test/ui/rfc1598-generic-associated-types/shadowing.rs create mode 100644 src/test/ui/rfc1598-generic-associated-types/shadowing.stdout diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.rs b/src/test/ui/rfc1598-generic-associated-types/collections.rs new file mode 100644 index 0000000000000..4ea2c82883133 --- /dev/null +++ b/src/test/ui/rfc1598-generic-associated-types/collections.rs @@ -0,0 +1,85 @@ +// 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 or the MIT license +// , 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 { + 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] + type Iter<'iter>: Iterator; + type Family: CollectionFamily; + // Test associated type defaults with parameters + type Sibling: Collection = <>::Family as CollectionFamily>::Member; + //~^ ERROR type parameters are not allowed on this type [E0109] +} + +trait CollectionFamily { + type Member: Collection; +} + +struct VecFamily; + +impl CollectionFamily for VecFamily { + type Member = Vec; +} + +impl Collection for Vec { + 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() + } + type Iter<'iter> = std::slice::Iter<'iter, T>; + type Family = VecFamily; +} + +fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member + //~^ ERROR type parameters are not allowed on this type [E0109] + where C: Collection { + let mut res = C::Family::Member::::empty(); + for &v in ints.iterate() { + res.add(v as f32); + } + res +} + +fn floatify_sibling(ints: &C) -> >::Sibling + //~^ ERROR type parameters are not allowed on this type [E0109] + where C: Collection { + let mut res = C::Family::Member::::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() {} \ No newline at end of file diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.stderr b/src/test/ui/rfc1598-generic-associated-types/collections.stderr new file mode 100644 index 0000000000000..6aa7aa993fd25 --- /dev/null +++ b/src/test/ui/rfc1598-generic-associated-types/collections.stderr @@ -0,0 +1,34 @@ +error[E0109]: type parameters are not allowed on this type + --> $DIR/collections.rs:57:90 + | +LL | fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member + | ^^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/collections.rs:67:69 + | +LL | fn floatify_sibling(ints: &C) -> >::Sibling + | ^^^ type parameter not allowed + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/collections.rs:23:50 + | +LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; + | ^^^^^ lifetime parameter not allowed on this type + +error[E0109]: type parameters are not allowed on this type + --> $DIR/collections.rs:28:100 + | +LL | type Sibling: Collection = <>::Family as CollectionFamily>::Member; + | ^ type parameter not allowed + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/collections.rs:49: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`. diff --git a/src/test/ui/rfc1598-generic-associated-types/iterable.rs b/src/test/ui/rfc1598-generic-associated-types/iterable.rs index 1287ddaf7f7fe..b79aa6179adfd 100644 --- a/src/test/ui/rfc1598-generic-associated-types/iterable.rs +++ b/src/test/ui/rfc1598-generic-associated-types/iterable.rs @@ -29,4 +29,38 @@ trait Iterable { //~^ ERROR lifetime parameters are not allowed on this type [E0110] } +// Impl for struct type +impl Iterable for Vec { + type Item<'a> = &'a T; + type Iter<'a> = std::slice::Iter<'a, T>; + type Iter2<'a> = &'a T; + // gavento: ^^^ Not 100% sure about the intention here + fn iter<'a>(&'a self) -> Self::Iter<'a> { + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + self.iter() + } +} + +// Impl for a primitive type +impl Iterable for [T] { + type Item<'a> = &'a T; + type Iter<'a> = std::slice::Iter<'a, T>; + type Iter2<'a> = &'a T; + // gavento: ^^^ Not 100% sure about the intention here + fn iter<'a>(&'a self) -> Self::Iter<'a> { + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + self.iter() + } +} + +fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> { + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + it.iter() +} + +fn get_first<'a, I: Iterable>(it: &'a I) -> Option> { + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + it.iter().next() +} + fn main() {} diff --git a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr index d33eebb42d607..34266dd3c512f 100644 --- a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr @@ -10,12 +10,36 @@ error[E0110]: lifetime parameters are not allowed on this type LL | type Iter2<'a>: Deref as Iterator>::Item>; | ^^ lifetime parameter not allowed on this type +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/iterable.rs:56:53 + | +LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> { + | ^^ lifetime parameter not allowed on this type + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/iterable.rs:61:60 + | +LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option> { + | ^^ lifetime parameter not allowed on this type + error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:28:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a>; | ^^ lifetime parameter not allowed on this type -error: aborting due to 3 previous errors +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/iterable.rs:38:41 + | +LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { + | ^^ lifetime parameter not allowed on this type + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/iterable.rs:50:41 + | +LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { + | ^^ lifetime parameter not allowed on this type + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0110`. diff --git a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs new file mode 100644 index 0000000000000..6e77ce2b3dd0c --- /dev/null +++ b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs @@ -0,0 +1,44 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(generic_associated_types)] + +//FIXME(#44265): The lifetime shadowing and type parameter shadowing +// should cause an error. This will be addressed by a future PR. +// For now this compiles: +// must-compile-successfully + +trait Shadow<'a> { + type Bar<'a>; // Error: shadowed lifetime +} + +trait NoShadow<'a> { + type Bar<'b>; // OK +} + +impl<'a> NoShadow<'a> for &'a u32 +{ + type Bar<'a> = i32; // Error: shadowed lifetime +} + +trait ShadowT { + type Bar; // Error: shadowed type parameter +} + +trait NoShadowT { + type Bar; // OK +} + +impl NoShadowT for Option +{ + type Bar = i32; // Error: shadowed type parameter +} + +fn main() {} diff --git a/src/test/ui/rfc1598-generic-associated-types/shadowing.stdout b/src/test/ui/rfc1598-generic-associated-types/shadowing.stdout new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs index f9e270ee92e22..522ddb5dc135e 100644 --- a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs +++ b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs @@ -35,4 +35,48 @@ struct Foo { fn foo(iter: T) where T: StreamingIterator, for<'a> T::Item<'a>: Display { /* ... */ } //~^ ERROR lifetime parameters are not allowed on this type [E0110] +// Full example of enumerate iterator + +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] +struct StreamEnumerate { + iter: I, + count: usize, +} + +impl StreamingIterator for StreamEnumerate { + type Item<'a> = (usize, I::Item<'a>); + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + fn next<'a>(&'a self) -> Option> { + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + match self.iter.next() { + None => None, + Some(val) => { + let r = Some((self.count, val)); + self.count += 1; + r + } + } + } +} + +impl StreamEnumerate { + pub fn new(iter: I) -> Self { + StreamEnumerate { + count: 0, + iter: iter, + } + } +} + +fn test_stream_enumerate() { + let v = vec!["a", "b", "c"]; + let se = StreamEnumerate::new(v.iter()); + let a: &str = se.next().unwrap().1; + for (i, s) in se { + println!("{} {}", i, s); + } + println!("{}", a); +} + + fn main() {} diff --git a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr index 9ab80151a7ed3..607a4b8d57996 100644 --- a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr @@ -16,6 +16,18 @@ error[E0110]: lifetime parameters are not allowed on this type LL | fn next<'a>(&'a self) -> Option>; | ^^ lifetime parameter not allowed on this type -error: aborting due to 3 previous errors +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/streaming_iterator.rs:47:37 + | +LL | type Item<'a> = (usize, I::Item<'a>); + | ^^ lifetime parameter not allowed on this type + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/streaming_iterator.rs:49:48 + | +LL | fn next<'a>(&'a self) -> Option> { + | ^^ lifetime parameter not allowed on this type + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0110`. From e09d9ecbcdbd4563656162be6a69e47a11f67c52 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 27 Mar 2018 22:26:46 +0200 Subject: [PATCH 2/7] Tidy up the code --- .../ui/rfc1598-generic-associated-types/collections.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.rs b/src/test/ui/rfc1598-generic-associated-types/collections.rs index 4ea2c82883133..19f5756609678 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.rs +++ b/src/test/ui/rfc1598-generic-associated-types/collections.rs @@ -14,8 +14,9 @@ //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/ +// 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 { fn empty() -> Self; @@ -25,7 +26,8 @@ trait Collection { type Iter<'iter>: Iterator; type Family: CollectionFamily; // Test associated type defaults with parameters - type Sibling: Collection = <>::Family as CollectionFamily>::Member; + type Sibling: Collection = <>::Family as CollectionFamily>:: + Member; //~^ ERROR type parameters are not allowed on this type [E0109] } @@ -82,4 +84,4 @@ fn use_floatify() { println!("{}", c.iterate().next()); } -fn main() {} \ No newline at end of file +fn main() {} From a66a0110de5258507c30e26d7e7d055ffc080cfc Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 28 Mar 2018 09:15:36 +0200 Subject: [PATCH 3/7] Fix test stderr after tidying the source --- .../collections.stderr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.stderr b/src/test/ui/rfc1598-generic-associated-types/collections.stderr index 6aa7aa993fd25..eda8fb5f93fba 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/collections.stderr @@ -1,29 +1,29 @@ error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:57:90 + --> $DIR/collections.rs:59:90 | LL | fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member | ^^^ type parameter not allowed error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:67:69 + --> $DIR/collections.rs:69:69 | LL | fn floatify_sibling(ints: &C) -> >::Sibling | ^^^ type parameter not allowed error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/collections.rs:23:50 + --> $DIR/collections.rs:24:50 | LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; | ^^^^^ lifetime parameter not allowed on this type error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:28:100 + --> $DIR/collections.rs:30:16 | -LL | type Sibling: Collection = <>::Family as CollectionFamily>::Member; - | ^ type parameter not allowed +LL | Member; + | ^ type parameter not allowed error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/collections.rs:49:50 + --> $DIR/collections.rs:51:50 | LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> { | ^^^^^ lifetime parameter not allowed on this type From 0617b925e83079ebebc53bc9a29a9e4105a39ec3 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 28 Mar 2018 09:22:44 +0200 Subject: [PATCH 4/7] Add tests for GAT parameter number and kindness --- .../parameter_number_and_kind.rs | 56 +++++++++++++++++++ .../parameter_number_and_kind.stderr | 34 +++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs create mode 100644 src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr diff --git a/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs new file mode 100644 index 0000000000000..51527d4117c2c --- /dev/null +++ b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs @@ -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 or the MIT license +// , 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; + type E<'a, T>; + // Test parameters in default values + type FOk = 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 = 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; // Error: lifetime param expected + type C<'a> = u32; // Error: no param expected + type D<'a> = u32; // Error: type param expected + type E = u32; // Error: lifetime expected as the first param +} + +struct Fooer; + +impl Foo for Fooer { + type A = u32; // Error: lifetime parameter expected + type B<'a> = u32; // Error: another lifetime param expected + type C = 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() {} diff --git a/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr new file mode 100644 index 0000000000000..df83fdaad5bfa --- /dev/null +++ b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr @@ -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 = 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 = 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 = 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 = 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`. From 571337b3dd89a17930a686a66d815f69889e9b66 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 11 Apr 2018 23:41:20 +0200 Subject: [PATCH 5/7] Update tests with Nikos comments --- .../collections.rs | 26 +++++++++++++------ .../collections.stderr | 20 +++++++------- .../construct_with_other_type.rs | 13 ++++++++-- .../construct_with_other_type.stderr | 20 +++++++++++--- .../iterable.rs | 11 ++------ .../iterable.stderr | 18 +++++-------- .../shadowing.rs | 4 +-- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.rs b/src/test/ui/rfc1598-generic-associated-types/collections.rs index 19f5756609678..24d756a83314e 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.rs +++ b/src/test/ui/rfc1598-generic-associated-types/collections.rs @@ -19,16 +19,19 @@ // associated-type-constructors-part-2-family-traits/ trait Collection { - 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] type Iter<'iter>: Iterator; type Family: CollectionFamily; // Test associated type defaults with parameters type Sibling: Collection = <>::Family as CollectionFamily>:: Member; //~^ 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 { @@ -42,23 +45,28 @@ impl CollectionFamily for VecFamily { } impl Collection for Vec { + 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() } - type Iter<'iter> = std::slice::Iter<'iter, T>; - type Family = VecFamily; } fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member //~^ ERROR type parameters are not allowed on this type [E0109] - where C: Collection { +where + C: Collection, +{ let mut res = C::Family::Member::::empty(); for &v in ints.iterate() { res.add(v as f32); @@ -68,7 +76,9 @@ fn floatify(ints: &C) -> <>::Family as CollectionFamily> fn floatify_sibling(ints: &C) -> >::Sibling //~^ ERROR type parameters are not allowed on this type [E0109] - where C: Collection { +where + C: Collection, +{ let mut res = C::Family::Member::::empty(); for &v in ints.iterate() { res.add(v as f32); diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.stderr b/src/test/ui/rfc1598-generic-associated-types/collections.stderr index eda8fb5f93fba..0a51bf56397df 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/collections.stderr @@ -1,29 +1,29 @@ error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:59:90 + --> $DIR/collections.rs:65:90 | LL | fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member | ^^^ type parameter not allowed error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:69:69 + --> $DIR/collections.rs:77:69 | LL | fn floatify_sibling(ints: &C) -> >::Sibling | ^^^ type parameter not allowed -error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/collections.rs:24:50 - | -LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; - | ^^^^^ lifetime parameter not allowed on this type - error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:30:16 + --> $DIR/collections.rs:26:16 | LL | Member; | ^ type parameter not allowed error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/collections.rs:51:50 + --> $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 diff --git a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs index 0d9b487876e21..0429410031526 100644 --- a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs +++ b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs @@ -10,6 +10,8 @@ #![feature(generic_associated_types)] +use std::ops::Deref; + //FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a //follow-up PR @@ -18,11 +20,18 @@ trait Foo { } trait Baz { - type Quux<'a>; + type Quux<'a>: Foo; + + // This weird type tests that we can use universal function call syntax to access the Item on + type Baa<'a>: Deref as Foo>::Bar<'a, 'static>>; + //~^ ERROR lifetime parameters are not allowed on this type [E0110] + //~| ERROR lifetime parameters are not allowed on this type [E0110] } impl Baz for T where T: Foo { - type Quux<'a> = ::Bar<'a, 'static>; + type Quux<'a> = T; + + type Baa<'a> = &'a ::Bar<'a, 'static>; //~^ ERROR lifetime parameters are not allowed on this type [E0110] } diff --git a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr index 054530e24bd18..764a0db2478a8 100644 --- a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr @@ -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> = ::Bar<'a, 'static>; - | ^^ lifetime parameter not allowed on this type +LL | type Baa<'a>: Deref 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 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 ::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`. diff --git a/src/test/ui/rfc1598-generic-associated-types/iterable.rs b/src/test/ui/rfc1598-generic-associated-types/iterable.rs index b79aa6179adfd..38967dbbe4530 100644 --- a/src/test/ui/rfc1598-generic-associated-types/iterable.rs +++ b/src/test/ui/rfc1598-generic-associated-types/iterable.rs @@ -20,11 +20,6 @@ trait Iterable { type Iter<'a>: Iterator>; //~^ ERROR lifetime parameters are not allowed on this type [E0110] - // This weird type tests that we can use universal function call syntax to access the Item on - // Self::Iter which we have declared to be an Iterator - type Iter2<'a>: Deref as Iterator>::Item>; - //~^ ERROR lifetime parameters are not allowed on this type [E0110] - fn iter<'a>(&'a self) -> Self::Iter<'a>; //~^ ERROR lifetime parameters are not allowed on this type [E0110] } @@ -33,8 +28,7 @@ trait Iterable { impl Iterable for Vec { type Item<'a> = &'a T; type Iter<'a> = std::slice::Iter<'a, T>; - type Iter2<'a> = &'a T; - // gavento: ^^^ Not 100% sure about the intention here + fn iter<'a>(&'a self) -> Self::Iter<'a> { //~^ ERROR lifetime parameters are not allowed on this type [E0110] self.iter() @@ -45,8 +39,7 @@ impl Iterable for Vec { impl Iterable for [T] { type Item<'a> = &'a T; type Iter<'a> = std::slice::Iter<'a, T>; - type Iter2<'a> = &'a T; - // gavento: ^^^ Not 100% sure about the intention here + fn iter<'a>(&'a self) -> Self::Iter<'a> { //~^ ERROR lifetime parameters are not allowed on this type [E0110] self.iter() diff --git a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr index 34266dd3c512f..0e251300e451f 100644 --- a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr @@ -5,41 +5,35 @@ LL | type Iter<'a>: Iterator>; | ^^ lifetime parameter not allowed on this type error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:25:48 - | -LL | type Iter2<'a>: Deref as Iterator>::Item>; - | ^^ lifetime parameter not allowed on this type - -error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:56:53 + --> $DIR/iterable.rs:49:53 | LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> { | ^^ lifetime parameter not allowed on this type error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:61:60 + --> $DIR/iterable.rs:54:60 | LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option> { | ^^ lifetime parameter not allowed on this type error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:28:41 + --> $DIR/iterable.rs:23:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a>; | ^^ lifetime parameter not allowed on this type error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:38:41 + --> $DIR/iterable.rs:32:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { | ^^ lifetime parameter not allowed on this type error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/iterable.rs:50:41 + --> $DIR/iterable.rs:43:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { | ^^ lifetime parameter not allowed on this type -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0110`. diff --git a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs index 6e77ce2b3dd0c..6ed7380f3f87a 100644 --- a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs +++ b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs @@ -11,8 +11,8 @@ #![feature(generic_associated_types)] //FIXME(#44265): The lifetime shadowing and type parameter shadowing -// should cause an error. This will be addressed by a future PR. -// For now this compiles: +// should cause an error. Now it compiles (errorneously) and this will be addressed +// by a future PR. Then remove the following: // must-compile-successfully trait Shadow<'a> { From a43171a24257f015113ecf494286d39f47db88ac Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Thu, 3 May 2018 00:34:34 +0200 Subject: [PATCH 6/7] Update tests to use compile-pass --- src/test/ui/rfc1598-generic-associated-types/shadowing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs index 6ed7380f3f87a..f0e711e71e341 100644 --- a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs +++ b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs @@ -13,7 +13,7 @@ //FIXME(#44265): The lifetime shadowing and type parameter shadowing // should cause an error. Now it compiles (errorneously) and this will be addressed // by a future PR. Then remove the following: -// must-compile-successfully +// compile-pass trait Shadow<'a> { type Bar<'a>; // Error: shadowed lifetime From 9073c897459a8582fa61d87f41654e18f9869b46 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Thu, 3 May 2018 00:58:35 +0200 Subject: [PATCH 7/7] Minor fromatting for RFC 1598 tests --- .../ui/rfc1598-generic-associated-types/collections.rs | 8 ++++---- .../rfc1598-generic-associated-types/collections.stderr | 6 +++--- src/test/ui/rfc1598-generic-associated-types/shadowing.rs | 6 ++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.rs b/src/test/ui/rfc1598-generic-associated-types/collections.rs index 24d756a83314e..e71166ed65bba 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.rs +++ b/src/test/ui/rfc1598-generic-associated-types/collections.rs @@ -22,8 +22,8 @@ trait Collection { type Iter<'iter>: Iterator; type Family: CollectionFamily; // Test associated type defaults with parameters - type Sibling: Collection = <>::Family as CollectionFamily>:: - Member; + type Sibling: Collection = + <>::Family as CollectionFamily>::Member; //~^ ERROR type parameters are not allowed on this type [E0109] fn empty() -> Self; @@ -63,7 +63,7 @@ impl Collection for Vec { } fn floatify(ints: &C) -> <>::Family as CollectionFamily>::Member - //~^ ERROR type parameters are not allowed on this type [E0109] +//~^ ERROR type parameters are not allowed on this type [E0109] where C: Collection, { @@ -75,7 +75,7 @@ where } fn floatify_sibling(ints: &C) -> >::Sibling - //~^ ERROR type parameters are not allowed on this type [E0109] +//~^ ERROR type parameters are not allowed on this type [E0109] where C: Collection, { diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.stderr b/src/test/ui/rfc1598-generic-associated-types/collections.stderr index 0a51bf56397df..ed96570583f4f 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/collections.stderr @@ -11,10 +11,10 @@ LL | fn floatify_sibling(ints: &C) -> >::Sibling | ^^^ type parameter not allowed error[E0109]: type parameters are not allowed on this type - --> $DIR/collections.rs:26:16 + --> $DIR/collections.rs:26:71 | -LL | Member; - | ^ type parameter not allowed +LL | <>::Family as CollectionFamily>::Member; + | ^ type parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/collections.rs:33:50 diff --git a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs index f0e711e71e341..6cdcaf2568394 100644 --- a/src/test/ui/rfc1598-generic-associated-types/shadowing.rs +++ b/src/test/ui/rfc1598-generic-associated-types/shadowing.rs @@ -23,8 +23,7 @@ trait NoShadow<'a> { type Bar<'b>; // OK } -impl<'a> NoShadow<'a> for &'a u32 -{ +impl<'a> NoShadow<'a> for &'a u32 { type Bar<'a> = i32; // Error: shadowed lifetime } @@ -36,8 +35,7 @@ trait NoShadowT { type Bar; // OK } -impl NoShadowT for Option -{ +impl NoShadowT for Option { type Bar = i32; // Error: shadowed type parameter }