Skip to content

Commit 571337b

Browse files
committed
Update tests with Nikos comments
1 parent 0617b92 commit 571337b

File tree

7 files changed

+65
-47
lines changed

7 files changed

+65
-47
lines changed

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

+18-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919
// associated-type-constructors-part-2-family-traits/
2020

2121
trait Collection<T> {
22-
fn empty() -> Self;
23-
fn add(&mut self, value: T);
24-
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
25-
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
2622
type Iter<'iter>: Iterator<Item=&'iter T>;
2723
type Family: CollectionFamily;
2824
// Test associated type defaults with parameters
2925
type Sibling<U>: Collection<U> = <<Self as Collection<T>>::Family as CollectionFamily>::
3026
Member<U>;
3127
//~^ ERROR type parameters are not allowed on this type [E0109]
28+
29+
fn empty() -> Self;
30+
31+
fn add(&mut self, value: T);
32+
33+
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
34+
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
3235
}
3336

3437
trait CollectionFamily {
@@ -42,23 +45,28 @@ impl CollectionFamily for VecFamily {
4245
}
4346

4447
impl<T> Collection<T> for Vec<T> {
48+
type Iter<'iter> = std::slice::Iter<'iter, T>;
49+
type Family = VecFamily;
50+
4551
fn empty() -> Self {
4652
Vec::new()
4753
}
54+
4855
fn add(&mut self, value: T) {
4956
self.push(value)
5057
}
58+
5159
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
5260
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
5361
self.iter()
5462
}
55-
type Iter<'iter> = std::slice::Iter<'iter, T>;
56-
type Family = VecFamily;
5763
}
5864

5965
fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
6066
//~^ ERROR type parameters are not allowed on this type [E0109]
61-
where C: Collection<i32> {
67+
where
68+
C: Collection<i32>,
69+
{
6270
let mut res = C::Family::Member::<f32>::empty();
6371
for &v in ints.iterate() {
6472
res.add(v as f32);
@@ -68,7 +76,9 @@ fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>
6876

6977
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
7078
//~^ ERROR type parameters are not allowed on this type [E0109]
71-
where C: Collection<i32> {
79+
where
80+
C: Collection<i32>,
81+
{
7282
let mut res = C::Family::Member::<f32>::empty();
7383
for &v in ints.iterate() {
7484
res.add(v as f32);

src/test/ui/rfc1598-generic-associated-types/collections.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0109]: type parameters are not allowed on this type
2-
--> $DIR/collections.rs:59:90
2+
--> $DIR/collections.rs:65:90
33
|
44
LL | fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
55
| ^^^ type parameter not allowed
66

77
error[E0109]: type parameters are not allowed on this type
8-
--> $DIR/collections.rs:69:69
8+
--> $DIR/collections.rs:77:69
99
|
1010
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
1111
| ^^^ type parameter not allowed
1212

13-
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/collections.rs:24:50
15-
|
16-
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
17-
| ^^^^^ lifetime parameter not allowed on this type
18-
1913
error[E0109]: type parameters are not allowed on this type
20-
--> $DIR/collections.rs:30:16
14+
--> $DIR/collections.rs:26:16
2115
|
2216
LL | Member<U>;
2317
| ^ type parameter not allowed
2418

2519
error[E0110]: lifetime parameters are not allowed on this type
26-
--> $DIR/collections.rs:51:50
20+
--> $DIR/collections.rs:33:50
21+
|
22+
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
23+
| ^^^^^ lifetime parameter not allowed on this type
24+
25+
error[E0110]: lifetime parameters are not allowed on this type
26+
--> $DIR/collections.rs:59:50
2727
|
2828
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
2929
| ^^^^^ lifetime parameter not allowed on this type

src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#![feature(generic_associated_types)]
1212

13+
use std::ops::Deref;
14+
1315
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
1416
//follow-up PR
1517

@@ -18,11 +20,18 @@ trait Foo {
1820
}
1921

2022
trait Baz {
21-
type Quux<'a>;
23+
type Quux<'a>: Foo;
24+
25+
// This weird type tests that we can use universal function call syntax to access the Item on
26+
type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
27+
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
28+
//~| ERROR lifetime parameters are not allowed on this type [E0110]
2229
}
2330

2431
impl<T> Baz for T where T: Foo {
25-
type Quux<'a> = <T as Foo>::Bar<'a, 'static>;
32+
type Quux<'a> = T;
33+
34+
type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
2635
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
2736
}
2837

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
error[E0110]: lifetime parameters are not allowed on this type
2-
--> $DIR/construct_with_other_type.rs:25:37
2+
--> $DIR/construct_with_other_type.rs:26:46
33
|
4-
LL | type Quux<'a> = <T as Foo>::Bar<'a, 'static>;
5-
| ^^ lifetime parameter not allowed on this type
4+
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
5+
| ^^ lifetime parameter not allowed on this type
66

7-
error: aborting due to previous error
7+
error[E0110]: lifetime parameters are not allowed on this type
8+
--> $DIR/construct_with_other_type.rs:26:63
9+
|
10+
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
11+
| ^^ lifetime parameter not allowed on this type
12+
13+
error[E0110]: lifetime parameters are not allowed on this type
14+
--> $DIR/construct_with_other_type.rs:34:40
15+
|
16+
LL | type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
17+
| ^^ lifetime parameter not allowed on this type
18+
19+
error: aborting due to 3 previous errors
820

921
For more information about this error, try `rustc --explain E0110`.

src/test/ui/rfc1598-generic-associated-types/iterable.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ trait Iterable {
2020
type Iter<'a>: Iterator<Item = Self::Item<'a>>;
2121
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
2222

23-
// This weird type tests that we can use universal function call syntax to access the Item on
24-
// Self::Iter which we have declared to be an Iterator
25-
type Iter2<'a>: Deref<Target = <Self::Iter<'a> as Iterator>::Item>;
26-
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
27-
2823
fn iter<'a>(&'a self) -> Self::Iter<'a>;
2924
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
3025
}
@@ -33,8 +28,7 @@ trait Iterable {
3328
impl<T> Iterable for Vec<T> {
3429
type Item<'a> = &'a T;
3530
type Iter<'a> = std::slice::Iter<'a, T>;
36-
type Iter2<'a> = &'a T;
37-
// gavento: ^^^ Not 100% sure about the intention here
31+
3832
fn iter<'a>(&'a self) -> Self::Iter<'a> {
3933
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
4034
self.iter()
@@ -45,8 +39,7 @@ impl<T> Iterable for Vec<T> {
4539
impl<T> Iterable for [T] {
4640
type Item<'a> = &'a T;
4741
type Iter<'a> = std::slice::Iter<'a, T>;
48-
type Iter2<'a> = &'a T;
49-
// gavento: ^^^ Not 100% sure about the intention here
42+
5043
fn iter<'a>(&'a self) -> Self::Iter<'a> {
5144
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
5245
self.iter()

src/test/ui/rfc1598-generic-associated-types/iterable.stderr

+6-12
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,35 @@ LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>;
55
| ^^ lifetime parameter not allowed on this type
66

77
error[E0110]: lifetime parameters are not allowed on this type
8-
--> $DIR/iterable.rs:25:48
9-
|
10-
LL | type Iter2<'a>: Deref<Target = <Self::Iter<'a> as Iterator>::Item>;
11-
| ^^ lifetime parameter not allowed on this type
12-
13-
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/iterable.rs:56:53
8+
--> $DIR/iterable.rs:49:53
159
|
1610
LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
1711
| ^^ lifetime parameter not allowed on this type
1812

1913
error[E0110]: lifetime parameters are not allowed on this type
20-
--> $DIR/iterable.rs:61:60
14+
--> $DIR/iterable.rs:54:60
2115
|
2216
LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
2317
| ^^ lifetime parameter not allowed on this type
2418

2519
error[E0110]: lifetime parameters are not allowed on this type
26-
--> $DIR/iterable.rs:28:41
20+
--> $DIR/iterable.rs:23:41
2721
|
2822
LL | fn iter<'a>(&'a self) -> Self::Iter<'a>;
2923
| ^^ lifetime parameter not allowed on this type
3024

3125
error[E0110]: lifetime parameters are not allowed on this type
32-
--> $DIR/iterable.rs:38:41
26+
--> $DIR/iterable.rs:32:41
3327
|
3428
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
3529
| ^^ lifetime parameter not allowed on this type
3630

3731
error[E0110]: lifetime parameters are not allowed on this type
38-
--> $DIR/iterable.rs:50:41
32+
--> $DIR/iterable.rs:43:41
3933
|
4034
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
4135
| ^^ lifetime parameter not allowed on this type
4236

43-
error: aborting due to 7 previous errors
37+
error: aborting due to 6 previous errors
4438

4539
For more information about this error, try `rustc --explain E0110`.

src/test/ui/rfc1598-generic-associated-types/shadowing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#![feature(generic_associated_types)]
1212

1313
//FIXME(#44265): The lifetime shadowing and type parameter shadowing
14-
// should cause an error. This will be addressed by a future PR.
15-
// For now this compiles:
14+
// should cause an error. Now it compiles (errorneously) and this will be addressed
15+
// by a future PR. Then remove the following:
1616
// must-compile-successfully
1717

1818
trait Shadow<'a> {

0 commit comments

Comments
 (0)