]> git.lizzy.rs Git - rust.git/commitdiff
Inform the user which trait is meant in the diagnostic itself instead of relying...
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 12 Dec 2022 11:55:46 +0000 (11:55 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 13 Dec 2022 09:48:26 +0000 (09:48 +0000)
15 files changed:
compiler/rustc_hir_typeck/src/method/suggest.rs
src/test/ui/binop/issue-28837.stderr
src/test/ui/binop/issue-3820.stderr
src/test/ui/destructuring-assignment/note-unsupported.stderr
src/test/ui/error-festival.stderr
src/test/ui/impl-trait/issues/issue-62742.stderr
src/test/ui/issues/issue-14091-2.stderr
src/test/ui/methods/method-call-err-msg.stderr
src/test/ui/mismatched_types/assignment-operator-unimplemented.stderr
src/test/ui/or-patterns/or-patterns-syntactic-fail.stderr
src/test/ui/span/issue-39018.stderr
src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr
src/test/ui/suggestions/derive-trait-for-method-call.stderr
src/test/ui/suggestions/restrict-type-not-param.stderr
src/test/ui/type/type-ascription-precedence.stderr

index db93cfab2c0dbd6a45508b9c35607b642cfe6c51..2d3b4663f06ce82f17f272d63bf4a0b86efe282e 100644 (file)
@@ -1853,7 +1853,7 @@ fn suggest_derive(
         )],
     ) {
         let mut derives = Vec::<(String, Span, Symbol)>::new();
-        let mut traits = Vec::<Span>::new();
+        let mut traits = Vec::new();
         for (pred, _, _) in unsatisfied_predicates {
             let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = pred.kind().skip_binder() else { continue };
             let adt = match trait_pred.self_ty().ty_adt_def() {
@@ -1892,10 +1892,10 @@ fn suggest_derive(
                     }
                     derives.push((self_name, self_span, diagnostic_name));
                 } else {
-                    traits.push(self.tcx.def_span(trait_pred.def_id()));
+                    traits.push(trait_pred.def_id());
                 }
             } else {
-                traits.push(self.tcx.def_span(trait_pred.def_id()));
+                traits.push(trait_pred.def_id());
             }
         }
         traits.sort();
@@ -1918,10 +1918,23 @@ fn suggest_derive(
 
         let len = traits.len();
         if len > 0 {
-            let span: MultiSpan = traits.into();
+            let span =
+                MultiSpan::from_spans(traits.iter().map(|&did| self.tcx.def_span(did)).collect());
+            let mut names = format!("`{}`", self.tcx.def_path_str(traits[0]));
+            for (i, &did) in traits.iter().enumerate().skip(1) {
+                if len > 2 {
+                    names.push_str(", ");
+                }
+                if i == len - 1 {
+                    names.push_str(" and ");
+                }
+                names.push('`');
+                names.push_str(&self.tcx.def_path_str(did));
+                names.push('`');
+            }
             err.span_note(
                 span,
-                &format!("the following trait{} must be implemented", pluralize!(len),),
+                &format!("the trait{} {} must be implemented", pluralize!(len), names),
             );
         }
 
index 89355edf74d787ee11d8eb14d497911451d40a8a..6e236ca5296a17eee6b9489dbcb05e4b3a4b32b6 100644 (file)
@@ -11,7 +11,7 @@ note: an implementation of `Add<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Add<_>`
-note: the following trait must be implemented
+note: the trait `Add` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: cannot subtract `A` from `A`
@@ -27,7 +27,7 @@ note: an implementation of `Sub<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Sub<_>`
-note: the following trait must be implemented
+note: the trait `Sub` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: cannot multiply `A` by `A`
@@ -43,7 +43,7 @@ note: an implementation of `Mul<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Mul<_>`
-note: the following trait must be implemented
+note: the trait `Mul` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: cannot divide `A` by `A`
@@ -59,7 +59,7 @@ note: an implementation of `Div<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Div<_>`
-note: the following trait must be implemented
+note: the trait `Div` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: cannot mod `A` by `A`
@@ -75,7 +75,7 @@ note: an implementation of `Rem<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Rem<_>`
-note: the following trait must be implemented
+note: the trait `Rem` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: no implementation for `A & A`
@@ -91,7 +91,7 @@ note: an implementation of `BitAnd<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `BitAnd<_>`
-note: the following trait must be implemented
+note: the trait `BitAnd` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error[E0369]: no implementation for `A | A`
@@ -107,7 +107,7 @@ note: an implementation of `BitOr<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `BitOr<_>`
-note: the following trait must be implemented
+note: the trait `BitOr` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error[E0369]: no implementation for `A << A`
@@ -123,7 +123,7 @@ note: an implementation of `Shl<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Shl<_>`
-note: the following trait must be implemented
+note: the trait `Shl` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error[E0369]: no implementation for `A >> A`
@@ -139,7 +139,7 @@ note: an implementation of `Shr<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^ must implement `Shr<_>`
-note: the following trait must be implemented
+note: the trait `Shr` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error[E0369]: binary operation `==` cannot be applied to type `A`
index 9bf178d1f856c7d29ae07a9e9a9fba0e2dfb0c14..c313ed6037f3ab043aef865989ef6725449c7fb7 100644 (file)
@@ -11,7 +11,7 @@ note: an implementation of `Mul<_>` might be missing for `Thing`
    |
 LL | struct Thing {
    | ^^^^^^^^^^^^ must implement `Mul<_>`
-note: the following trait must be implemented
+note: the trait `Mul` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error: aborting due to previous error
index 3b546115a505cf7df4a85250ff7b5177bfa99cc6..8a88332b73e105f8b06c85c634f8cdeefba70f7e 100644 (file)
@@ -49,7 +49,7 @@ note: an implementation of `AddAssign<_>` might be missing for `S`
    |
 LL | struct S { x: u8, y: u8 }
    | ^^^^^^^^ must implement `AddAssign<_>`
-note: the following trait must be implemented
+note: the trait `AddAssign` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0067]: invalid left-hand side of assignment
index 5ff7ec952c1298b0fa3305eb484bc4d4399e6373..fe9956b70bdd75f3e9cb374adbb589cde91d2e50 100644 (file)
@@ -41,7 +41,7 @@ note: an implementation of `Not` might be missing for `Question`
    |
 LL | enum Question {
    | ^^^^^^^^^^^^^ must implement `Not`
-note: the following trait must be implemented
+note: the trait `Not` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error[E0604]: only `u8` can be cast as `char`, not `u32`
index 34f4dc2cef37dd3348af6f125f195abb12ea746d..bc342dc46893b80e02778235fc7437037bb9d406 100644 (file)
@@ -25,7 +25,7 @@ LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
    |
    = note: the following trait bounds were not satisfied:
            `RawImpl<()>: Raw<()>`
-note: the following trait must be implemented
+note: the trait `Raw` must be implemented
   --> $DIR/issue-62742.rs:12:1
    |
 LL | pub trait Raw<T: ?Sized> {
index 2e164f7c53e2d8ff5f3efe2098ce129e64613bd6..f8375d4ef9014ba6e7dcfe0ca100c93ee114a47d 100644 (file)
@@ -9,7 +9,7 @@ note: an implementation of `Not` might be missing for `BytePos`
    |
 LL | pub struct BytePos(pub u32);
    | ^^^^^^^^^^^^^^^^^^ must implement `Not`
-note: the following trait must be implemented
+note: the trait `Not` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
    = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
 
index 13d07ea2e49f6221a28e52ad5faa2ea440159fde..3f4e647491eb7390efc4ba288ba0a788b0bd2484 100644 (file)
@@ -61,7 +61,7 @@ LL |      .take()
    = note: the following trait bounds were not satisfied:
            `Foo: Iterator`
            which is required by `&mut Foo: Iterator`
-note: the following trait must be implemented
+note: the trait `Iterator` must be implemented
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `take`, perhaps you need to implement it:
index 53937d290774a34e97035526fa592aeffd6aa9a4..2393791a9b2a81106ad423e13de7bb2f245282ff 100644 (file)
@@ -11,7 +11,7 @@ note: an implementation of `AddAssign<_>` might be missing for `Foo`
    |
 LL | struct Foo;
    | ^^^^^^^^^^ must implement `AddAssign<_>`
-note: the following trait must be implemented
+note: the trait `AddAssign` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error: aborting due to previous error
index a65ad0bb7850437ac0f544024054bdc3c85e7fc4..10d42b7e3c0b8de4892a98ee411bb38e709c8198 100644 (file)
@@ -35,7 +35,7 @@ note: an implementation of `BitOr<_>` might be missing for `E`
    |
 LL | enum E { A, B }
    | ^^^^^^ must implement `BitOr<_>`
-note: the following trait must be implemented
+note: the trait `BitOr` must be implemented
   --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
 
 error: aborting due to 5 previous errors
index fd15f2ba9d46e3967d6a8138a4b720c4cd1e228f..5d4d692b2cffb7e5c39ccc0754002018c7ca9ed1 100644 (file)
@@ -26,7 +26,7 @@ note: an implementation of `Add<_>` might be missing for `World`
    |
 LL | enum World {
    | ^^^^^^^^^^ must implement `Add<_>`
-note: the following trait must be implemented
+note: the trait `Add` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0369]: cannot add `String` to `&str`
index 33ca7a2c210d680ec7d7f664fae9aca585c0b029..37788612f4371dd6ce95af228211a59799424d6a 100644 (file)
@@ -27,7 +27,7 @@ LL | default impl<T> Foo for T {
    | ^^^^^^^^^^^^^^^^---^^^^^-
    | |
    | unsatisfied trait bound introduced here
-note: the following trait must be implemented
+note: the trait `Foo` must be implemented
   --> $DIR/specialization-trait-not-implemented.rs:7:1
    |
 LL | trait Foo {
index f07fd54e07c0b0e947a6cce60f5f9961cbdef01e..14e8a2675dd18dca6b2dc57fc4c4a973d1d2ebee 100644 (file)
@@ -20,7 +20,7 @@ LL |     let y = x.test();
            `Enum: Clone`
            `Enum: Default`
            `CloneEnum: Default`
-note: the following trait must be implemented
+note: the trait `Default` must be implemented
   --> $SRC_DIR/core/src/default.rs:LL:COL
 help: consider annotating `Enum` with `#[derive(Clone)]`
    |
index cf31c9ebcc7a1d220911588122139acf16093be3..5434472ceecc7605e3b324553e86d07a6acb0517 100644 (file)
@@ -11,7 +11,7 @@ note: an implementation of `Add<_>` might be missing for `Wrapper<T>`
    |
 LL | struct Wrapper<T>(T);
    | ^^^^^^^^^^^^^^^^^ must implement `Add<_>`
-note: the following trait must be implemented
+note: the trait `Add` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
    |
index ecf5845ca55fe7db84180e45e1d2ff72014fb1e5..edc5aeffdcd65fda4697a7fcc12895bd9ca88f54 100644 (file)
@@ -33,7 +33,7 @@ note: an implementation of `std::ops::Neg` might be missing for `Z`
    |
 LL | struct Z;
    | ^^^^^^^^ must implement `std::ops::Neg`
-note: the following trait must be implemented
+note: the trait `std::ops::Neg` must be implemented
   --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
 
 error[E0308]: mismatched types