Auto merge of #55808 - estebank:type-arguments, r=petrochenkov

Suggest correct syntax when writing type arg instead of assoc type

- When confusing an associated type with a type argument, suggest the appropriate syntax. Given `Iterator<isize>`, suggest `Iterator<Item = isize>`.
- When encountering multiple missing associated types, emit only one diagnostic.
- Point at associated type def span for context.
- Point at each extra type argument.

Follow up to #48288, fix #20977.
This commit is contained in:
bors 2018-11-23 11:26:48 +00:00
commit aecbcd1ce2
20 changed files with 222 additions and 94 deletions

View file

@ -16,9 +16,7 @@ trait Hierarchy {
type Value;
type ChildKey;
type Children = Index<Self::ChildKey, Output=Hierarchy>;
//~^ ERROR: the value of the associated type `ChildKey`
//~^^ ERROR: the value of the associated type `Children`
//~^^^ ERROR: the value of the associated type `Value`
//~^ ERROR: the value of the associated types `Value` (from the trait `Hierarchy`), `ChildKey`
fn data(&self) -> Option<(Self::Value, Self::Children)>;
}

View file

@ -25,8 +25,11 @@ LL | fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
error[E0191]: the value of the associated type `Color` (from the trait `Vehicle`) must be specified
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:33:26
|
LL | type Color;
| ----------- `Color` defined here
...
LL | fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
| ^^^^^^^^^^^^^^^^^^^ missing associated type `Color` value
| ^^^^^^^^^^^^^^^^^^^ associated type `Color` must be specified
error[E0221]: ambiguous associated type `Color` in bounds of `C`
--> $DIR/associated-type-projection-from-multiple-supertraits.rs:38:29

View file

@ -37,6 +37,5 @@ pub fn main() {
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
let d = &42isize as &Foo;
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
//~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified
//~^ ERROR the value of the associated types `A` (from the trait `Foo`), `B` (from the trait
}

View file

@ -1,27 +1,35 @@
error[E0191]: the value of the associated type `B` (from the trait `Foo`) must be specified
--> $DIR/associated-types-incomplete-object.rs:33:26
|
LL | type B;
| ------- `B` defined here
...
LL | let b = &42isize as &Foo<A=usize>;
| ^^^^^^^^^^^^ missing associated type `B` value
| ^^^^^^^^^^^^ associated type `B` must be specified
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
--> $DIR/associated-types-incomplete-object.rs:36:26
|
LL | type A;
| ------- `A` defined here
...
LL | let c = &42isize as &Foo<B=char>;
| ^^^^^^^^^^^ missing associated type `A` value
| ^^^^^^^^^^^ associated type `A` must be specified
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
error[E0191]: the value of the associated types `A` (from the trait `Foo`), `B` (from the trait `Foo`) must be specified
--> $DIR/associated-types-incomplete-object.rs:39:26
|
LL | type A;
| ------- `A` defined here
LL | type B;
| ------- `B` defined here
...
LL | let d = &42isize as &Foo;
| ^^^ missing associated type `A` value
| ^^^
| |
| associated type `A` must be specified
| associated type `B` must be specified
error[E0191]: the value of the associated type `B` (from the trait `Foo`) must be specified
--> $DIR/associated-types-incomplete-object.rs:39:26
|
LL | let d = &42isize as &Foo;
| ^^^ missing associated type `B` value
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0191`.

View file

@ -26,7 +26,8 @@ struct Baz<'a, 'b, 'c> {
//~| unexpected lifetime argument
foo2: Foo<'a, 'b, 'c>,
//~^ ERROR E0107
//~| 2 unexpected lifetime arguments
//~| unexpected lifetime argument
//~| unexpected lifetime argument
}
fn main() {}

View file

@ -11,10 +11,12 @@ LL | bar: Bar<'a>,
| ^^ unexpected lifetime argument
error[E0107]: wrong number of lifetime arguments: expected 1, found 3
--> $DIR/E0107.rs:27:11
--> $DIR/E0107.rs:27:19
|
LL | foo2: Foo<'a, 'b, 'c>,
| ^^^^^^^^^^^^^^^ 2 unexpected lifetime arguments
| ^^ ^^ unexpected lifetime argument
| |
| unexpected lifetime argument
error: aborting due to 3 previous errors

View file

@ -1,8 +1,11 @@
error[E0191]: the value of the associated type `Bar` (from the trait `Trait`) must be specified
--> $DIR/E0191.rs:15:12
|
LL | type Bar;
| --------- `Bar` defined here
...
LL | type Foo = Trait; //~ ERROR E0191
| ^^^^^ missing associated type `Bar` value
| ^^^^^ associated type `Bar` must be specified
error: aborting due to previous error

View file

@ -7,8 +7,11 @@ LL | type Foo = Trait<F=i32>; //~ ERROR E0220
error[E0191]: the value of the associated type `Bar` (from the trait `Trait`) must be specified
--> $DIR/E0220.rs:15:12
|
LL | type Bar;
| --------- `Bar` defined here
...
LL | type Foo = Trait<F=i32>; //~ ERROR E0220
| ^^^^^^^^^^^^ missing associated type `Bar` value
| ^^^^^^^^^^^^ associated type `Bar` must be specified
error: aborting due to 2 previous errors

View file

@ -1,8 +1,11 @@
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
--> $DIR/issue-19482.rs:20:12
|
LL | type A;
| ------- `A` defined here
...
LL | fn bar(x: &Foo) {}
| ^^^ missing associated type `A` value
| ^^^ associated type `A` must be specified
error: aborting due to previous error

View file

@ -10,7 +10,7 @@ error[E0191]: the value of the associated type `Output` (from the trait `std::op
--> $DIR/issue-21950.rs:17:14
|
LL | &Add;
| ^^^ missing associated type `Output` value
| ^^^ associated type `Output` must be specified
error: aborting due to 2 previous errors

View file

@ -1,8 +1,11 @@
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
--> $DIR/issue-22434.rs:15:19
|
LL | type A;
| ------- `A` defined here
...
LL | type I<'a> = &'a (Foo + 'a);
| ^^^^^^^^ missing associated type `A` value
| ^^^^^^^^ associated type `A` must be specified
error: aborting due to previous error

View file

@ -28,7 +28,7 @@ LL | type Test = Add +
LL | | //~^ ERROR E0393
LL | | //~| ERROR E0191
LL | | Sub;
| |_______________^ missing associated type `Output` value
| |_______________^ associated type `Output` must be specified
error: aborting due to 4 previous errors

View file

@ -16,7 +16,7 @@ error[E0191]: the value of the associated type `Output` (from the trait `std::op
--> $DIR/issue-23024.rs:19:35
|
LL | println!("{:?}",(vfnfer[0] as Fn)(3));
| ^^ missing associated type `Output` value
| ^^ associated type `Output` must be specified
error: aborting due to 3 previous errors

View file

@ -2,7 +2,7 @@ error[E0191]: the value of the associated type `Output` (from the trait `std::op
--> $DIR/issue-28344.rs:14:17
|
LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
| ^^^^^^^^^^^^^ missing associated type `Output` value
| ^^^^^^^^^^^^^ associated type `Output` must be specified
error[E0599]: no function or associated item named `bitor` found for type `dyn std::ops::BitXor<_>` in the current scope
--> $DIR/issue-28344.rs:14:17
@ -16,7 +16,7 @@ error[E0191]: the value of the associated type `Output` (from the trait `std::op
--> $DIR/issue-28344.rs:18:13
|
LL | let g = BitXor::bitor;
| ^^^^^^^^^^^^^ missing associated type `Output` value
| ^^^^^^^^^^^^^ associated type `Output` must be specified
error[E0599]: no function or associated item named `bitor` found for type `dyn std::ops::BitXor<_>` in the current scope
--> $DIR/issue-28344.rs:18:13

View file

@ -0,0 +1,8 @@
pub trait T<X, Y> {
type A;
type B;
type C;
}
pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
fn main() {}

View file

@ -0,0 +1,31 @@
error[E0107]: wrong number of type arguments: expected 2, found 4
--> $DIR/use-type-argument-instead-of-assoc-type.rs:6:42
|
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
| ^^^^^ ^^^^^ unexpected type argument
| |
| unexpected type argument
error[E0191]: the value of the associated types `A` (from the trait `T`), `C` (from the trait `T`) must be specified
--> $DIR/use-type-argument-instead-of-assoc-type.rs:6:26
|
LL | type A;
| ------- `A` defined here
LL | type B;
LL | type C;
| ------- `C` defined here
LL | }
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| associated type `A` must be specified
| associated type `C` must be specified
help: if you meant to specify the associated types, write
|
LL | pub struct Foo { i: Box<T<usize, usize, A = usize, C = usize, B=usize>> }
| ^^^^^^^^^ ^^^^^^^^^
error: aborting due to 2 previous errors
Some errors occurred: E0107, E0191.
For more information about an error, try `rustc --explain E0107`.

View file

@ -10,7 +10,7 @@ error[E0191]: the value of the associated type `Item` (from the trait `std::iter
--> $DIR/trait-alias-object.rs:18:13
|
LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
| ^^^^^^^^^^^^^^^^^ missing associated type `Item` value
| ^^^^^^^^^^^^^^^^^ associated type `Item` must be specified
error: aborting due to 2 previous errors