]> git.lizzy.rs Git - rust.git/commitdiff
structured suggestion for E0223 ambiguous associated type
authorZack M. Davis <code@zackmdavis.net>
Thu, 11 Oct 2018 03:49:45 +0000 (20:49 -0700)
committerZack M. Davis <code@zackmdavis.net>
Fri, 12 Oct 2018 04:10:35 +0000 (21:10 -0700)
It looks like we tend to use angle-brackets around the placeholder in
the few other places we use `Applicability::HasPlaceholders`, but that
would be confusing here, so ...

12 files changed:
src/librustc_typeck/astconv.rs
src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr
src/test/ui/did_you_mean/bad-assoc-ty.stderr
src/test/ui/error-codes/E0223.stderr
src/test/ui/impl-trait/impl_trait_projections.stderr
src/test/ui/issues/issue-23073.stderr
src/test/ui/issues/issue-34209.stderr
src/test/ui/qualified/qualified-path-params-2.stderr
src/test/ui/self/self-impl.stderr
src/test/ui/structs/struct-path-associated-type.stderr
src/test/ui/traits/trait-item-privacy.stderr
src/test/ui/ufcs/ufcs-partially-resolved.stderr

index e4ad02595d107df0f8f0499283db6f0dfa3ca042..32889ef8698339b3c3e153656b9575c28cc0a6fe 100644 (file)
@@ -30,7 +30,7 @@
 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;
@@ -1092,11 +1092,12 @@ fn report_ambiguous_associated_type(&self,
                                         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
index c45873ffd53083f1906724142560f9ed7d2457eb..755e83daf4784c5b66a96438830a124cb77fd721 100644 (file)
@@ -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
 
index 33792d4f5b3fa4cb62efff4fe2ae71a42a6b3469..5de9f5866ff83a1d2cdf2e897c412b1beeb42acb 100644 (file)
@@ -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
@@ -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
 
index f65e744c62594dca6dc6310970c7ad7e890d49cf..87736c10774ffa9cb631986a49caf2e572c4d0f4 100644 (file)
@@ -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
 
index f6d58984ecef747ae3994640d005c6380d7ae928..a6daf898e30b5b476e826c4295a4aea1d17fd034 100644 (file)
@@ -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
 
index 44b2128af0aa1b968cb39254e2e497fb7204deda..ef2430561ec1147d9a9f094cb5df266f6694a8cb 100644 (file)
@@ -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
 
index 5c31acea5b600571093b90098e082d8b046c1213..0dfdd8b588634d2dc9c4f6a8d32c7762d803d66c 100644 (file)
@@ -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
 
index 8b618cbf7ba9e665ebb8eac89b0ff02833feca44..70aac7791035b5983b7e470cc9079dc4f6eed002 100644 (file)
@@ -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
 
index a5a5135faad729917c2b86bbbd0b31b7896d3b8b..b951b1194367feede1faab65cec0ea90ccce196e 100644 (file)
@@ -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
 
index 1364b2a6b0c8643bdcbde433a57cc84878100872..873e7bb7b835d39cf8027a3536ea6a0da0157b4f 100644 (file)
@@ -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
@@ -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
 
index a3747bcee5d5c3e1263699048f40800a6bf45776..fc14ae91d7b36c3464d4ed1cbb86256c16a54487 100644 (file)
@@ -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
index 5de8fb158b770282bb6271588169b59874b0d2c0..77d887f1d68d8e616070e137c6ff40ac198c5bbf 100644 (file)
@@ -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