about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeSeulArtichaut <leseulartichaut@gmail.com>2020-02-16 21:42:37 +0100
committerLeSeulArtichaut <leseulartichaut@gmail.com>2020-02-17 15:21:36 +0100
commit2e07892c7dd71f2025b68dcf8c144d53b3560511 (patch)
treed8a214513730b39e71f5eeb0ecaf275301b1ae7c
parent75b98fbe77d472d85d1691bae5b25e7eefb3609c (diff)
downloadrust-2e07892c7dd71f2025b68dcf8c144d53b3560511.tar.gz
rust-2e07892c7dd71f2025b68dcf8c144d53b3560511.zip
Do not emit note suggesting to implement trait to foreign type
Update tests

Extend to other operations

Refractor check in a separate function

Fix more tests
-rw-r--r--src/librustc_typeck/check/op.rs33
-rw-r--r--src/test/ui/autoderef-full-lval.stderr4
-rw-r--r--src/test/ui/binop/binop-bitxor-str.stderr2
-rw-r--r--src/test/ui/binop/binop-mul-bool.stderr2
-rw-r--r--src/test/ui/binop/binop-typeck.stderr2
-rw-r--r--src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr4
-rw-r--r--src/test/ui/destructuring-assignment/note-unsupported.stderr4
-rw-r--r--src/test/ui/error-codes/E0067.stderr2
-rw-r--r--src/test/ui/error-festival.stderr2
-rw-r--r--src/test/ui/for/for-loop-type-error.stderr2
-rw-r--r--src/test/ui/issues/issue-14915.stderr2
-rw-r--r--src/test/ui/issues/issue-24363.stderr2
-rw-r--r--src/test/ui/issues/issue-31076.stderr4
-rw-r--r--src/test/ui/issues/issue-35668.stderr2
-rw-r--r--src/test/ui/issues/issue-40610.stderr2
-rw-r--r--src/test/ui/issues/issue-41394.stderr2
-rw-r--r--src/test/ui/issues/issue-59488.stderr3
-rw-r--r--src/test/ui/minus-string.stderr2
-rw-r--r--src/test/ui/pattern/pattern-tyvar-2.stderr2
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr6
-rw-r--r--src/test/ui/span/issue-39018.stderr4
-rw-r--r--src/test/ui/traits/trait-resolution-in-overloaded-op.stderr2
-rw-r--r--src/test/ui/unop-neg-bool.stderr2
-rw-r--r--src/test/ui/vec/vec-res-add.stderr2
24 files changed, 17 insertions, 77 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs
index 86b00c2f0d3..bb31e979b73 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 e2870ef8062..f094388794e 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<isize>
    |                    |
    |                    std::boxed::Box<isize>
-   |
-   = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
 
 error[E0369]: cannot add `std::boxed::Box<isize>` to `std::boxed::Box<isize>`
   --> $DIR/autoderef-full-lval.rs:21:33
@@ -15,8 +13,6 @@ LL |     let answer: isize = forty.a + two.a;
    |                         ------- ^ ----- std::boxed::Box<isize>
    |                         |
    |                         std::boxed::Box<isize>
-   |
-   = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
 
 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 9a0d301d863..18c1ce0ff02 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 ade22025589..859c44a859e 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 ebf82079ef2..42d91081999 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 781a179624e..c03377d74e9 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 a6805c32a6e..d4e25930d22 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 526503798b3..fad8270fd5a 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 9b69b373364..fb5290bf64e 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 0ed26384f40..c93a3b9b25c 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 00b9909af59..3c34a8a3467 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<isize>
-   |
-   = note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
 
 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 a60fb24ec12..16537e21ae0 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 5d65734cd23..4c0e1cf7ebb 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 9d5796a5eef..98e8e6366b9 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 95f45c168e1..b4e302dfffc 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 3f60ea4bbf7..47a24547d45 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 2ac5577e0a0..58f1376b19d 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 9177082cf0b..3fbec7c89c9 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 bb3e61017d4..95662444640 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<isize>
-   |
-   = note: an implementation of `std::ops::Mul` might be missing for `std::vec::Vec<isize>`
 
 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 084f070989b..39874a6c680 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 8a32561bd01..8caa5bea4ac 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 8d7ba36c665..29216f36f5f 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 18273013749..9913747b88e 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 1cc12a222e5..2d41583268c 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<R>
    |             |
    |             std::vec::Vec<R>
-   |
-   = note: an implementation of `std::ops::Add` might be missing for `std::vec::Vec<R>`
 
 error: aborting due to previous error