Skip to content

Commit fb3b47a

Browse files
committed
Auto merge of #54980 - zackmdavis:and_the_case_of_the_universal_call, r=oli-obk
structured suggestion for E0223 ambiguous associated type (routine (and when are we going to be done finding these, anyway?) but something that stuck out to me while glancing at #54970) r? @estebank
2 parents c47785f + a5de379 commit fb3b47a

12 files changed

+31
-78
lines changed

Diff for: src/librustc_typeck/astconv.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::slice;
3030
use require_c_abi_if_variadic;
3131
use util::common::ErrorReported;
3232
use util::nodemap::FxHashMap;
33-
use errors::{FatalError, DiagnosticId};
33+
use errors::{Applicability, FatalError, DiagnosticId};
3434
use lint;
3535

3636
use std::iter;
@@ -1092,11 +1092,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10921092
trait_str: &str,
10931093
name: &str) {
10941094
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
1095-
.span_label(span, "ambiguous associated type")
1096-
.note(&format!("specify the type using the syntax `<{} as {}>::{}`",
1097-
type_str, trait_str, name))
1098-
.emit();
1099-
1095+
.span_suggestion_with_applicability(
1096+
span,
1097+
"use fully-qualified syntax",
1098+
format!("<{} as {}>::{}", type_str, trait_str, name),
1099+
Applicability::HasPlaceholders
1100+
).emit();
11001101
}
11011102

11021103
// Search for a bound on a type parameter which includes the associated item

Diff for: src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ error[E0223]: ambiguous associated type
22
--> $DIR/associated-types-in-ambiguous-context.rs:16:36
33
|
44
LL | fn get<T:Get,U:Get>(x: T, y: U) -> Get::Value {}
5-
| ^^^^^^^^^^ ambiguous associated type
6-
|
7-
= note: specify the type using the syntax `<Type as Get>::Value`
5+
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Type as Get>::Value`
86

97
error[E0223]: ambiguous associated type
108
--> $DIR/associated-types-in-ambiguous-context.rs:25:10
119
|
1210
LL | type X = std::ops::Deref::Target;
13-
| ^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
14-
|
15-
= note: specify the type using the syntax `<Type as std::ops::Deref>::Target`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<Type as std::ops::Deref>::Target`
1612

1713
error[E0223]: ambiguous associated type
1814
--> $DIR/associated-types-in-ambiguous-context.rs:21:23
1915
|
2016
LL | fn grab(&self) -> Grab::Value;
21-
| ^^^^^^^^^^^ ambiguous associated type
22-
|
23-
= note: specify the type using the syntax `<Type as Grab>::Value`
17+
| ^^^^^^^^^^^ help: use fully-qualified syntax: `<Type as Grab>::Value`
2418

2519
error: aborting due to 3 previous errors
2620

Diff for: src/test/ui/did_you_mean/bad-assoc-ty.stderr

+7-21
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,25 @@ error[E0223]: ambiguous associated type
4444
--> $DIR/bad-assoc-ty.rs:11:10
4545
|
4646
LL | type A = [u8; 4]::AssocTy;
47-
| ^^^^^^^^^^^^^^^^ ambiguous associated type
48-
|
49-
= note: specify the type using the syntax `<[u8; _] as Trait>::AssocTy`
47+
| ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<[u8; _] as Trait>::AssocTy`
5048

5149
error[E0223]: ambiguous associated type
5250
--> $DIR/bad-assoc-ty.rs:15:10
5351
|
5452
LL | type B = [u8]::AssocTy;
55-
| ^^^^^^^^^^^^^ ambiguous associated type
56-
|
57-
= note: specify the type using the syntax `<[u8] as Trait>::AssocTy`
53+
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<[u8] as Trait>::AssocTy`
5854

5955
error[E0223]: ambiguous associated type
6056
--> $DIR/bad-assoc-ty.rs:19:10
6157
|
6258
LL | type C = (u8)::AssocTy;
63-
| ^^^^^^^^^^^^^ ambiguous associated type
64-
|
65-
= note: specify the type using the syntax `<u8 as Trait>::AssocTy`
59+
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
6660

6761
error[E0223]: ambiguous associated type
6862
--> $DIR/bad-assoc-ty.rs:23:10
6963
|
7064
LL | type D = (u8, u8)::AssocTy;
71-
| ^^^^^^^^^^^^^^^^^ ambiguous associated type
72-
|
73-
= note: specify the type using the syntax `<(u8, u8) as Trait>::AssocTy`
65+
| ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(u8, u8) as Trait>::AssocTy`
7466

7567
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
7668
--> $DIR/bad-assoc-ty.rs:27:10
@@ -82,25 +74,19 @@ error[E0223]: ambiguous associated type
8274
--> $DIR/bad-assoc-ty.rs:31:19
8375
|
8476
LL | type F = &'static (u8)::AssocTy;
85-
| ^^^^^^^^^^^^^ ambiguous associated type
86-
|
87-
= note: specify the type using the syntax `<u8 as Trait>::AssocTy`
77+
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
8878

8979
error[E0223]: ambiguous associated type
9080
--> $DIR/bad-assoc-ty.rs:37:10
9181
|
9282
LL | type G = 'static + (Send)::AssocTy;
93-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
94-
|
95-
= note: specify the type using the syntax `<(dyn std::marker::Send + 'static) as Trait>::AssocTy`
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::marker::Send + 'static) as Trait>::AssocTy`
9684

9785
error[E0223]: ambiguous associated type
9886
--> $DIR/bad-assoc-ty.rs:43:10
9987
|
10088
LL | type H = Fn(u8) -> (u8)::Output;
101-
| ^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
102-
|
103-
= note: specify the type using the syntax `<(dyn std::ops::Fn(u8) -> u8 + 'static) as Trait>::Output`
89+
| ^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::ops::Fn(u8) -> u8 + 'static) as Trait>::Output`
10490

10591
error: aborting due to 15 previous errors
10692

Diff for: src/test/ui/error-codes/E0223.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
22
--> $DIR/E0223.rs:14:14
33
|
44
LL | let foo: MyTrait::X;
5-
| ^^^^^^^^^^ ambiguous associated type
6-
|
7-
= note: specify the type using the syntax `<Type as MyTrait>::X`
5+
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Type as MyTrait>::X`
86

97
error: aborting due to previous error
108

Diff for: src/test/ui/impl-trait/impl_trait_projections.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ error[E0223]: ambiguous associated type
2626
--> $DIR/impl_trait_projections.rs:21:50
2727
|
2828
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
29-
| ^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
30-
|
31-
= note: specify the type using the syntax `<impl std::iter::Iterator as Trait>::Item`
29+
| ^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<impl std::iter::Iterator as Trait>::Item`
3230

3331
error: aborting due to 5 previous errors
3432

Diff for: src/test/ui/issues/issue-23073.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
22
--> $DIR/issue-23073.rs:16:17
33
|
44
LL | type FooT = <<Self as Bar>::Foo>::T; //~ ERROR ambiguous associated type
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
6-
|
7-
= note: specify the type using the syntax `<<Self as Bar>::Foo as Trait>::T`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<Self as Bar>::Foo as Trait>::T`
86

97
error: aborting due to previous error
108

Diff for: src/test/ui/issues/issue-34209.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
22
--> $DIR/issue-34209.rs:17:9
33
|
44
LL | S::B{ } => { },
5-
| ^^^^ ambiguous associated type
6-
|
7-
= note: specify the type using the syntax `<S as Trait>::B`
5+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::B`
86

97
error: aborting due to previous error
108

Diff for: src/test/ui/qualified/qualified-path-params-2.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ error[E0223]: ambiguous associated type
88
--> $DIR/qualified-path-params-2.rs:28:10
99
|
1010
LL | type A = <S as Tr>::A::f<u8>;
11-
| ^^^^^^^^^^^^^^^^^^^ ambiguous associated type
12-
|
13-
= note: specify the type using the syntax `<<S as Tr>::A as Trait>::f`
11+
| ^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<S as Tr>::A as Trait>::f`
1412

1513
error: aborting due to 2 previous errors
1614

Diff for: src/test/ui/self/self-impl.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ error[E0223]: ambiguous associated type
22
--> $DIR/self-impl.rs:33:16
33
|
44
LL | let _: <Self>::Baz = true;
5-
| ^^^^^^^^^^^ ambiguous associated type
6-
|
7-
= note: specify the type using the syntax `<Bar as Trait>::Baz`
5+
| ^^^^^^^^^^^ help: use fully-qualified syntax: `<Bar as Trait>::Baz`
86

97
error[E0223]: ambiguous associated type
108
--> $DIR/self-impl.rs:35:16
119
|
1210
LL | let _: Self::Baz = true;
13-
| ^^^^^^^^^ ambiguous associated type
14-
|
15-
= note: specify the type using the syntax `<Bar as Trait>::Baz`
11+
| ^^^^^^^^^ help: use fully-qualified syntax: `<Bar as Trait>::Baz`
1612

1713
error: aborting due to 2 previous errors
1814

Diff for: src/test/ui/structs/struct-path-associated-type.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ error[E0223]: ambiguous associated type
3232
--> $DIR/struct-path-associated-type.rs:42:13
3333
|
3434
LL | let s = S::A {}; //~ ERROR ambiguous associated type
35-
| ^^^^ ambiguous associated type
36-
|
37-
= note: specify the type using the syntax `<S as Trait>::A`
35+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
3836

3937
error[E0109]: type parameters are not allowed on this type
4038
--> $DIR/struct-path-associated-type.rs:43:20
@@ -46,17 +44,13 @@ error[E0223]: ambiguous associated type
4644
--> $DIR/struct-path-associated-type.rs:43:13
4745
|
4846
LL | let z = S::A::<u8> {}; //~ ERROR ambiguous associated type
49-
| ^^^^^^^^^^ ambiguous associated type
50-
|
51-
= note: specify the type using the syntax `<S as Trait>::A`
47+
| ^^^^^^^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
5248

5349
error[E0223]: ambiguous associated type
5450
--> $DIR/struct-path-associated-type.rs:46:9
5551
|
5652
LL | S::A {} => {} //~ ERROR ambiguous associated type
57-
| ^^^^ ambiguous associated type
58-
|
59-
= note: specify the type using the syntax `<S as Trait>::A`
53+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
6054

6155
error: aborting due to 9 previous errors
6256

Diff for: src/test/ui/traits/trait-item-privacy.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,19 @@ error[E0223]: ambiguous associated type
138138
--> $DIR/trait-item-privacy.rs:127:12
139139
|
140140
LL | let _: S::A; //~ ERROR ambiguous associated type
141-
| ^^^^ ambiguous associated type
142-
|
143-
= note: specify the type using the syntax `<S as Trait>::A`
141+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
144142

145143
error[E0223]: ambiguous associated type
146144
--> $DIR/trait-item-privacy.rs:128:12
147145
|
148146
LL | let _: S::B; //~ ERROR ambiguous associated type
149-
| ^^^^ ambiguous associated type
150-
|
151-
= note: specify the type using the syntax `<S as Trait>::B`
147+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::B`
152148

153149
error[E0223]: ambiguous associated type
154150
--> $DIR/trait-item-privacy.rs:129:12
155151
|
156152
LL | let _: S::C; //~ ERROR ambiguous associated type
157-
| ^^^^ ambiguous associated type
158-
|
159-
= note: specify the type using the syntax `<S as Trait>::C`
153+
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::C`
160154

161155
error: associated type `A` is private
162156
--> $DIR/trait-item-privacy.rs:131:12

Diff for: src/test/ui/ufcs/ufcs-partially-resolved.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ error[E0223]: ambiguous associated type
184184
--> $DIR/ufcs-partially-resolved.rs:46:12
185185
|
186186
LL | let _: <u8 as Tr>::Y::NN; //~ ERROR ambiguous associated type
187-
| ^^^^^^^^^^^^^^^^^ ambiguous associated type
188-
|
189-
= note: specify the type using the syntax `<<u8 as Tr>::Y as Trait>::NN`
187+
| ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<u8 as Tr>::Y as Trait>::NN`
190188

191189
error[E0599]: no associated item named `NN` found for type `<u8 as Tr>::Y` in the current scope
192190
--> $DIR/ufcs-partially-resolved.rs:48:5

0 commit comments

Comments
 (0)