Skip to content

structured suggestion for E0223 ambiguous associated type #54980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::slice;
use require_c_abi_if_variadic;
use util::common::ErrorReported;
use util::nodemap::FxHashMap;
use errors::{FatalError, DiagnosticId};
use errors::{Applicability, FatalError, DiagnosticId};
use lint;

use std::iter;
Expand Down Expand Up @@ -1092,11 +1092,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
trait_str: &str,
name: &str) {
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
.span_label(span, "ambiguous associated type")
.note(&format!("specify the type using the syntax `<{} as {}>::{}`",
type_str, trait_str, name))
.emit();

.span_suggestion_with_applicability(
span,
"use fully-qualified syntax",
format!("<{} as {}>::{}", type_str, trait_str, name),
Applicability::HasPlaceholders
).emit();
}

// Search for a bound on a type parameter which includes the associated item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@ error[E0223]: ambiguous associated type
--> $DIR/associated-types-in-ambiguous-context.rs:16:36
|
LL | fn get<T:Get,U:Get>(x: T, y: U) -> Get::Value {}
| ^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<Type as Get>::Value`
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Type as Get>::Value`

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

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

error: aborting due to 3 previous errors

Expand Down
28 changes: 7 additions & 21 deletions src/test/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,25 @@ error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:11:10
|
LL | type A = [u8; 4]::AssocTy;
| ^^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<[u8; _] as Trait>::AssocTy`
| ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<[u8; _] as Trait>::AssocTy`

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

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

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

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

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

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

error: aborting due to 15 previous errors

Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/error-codes/E0223.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
--> $DIR/E0223.rs:14:14
|
LL | let foo: MyTrait::X;
| ^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<Type as MyTrait>::X`
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Type as MyTrait>::X`

error: aborting due to previous error

Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/impl-trait/impl_trait_projections.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ error[E0223]: ambiguous associated type
--> $DIR/impl_trait_projections.rs:21:50
|
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
| ^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<impl std::iter::Iterator as Trait>::Item`
| ^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<impl std::iter::Iterator as Trait>::Item`

error: aborting due to 5 previous errors

Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/issues/issue-23073.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
--> $DIR/issue-23073.rs:16:17
|
LL | type FooT = <<Self as Bar>::Foo>::T; //~ ERROR ambiguous associated type
| ^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<<Self as Bar>::Foo as Trait>::T`
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<Self as Bar>::Foo as Trait>::T`

error: aborting due to previous error

Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/issues/issue-34209.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error[E0223]: ambiguous associated type
--> $DIR/issue-34209.rs:17:9
|
LL | S::B{ } => { },
| ^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<S as Trait>::B`
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::B`

error: aborting due to previous error

Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/qualified/qualified-path-params-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ error[E0223]: ambiguous associated type
--> $DIR/qualified-path-params-2.rs:28:10
|
LL | type A = <S as Tr>::A::f<u8>;
| ^^^^^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<<S as Tr>::A as Trait>::f`
| ^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<S as Tr>::A as Trait>::f`

error: aborting due to 2 previous errors

Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/self/self-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ error[E0223]: ambiguous associated type
--> $DIR/self-impl.rs:33:16
|
LL | let _: <Self>::Baz = true;
| ^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<Bar as Trait>::Baz`
| ^^^^^^^^^^^ help: use fully-qualified syntax: `<Bar as Trait>::Baz`

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

error: aborting due to 2 previous errors

Expand Down
12 changes: 3 additions & 9 deletions src/test/ui/structs/struct-path-associated-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ error[E0223]: ambiguous associated type
--> $DIR/struct-path-associated-type.rs:42:13
|
LL | let s = S::A {}; //~ ERROR ambiguous associated type
| ^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<S as Trait>::A`
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`

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

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

error: aborting due to 9 previous errors

Expand Down
12 changes: 3 additions & 9 deletions src/test/ui/traits/trait-item-privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,19 @@ error[E0223]: ambiguous associated type
--> $DIR/trait-item-privacy.rs:127:12
|
LL | let _: S::A; //~ ERROR ambiguous associated type
| ^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<S as Trait>::A`
| ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`

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

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

error: associated type `A` is private
--> $DIR/trait-item-privacy.rs:131:12
Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/ufcs/ufcs-partially-resolved.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ error[E0223]: ambiguous associated type
--> $DIR/ufcs-partially-resolved.rs:46:12
|
LL | let _: <u8 as Tr>::Y::NN; //~ ERROR ambiguous associated type
| ^^^^^^^^^^^^^^^^^ ambiguous associated type
|
= note: specify the type using the syntax `<<u8 as Tr>::Y as Trait>::NN`
| ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<u8 as Tr>::Y as Trait>::NN`

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