Skip to content

Commit 547abe0

Browse files
committed
Tweak errors for missing associated types and type parameters
1 parent c5a2a9a commit 547abe0

37 files changed

+611
-299
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 194 additions & 56 deletions
Large diffs are not rendered by default.

src/test/compile-fail/issue-23595-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![feature(associated_type_defaults)]
22

3-
use std::ops::{Index};
3+
use std::ops::Index;
44

55
trait Hierarchy {
66
type Value;
77
type ChildKey;
88
type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
9-
//~^ ERROR: the value of the associated types `Value` (from the trait `Hierarchy`), `ChildKey`
9+
//~^ ERROR: the value of the associated types `Value` (from trait `Hierarchy`), `ChildKey`
1010

1111
fn data(&self) -> Option<(Self::Value, Self::Children)>;
1212
}

src/test/ui/associated-type-bounds/duplicate.rs

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

src/test/ui/associated-type-bounds/duplicate.stderr

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

src/test/ui/associated-type/associated-type-projection-ambig-between-bound-and-where-clause.stderr

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ LL | type Color;
99
...
1010
LL | fn a<C:Vehicle+Box>(_: C::Color) {
1111
| ^^^^^^^^ ambiguous associated type `Color`
12+
|
13+
help: use fully qualified syntax to disambiguate
14+
|
15+
LL | fn a<C:Vehicle+Box>(_: <C as Box>::Color) {
16+
| ^^^^^^^^^^^^^^^^^
17+
help: use fully qualified syntax to disambiguate
18+
|
19+
LL | fn a<C:Vehicle+Box>(_: <C as Vehicle>::Color) {
20+
| ^^^^^^^^^^^^^^^^^^^^^
1221

1322
error[E0221]: ambiguous associated type `Color` in bounds of `C`
1423
--> $DIR/associated-type-projection-ambig-between-bound-and-where-clause.rs:20:12
@@ -21,6 +30,15 @@ LL | type Color;
2130
...
2231
LL | fn b<C>(_: C::Color) where C : Vehicle+Box {
2332
| ^^^^^^^^ ambiguous associated type `Color`
33+
|
34+
help: use fully qualified syntax to disambiguate
35+
|
36+
LL | fn b<C>(_: <C as Box>::Color) where C : Vehicle+Box {
37+
| ^^^^^^^^^^^^^^^^^
38+
help: use fully qualified syntax to disambiguate
39+
|
40+
LL | fn b<C>(_: <C as Vehicle>::Color) where C : Vehicle+Box {
41+
| ^^^^^^^^^^^^^^^^^^^^^
2442

2543
error[E0221]: ambiguous associated type `Color` in bounds of `C`
2644
--> $DIR/associated-type-projection-ambig-between-bound-and-where-clause.rs:24:12
@@ -33,6 +51,15 @@ LL | type Color;
3351
...
3452
LL | fn c<C>(_: C::Color) where C : Vehicle, C : Box {
3553
| ^^^^^^^^ ambiguous associated type `Color`
54+
|
55+
help: use fully qualified syntax to disambiguate
56+
|
57+
LL | fn c<C>(_: <C as Box>::Color) where C : Vehicle, C : Box {
58+
| ^^^^^^^^^^^^^^^^^
59+
help: use fully qualified syntax to disambiguate
60+
|
61+
LL | fn c<C>(_: <C as Vehicle>::Color) where C : Vehicle, C : Box {
62+
| ^^^^^^^^^^^^^^^^^^^^^
3663

3764
error[E0221]: ambiguous associated type `Color` in bounds of `X`
3865
--> $DIR/associated-type-projection-ambig-between-bound-and-where-clause.rs:35:20
@@ -45,6 +72,15 @@ LL | type Color;
4572
...
4673
LL | fn e(&self, _: X::Color) where X : Box;
4774
| ^^^^^^^^ ambiguous associated type `Color`
75+
|
76+
help: use fully qualified syntax to disambiguate
77+
|
78+
LL | fn e(&self, _: <X as Box>::Color) where X : Box;
79+
| ^^^^^^^^^^^^^^^^^
80+
help: use fully qualified syntax to disambiguate
81+
|
82+
LL | fn e(&self, _: <X as Vehicle>::Color) where X : Box;
83+
| ^^^^^^^^^^^^^^^^^^^^^
4884

4985
error[E0221]: ambiguous associated type `Color` in bounds of `X`
5086
--> $DIR/associated-type-projection-ambig-between-bound-and-where-clause.rs:38:20
@@ -57,6 +93,15 @@ LL | type Color;
5793
...
5894
LL | fn f(&self, _: X::Color) where X : Box { }
5995
| ^^^^^^^^ ambiguous associated type `Color`
96+
|
97+
help: use fully qualified syntax to disambiguate
98+
|
99+
LL | fn f(&self, _: <X as Box>::Color) where X : Box { }
100+
| ^^^^^^^^^^^^^^^^^
101+
help: use fully qualified syntax to disambiguate
102+
|
103+
LL | fn f(&self, _: <X as Vehicle>::Color) where X : Box { }
104+
| ^^^^^^^^^^^^^^^^^^^^^
60105

61106
error[E0221]: ambiguous associated type `Color` in bounds of `X`
62107
--> $DIR/associated-type-projection-ambig-between-bound-and-where-clause.rs:30:20
@@ -69,6 +114,15 @@ LL | type Color;
69114
...
70115
LL | fn d(&self, _: X::Color) where X : Box { }
71116
| ^^^^^^^^ ambiguous associated type `Color`
117+
|
118+
help: use fully qualified syntax to disambiguate
119+
|
120+
LL | fn d(&self, _: <X as Box>::Color) where X : Box { }
121+
| ^^^^^^^^^^^^^^^^^
122+
help: use fully qualified syntax to disambiguate
123+
|
124+
LL | fn d(&self, _: <X as Vehicle>::Color) where X : Box { }
125+
| ^^^^^^^^^^^^^^^^^^^^^
72126

73127
error: aborting due to 6 previous errors
74128

src/test/ui/associated-type/associated-type-projection-from-multiple-supertraits.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,26 @@ fn dent<C:BoxCar>(c: C, color: C::Color) {
2020
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
2121
}
2222

23+
// FIXME: add error code to detect this case and explain that you'll want the approach in
24+
// `dent_object_3` of using a new type param and relying on the `where` clauses.
2325
fn dent_object<COLOR>(c: dyn BoxCar<Color=COLOR>) {
2426
//~^ ERROR ambiguous associated type
25-
//~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified
27+
//~| ERROR the value of the associated type `Color` (from trait `Vehicle`) must be specified
2628
}
2729

2830
fn paint<C:BoxCar>(c: C, d: C::Color) {
2931
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
3032
}
3133

34+
fn dent_object_2<COLOR>(c: dyn BoxCar) where <dyn BoxCar as Vehicle>::Color = COLOR {
35+
//~^ ERROR the value of the associated types `Color` (from trait `Vehicle`), `Color` (from
36+
//~| ERROR equality constraints are not yet supported in where clauses
37+
}
38+
39+
fn dent_object_3<X, COLOR>(c: X)
40+
where X: BoxCar,
41+
X: Vehicle<Color = COLOR>,
42+
X: Box<Color = COLOR>
43+
{} // OK!
44+
3245
pub fn main() { }

src/test/ui/associated-type/associated-type-projection-from-multiple-supertraits.stderr

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: equality constraints are not yet supported in where clauses (see #20041)
2+
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:34:46
3+
|
4+
LL | fn dent_object_2<COLOR>(c: dyn BoxCar) where <dyn BoxCar as Vehicle>::Color = COLOR {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0221]: ambiguous associated type `Color` in bounds of `C`
28
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:19:32
39
|
@@ -9,9 +15,18 @@ LL | type Color;
915
...
1016
LL | fn dent<C:BoxCar>(c: C, color: C::Color) {
1117
| ^^^^^^^^ ambiguous associated type `Color`
18+
|
19+
help: use fully qualified syntax to disambiguate
20+
|
21+
LL | fn dent<C:BoxCar>(c: C, color: <C as Box>::Color) {
22+
| ^^^^^^^^^^^^^^^^^
23+
help: use fully qualified syntax to disambiguate
24+
|
25+
LL | fn dent<C:BoxCar>(c: C, color: <C as Vehicle>::Color) {
26+
| ^^^^^^^^^^^^^^^^^^^^^
1227

1328
error[E0221]: ambiguous associated type `Color` in bounds of `BoxCar`
14-
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:23:37
29+
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:25:37
1530
|
1631
LL | type Color;
1732
| ----------- ambiguous `Color` from `Vehicle`
@@ -21,18 +36,27 @@ LL | type Color;
2136
...
2237
LL | fn dent_object<COLOR>(c: dyn BoxCar<Color=COLOR>) {
2338
| ^^^^^^^^^^^ ambiguous associated type `Color`
39+
|
40+
help: use fully qualified syntax to disambiguate
41+
|
42+
LL | fn dent_object<COLOR>(c: dyn BoxCar<<BoxCar as Box>::Color>) {
43+
| ^^^^^^^^^^^^^^^^^^^^^^
44+
help: use fully qualified syntax to disambiguate
45+
|
46+
LL | fn dent_object<COLOR>(c: dyn BoxCar<<BoxCar as Vehicle>::Color>) {
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2448

25-
error[E0191]: the value of the associated type `Color` (from the trait `Vehicle`) must be specified
26-
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:23:26
49+
error[E0191]: the value of the associated type `Color` (from trait `Vehicle`) must be specified
50+
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:25:30
2751
|
2852
LL | type Color;
2953
| ----------- `Color` defined here
3054
...
3155
LL | fn dent_object<COLOR>(c: dyn BoxCar<Color=COLOR>) {
32-
| ^^^^^^^^^^^^^^^^^^^^^^^ associated type `Color` must be specified
56+
| ^^^^^^^^^^^^^^^^^^^ help: specify the associated type: `BoxCar<Color=COLOR, Color = Type>`
3357

3458
error[E0221]: ambiguous associated type `Color` in bounds of `C`
35-
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:28:29
59+
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:30:29
3660
|
3761
LL | type Color;
3862
| ----------- ambiguous `Color` from `Vehicle`
@@ -42,8 +66,29 @@ LL | type Color;
4266
...
4367
LL | fn paint<C:BoxCar>(c: C, d: C::Color) {
4468
| ^^^^^^^^ ambiguous associated type `Color`
69+
|
70+
help: use fully qualified syntax to disambiguate
71+
|
72+
LL | fn paint<C:BoxCar>(c: C, d: <C as Box>::Color) {
73+
| ^^^^^^^^^^^^^^^^^
74+
help: use fully qualified syntax to disambiguate
75+
|
76+
LL | fn paint<C:BoxCar>(c: C, d: <C as Vehicle>::Color) {
77+
| ^^^^^^^^^^^^^^^^^^^^^
78+
79+
error[E0191]: the value of the associated types `Color` (from trait `Vehicle`), `Color` (from trait `Box`) must be specified
80+
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:34:32
81+
|
82+
LL | type Color;
83+
| ----------- `Color` defined here
84+
...
85+
LL | type Color;
86+
| ----------- `Color` defined here
87+
...
88+
LL | fn dent_object_2<COLOR>(c: dyn BoxCar) where <dyn BoxCar as Vehicle>::Color = COLOR {
89+
| ^^^^^^ help: specify the associated types: `BoxCar<Color = Type, Color = Type>`
4590

46-
error: aborting due to 4 previous errors
91+
error: aborting due to 6 previous errors
4792

4893
Some errors have detailed explanations: E0191, E0221.
4994
For more information about an error, try `rustc --explain E0191`.

src/test/ui/associated-types/associated-types-incomplete-object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ pub fn main() {
2121
let a = &42isize as &dyn Foo<A=usize, B=char>;
2222

2323
let b = &42isize as &dyn Foo<A=usize>;
24-
//~^ ERROR the value of the associated type `B` (from the trait `Foo`) must be specified
24+
//~^ ERROR the value of the associated type `B` (from trait `Foo`) must be specified
2525

2626
let c = &42isize as &dyn Foo<B=char>;
27-
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
27+
//~^ ERROR the value of the associated type `A` (from trait `Foo`) must be specified
2828

2929
let d = &42isize as &dyn Foo;
30-
//~^ ERROR the value of the associated types `A` (from the trait `Foo`), `B` (from the trait
30+
//~^ ERROR the value of the associated types `A` (from trait `Foo`), `B` (from trait
3131
}

src/test/ui/associated-types/associated-types-incomplete-object.stderr

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
error[E0191]: the value of the associated type `B` (from the trait `Foo`) must be specified
2-
--> $DIR/associated-types-incomplete-object.rs:23:26
1+
error[E0191]: the value of the associated type `B` (from trait `Foo`) must be specified
2+
--> $DIR/associated-types-incomplete-object.rs:23:30
33
|
44
LL | type B;
55
| ------- `B` defined here
66
...
77
LL | let b = &42isize as &dyn Foo<A=usize>;
8-
| ^^^^^^^^^^^^^^^^ associated type `B` must be specified
8+
| ^^^^^^^^^^^^ help: specify the associated type: `Foo<A=usize, B = Type>`
99

10-
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
11-
--> $DIR/associated-types-incomplete-object.rs:26:26
10+
error[E0191]: the value of the associated type `A` (from trait `Foo`) must be specified
11+
--> $DIR/associated-types-incomplete-object.rs:26:30
1212
|
1313
LL | type A;
1414
| ------- `A` defined here
1515
...
1616
LL | let c = &42isize as &dyn Foo<B=char>;
17-
| ^^^^^^^^^^^^^^^ associated type `A` must be specified
17+
| ^^^^^^^^^^^ help: specify the associated type: `Foo<B=char, A = Type>`
1818

19-
error[E0191]: the value of the associated types `A` (from the trait `Foo`), `B` (from the trait `Foo`) must be specified
20-
--> $DIR/associated-types-incomplete-object.rs:29:26
19+
error[E0191]: the value of the associated types `A` (from trait `Foo`), `B` (from trait `Foo`) must be specified
20+
--> $DIR/associated-types-incomplete-object.rs:29:30
2121
|
2222
LL | type A;
2323
| ------- `A` defined here
2424
LL | type B;
2525
| ------- `B` defined here
2626
...
2727
LL | let d = &42isize as &dyn Foo;
28-
| ^^^^^^^
29-
| |
30-
| associated type `A` must be specified
31-
| associated type `B` must be specified
28+
| ^^^ help: specify the associated types: `Foo<A = Type, B = Type>`
3229

3330
error: aborting due to 3 previous errors
3431

src/test/ui/associated-types/associated-types-path-1.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ LL | type A;
1515
...
1616
LL | pub fn f2<T: Foo + Bar>(a: T, x: T::A) {}
1717
| ^^^^ ambiguous associated type `A`
18+
|
19+
help: use fully qualified syntax to disambiguate
20+
|
21+
LL | pub fn f2<T: Foo + Bar>(a: T, x: <T as Bar>::A) {}
22+
| ^^^^^^^^^^^^^
23+
help: use fully qualified syntax to disambiguate
24+
|
25+
LL | pub fn f2<T: Foo + Bar>(a: T, x: <T as Foo>::A) {}
26+
| ^^^^^^^^^^^^^
1827

1928
error: aborting due to 2 previous errors
2029

0 commit comments

Comments
 (0)