diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 86b00c2f0d3f0..bb31e979b733f 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -5,7 +5,7 @@ use super::{FnCtxt, Needs}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; use rustc::ty::{self, Ty, TypeFoldable}; -use rustc_errors::{self, struct_span_err, Applicability}; +use rustc_errors::{self, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_span::Span; @@ -321,11 +321,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lhs_ty, missing_trait )); } else if !suggested_deref { - err.note(&format!( - "an implementation of `{}` might \ - be missing for `{}`", - missing_trait, lhs_ty - )); + suggest_impl_missing(&mut err, lhs_ty, &missing_trait); } } err.emit(); @@ -467,11 +463,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lhs_ty, missing_trait )); } else if !suggested_deref && !involves_fn { - err.note(&format!( - "an implementation of `{}` might \ - be missing for `{}`", - missing_trait, lhs_ty - )); + suggest_impl_missing(&mut err, lhs_ty, &missing_trait); } } err.emit(); @@ -707,11 +699,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::UnOp::UnNot => "std::ops::Not", hir::UnOp::UnDeref => "std::ops::UnDerf", }; - err.note(&format!( - "an implementation of `{}` might \ - be missing for `{}`", - missing_trait, operand_ty - )); + suggest_impl_missing(&mut err, operand_ty, &missing_trait); } } err.emit(); @@ -929,3 +917,16 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool } } } + +/// If applicable, note that an implementation of `trait` for `ty` may fix the error. +fn suggest_impl_missing(err: &mut DiagnosticBuilder<'_>, ty: Ty<'_>, missing_trait: &str) { + if let Adt(def, _) = ty.peel_refs().kind { + if def.did.is_local() { + err.note(&format!( + "an implementation of `{}` might \ + be missing for `{}`", + missing_trait, ty + )); + } + } +} diff --git a/src/test/ui/autoderef-full-lval.stderr b/src/test/ui/autoderef-full-lval.stderr index e2870ef8062d3..f094388794eda 100644 --- a/src/test/ui/autoderef-full-lval.stderr +++ b/src/test/ui/autoderef-full-lval.stderr @@ -5,8 +5,6 @@ LL | let z: isize = a.x + b.y; | --- ^ --- std::boxed::Box | | | std::boxed::Box - | - = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box` error[E0369]: cannot add `std::boxed::Box` to `std::boxed::Box` --> $DIR/autoderef-full-lval.rs:21:33 @@ -15,8 +13,6 @@ LL | let answer: isize = forty.a + two.a; | ------- ^ ----- std::boxed::Box | | | std::boxed::Box - | - = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box` error: aborting due to 2 previous errors diff --git a/src/test/ui/binop/binop-bitxor-str.stderr b/src/test/ui/binop/binop-bitxor-str.stderr index 9a0d301d86356..18c1ce0ff02e1 100644 --- a/src/test/ui/binop/binop-bitxor-str.stderr +++ b/src/test/ui/binop/binop-bitxor-str.stderr @@ -5,8 +5,6 @@ LL | fn main() { let x = "a".to_string() ^ "b".to_string(); } | --------------- ^ --------------- std::string::String | | | std::string::String - | - = note: an implementation of `std::ops::BitXor` might be missing for `std::string::String` error: aborting due to previous error diff --git a/src/test/ui/binop/binop-mul-bool.stderr b/src/test/ui/binop/binop-mul-bool.stderr index ade2202558934..859c44a859e85 100644 --- a/src/test/ui/binop/binop-mul-bool.stderr +++ b/src/test/ui/binop/binop-mul-bool.stderr @@ -5,8 +5,6 @@ LL | fn main() { let x = true * false; } | ---- ^ ----- bool | | | bool - | - = note: an implementation of `std::ops::Mul` might be missing for `bool` error: aborting due to previous error diff --git a/src/test/ui/binop/binop-typeck.stderr b/src/test/ui/binop/binop-typeck.stderr index ebf82079ef2e8..42d910819995a 100644 --- a/src/test/ui/binop/binop-typeck.stderr +++ b/src/test/ui/binop/binop-typeck.stderr @@ -5,8 +5,6 @@ LL | let z = x + y; | - ^ - {integer} | | | bool - | - = note: an implementation of `std::ops::Add` might be missing for `bool` error: aborting due to previous error diff --git a/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr b/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr index 781a179624e77..c03377d74e9b7 100644 --- a/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr +++ b/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr @@ -23,8 +23,6 @@ LL | [0_usize; 33] == [1_usize; 33] | ------------- ^^ ------------- [usize; 33] | | | [usize; 33] - | - = note: an implementation of `std::cmp::PartialEq` might be missing for `[usize; 33]` error[E0369]: binary operation `<` cannot be applied to type `[usize; 33]` --> $DIR/core-traits-no-impls-length-33.rs:19:19 @@ -33,8 +31,6 @@ LL | [0_usize; 33] < [1_usize; 33] | ------------- ^ ------------- [usize; 33] | | | [usize; 33] - | - = note: an implementation of `std::cmp::PartialOrd` might be missing for `[usize; 33]` error[E0277]: the trait bound `&[usize; 33]: std::iter::IntoIterator` is not satisfied --> $DIR/core-traits-no-impls-length-33.rs:24:14 diff --git a/src/test/ui/destructuring-assignment/note-unsupported.stderr b/src/test/ui/destructuring-assignment/note-unsupported.stderr index a6805c32a6e52..d4e25930d22d7 100644 --- a/src/test/ui/destructuring-assignment/note-unsupported.stderr +++ b/src/test/ui/destructuring-assignment/note-unsupported.stderr @@ -16,8 +16,6 @@ LL | (a, b) += (3, 4); | ------^^^^^^^^^^ | | | cannot use `+=` on type `({integer}, {integer})` - | - = note: an implementation of `std::ops::AddAssign` might be missing for `({integer}, {integer})` error[E0067]: invalid left-hand side of assignment --> $DIR/note-unsupported.rs:7:12 @@ -48,8 +46,6 @@ LL | [a, b] += [3, 4]; | ------^^^^^^^^^^ | | | cannot use `+=` on type `[{integer}; 2]` - | - = note: an implementation of `std::ops::AddAssign` might be missing for `[{integer}; 2]` error[E0067]: invalid left-hand side of assignment --> $DIR/note-unsupported.rs:11:12 diff --git a/src/test/ui/error-codes/E0067.stderr b/src/test/ui/error-codes/E0067.stderr index 526503798b3d4..fad8270fd5ad2 100644 --- a/src/test/ui/error-codes/E0067.stderr +++ b/src/test/ui/error-codes/E0067.stderr @@ -5,8 +5,6 @@ LL | LinkedList::new() += 1; | -----------------^^^^^ | | | cannot use `+=` on type `std::collections::LinkedList<_>` - | - = note: an implementation of `std::ops::AddAssign` might be missing for `std::collections::LinkedList<_>` error[E0067]: invalid left-hand side of assignment --> $DIR/E0067.rs:4:23 diff --git a/src/test/ui/error-festival.stderr b/src/test/ui/error-festival.stderr index 9b69b3733642b..fb5290bf64eb4 100644 --- a/src/test/ui/error-festival.stderr +++ b/src/test/ui/error-festival.stderr @@ -23,8 +23,6 @@ LL | x += 2; | -^^^^^ | | | cannot use `+=` on type `&str` - | - = note: an implementation of `std::ops::AddAssign` might be missing for `&str` error[E0599]: no method named `z` found for reference `&str` in the current scope --> $DIR/error-festival.rs:16:7 diff --git a/src/test/ui/for/for-loop-type-error.stderr b/src/test/ui/for/for-loop-type-error.stderr index 0ed26384f4064..c93a3b9b25c15 100644 --- a/src/test/ui/for/for-loop-type-error.stderr +++ b/src/test/ui/for/for-loop-type-error.stderr @@ -5,8 +5,6 @@ LL | let x = () + (); | -- ^ -- () | | | () - | - = note: an implementation of `std::ops::Add` might be missing for `()` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-14915.stderr b/src/test/ui/issues/issue-14915.stderr index 00b9909af5979..3c34a8a34673e 100644 --- a/src/test/ui/issues/issue-14915.stderr +++ b/src/test/ui/issues/issue-14915.stderr @@ -5,8 +5,6 @@ LL | println!("{}", x + 1); | - ^ - {integer} | | | std::boxed::Box - | - = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-24363.stderr b/src/test/ui/issues/issue-24363.stderr index a60fb24ec1209..16537e21ae08c 100644 --- a/src/test/ui/issues/issue-24363.stderr +++ b/src/test/ui/issues/issue-24363.stderr @@ -11,8 +11,6 @@ LL | ()+() | --^-- () | | | () - | - = note: an implementation of `std::ops::Add` might be missing for `()` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-31076.stderr b/src/test/ui/issues/issue-31076.stderr index 5d65734cd230a..4c0e1cf7ebb0b 100644 --- a/src/test/ui/issues/issue-31076.stderr +++ b/src/test/ui/issues/issue-31076.stderr @@ -5,8 +5,6 @@ LL | let x = 5 + 6; | - ^ - {integer} | | | {integer} - | - = note: an implementation of `std::ops::Add` might be missing for `{integer}` error[E0369]: cannot add `i32` to `i32` --> $DIR/issue-31076.rs:15:18 @@ -15,8 +13,6 @@ LL | let y = 5i32 + 6i32; | ---- ^ ---- i32 | | | i32 - | - = note: an implementation of `std::ops::Add` might be missing for `i32` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-35668.stderr b/src/test/ui/issues/issue-35668.stderr index 9d5796a5eefed..98e8e6366b99b 100644 --- a/src/test/ui/issues/issue-35668.stderr +++ b/src/test/ui/issues/issue-35668.stderr @@ -5,8 +5,6 @@ LL | a.iter().map(|a| a*a) | -^- &T | | | &T - | - = note: an implementation of `std::ops::Mul` might be missing for `&T` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-40610.stderr b/src/test/ui/issues/issue-40610.stderr index 95f45c168e122..b4e302dfffc7a 100644 --- a/src/test/ui/issues/issue-40610.stderr +++ b/src/test/ui/issues/issue-40610.stderr @@ -5,8 +5,6 @@ LL | () + f(&[1.0]); | -- ^ --------- () | | | () - | - = note: an implementation of `std::ops::Add` might be missing for `()` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-41394.stderr b/src/test/ui/issues/issue-41394.stderr index 3f60ea4bbf73a..47a24547d4533 100644 --- a/src/test/ui/issues/issue-41394.stderr +++ b/src/test/ui/issues/issue-41394.stderr @@ -5,8 +5,6 @@ LL | A = "" + 1 | -- ^ - {integer} | | | &str - | - = note: an implementation of `std::ops::Add` might be missing for `&str` error[E0080]: evaluation of constant value failed --> $DIR/issue-41394.rs:7:9 diff --git a/src/test/ui/issues/issue-59488.stderr b/src/test/ui/issues/issue-59488.stderr index 2ac5577e0a0ec..58f1376b19ddf 100644 --- a/src/test/ui/issues/issue-59488.stderr +++ b/src/test/ui/issues/issue-59488.stderr @@ -58,8 +58,6 @@ LL | foo > bar; | --- ^ --- fn(i64) -> i64 {bar} | | | fn() -> i32 {foo} - | - = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}` error[E0308]: mismatched types --> $DIR/issue-59488.rs:25:11 @@ -79,7 +77,6 @@ LL | assert_eq!(Foo::Bar, i); | fn(usize) -> Foo {Foo::Bar} | fn(usize) -> Foo {Foo::Bar} | - = note: an implementation of `std::cmp::PartialEq` might be missing for `fn(usize) -> Foo {Foo::Bar}` = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug` diff --git a/src/test/ui/minus-string.stderr b/src/test/ui/minus-string.stderr index 9177082cf0b7d..3fbec7c89c9a2 100644 --- a/src/test/ui/minus-string.stderr +++ b/src/test/ui/minus-string.stderr @@ -3,8 +3,6 @@ error[E0600]: cannot apply unary operator `-` to type `std::string::String` | LL | fn main() { -"foo".to_string(); } | ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-` - | - = note: an implementation of `std::ops::Neg` might be missing for `std::string::String` error: aborting due to previous error diff --git a/src/test/ui/pattern/pattern-tyvar-2.stderr b/src/test/ui/pattern/pattern-tyvar-2.stderr index bb3e61017d487..9566244464081 100644 --- a/src/test/ui/pattern/pattern-tyvar-2.stderr +++ b/src/test/ui/pattern/pattern-tyvar-2.stderr @@ -5,8 +5,6 @@ LL | fn foo(t: Bar) -> isize { match t { Bar::T1(_, Some(x)) => { return x * 3; | - ^ - {integer} | | | std::vec::Vec - | - = note: an implementation of `std::ops::Mul` might be missing for `std::vec::Vec` error: aborting due to previous error diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr index 084f070989b6c..39874a6c680cd 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -560,8 +560,6 @@ error[E0600]: cannot apply unary operator `-` to type `bool` | LL | if -let 0 = 0 {} | ^^^^^^^^^^ cannot apply unary operator `-` - | - = note: an implementation of `std::ops::Neg` might be missing for `bool` error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` --> $DIR/disallowed-positions.rs:46:8 @@ -748,8 +746,6 @@ error[E0600]: cannot apply unary operator `-` to type `bool` | LL | while -let 0 = 0 {} | ^^^^^^^^^^ cannot apply unary operator `-` - | - = note: an implementation of `std::ops::Neg` might be missing for `bool` error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` --> $DIR/disallowed-positions.rs:110:11 @@ -927,8 +923,6 @@ error[E0600]: cannot apply unary operator `-` to type `bool` | LL | -let 0 = 0; | ^^^^^^^^^^ cannot apply unary operator `-` - | - = note: an implementation of `std::ops::Neg` might be missing for `bool` error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` --> $DIR/disallowed-positions.rs:183:5 diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr index 8a32561bd01db..8caa5bea4ac1e 100644 --- a/src/test/ui/span/issue-39018.stderr +++ b/src/test/ui/span/issue-39018.stderr @@ -136,8 +136,6 @@ LL | let _ = &c + &d; | -- ^ -- &&str | | | &&str - | - = note: an implementation of `std::ops::Add` might be missing for `&&str` error[E0369]: cannot add `&str` to `&&str` --> $DIR/issue-39018.rs:35:16 @@ -146,8 +144,6 @@ LL | let _ = &c + d; | -- ^ - &str | | | &&str - | - = note: an implementation of `std::ops::Add` might be missing for `&&str` error[E0369]: cannot add `&&str` to `&str` --> $DIR/issue-39018.rs:36:15 diff --git a/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr b/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr index 8d7ba36c665b3..29216f36f5f31 100644 --- a/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr +++ b/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr @@ -5,8 +5,6 @@ LL | a * b | - ^ - f64 | | | &T - | - = note: an implementation of `std::ops::Mul` might be missing for `&T` error: aborting due to previous error diff --git a/src/test/ui/unop-neg-bool.stderr b/src/test/ui/unop-neg-bool.stderr index 182730137492b..9913747b88ee9 100644 --- a/src/test/ui/unop-neg-bool.stderr +++ b/src/test/ui/unop-neg-bool.stderr @@ -3,8 +3,6 @@ error[E0600]: cannot apply unary operator `-` to type `bool` | LL | -true; | ^^^^^ cannot apply unary operator `-` - | - = note: an implementation of `std::ops::Neg` might be missing for `bool` error: aborting due to previous error diff --git a/src/test/ui/vec/vec-res-add.stderr b/src/test/ui/vec/vec-res-add.stderr index 1cc12a222e50b..2d41583268c4e 100644 --- a/src/test/ui/vec/vec-res-add.stderr +++ b/src/test/ui/vec/vec-res-add.stderr @@ -5,8 +5,6 @@ LL | let k = i + j; | - ^ - std::vec::Vec | | | std::vec::Vec - | - = note: an implementation of `std::ops::Add` might be missing for `std::vec::Vec` error: aborting due to previous error