about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs78
-rw-r--r--tests/ui/argument-suggestions/issue-100154.stderr6
-rw-r--r--tests/ui/associated-types/associated-types-invalid-trait-ref-issue-18865.stderr4
-rw-r--r--tests/ui/associated-types/associated-types-issue-20346.stderr6
-rw-r--r--tests/ui/const-generics/exhaustive-value.stderr4
-rw-r--r--tests/ui/inference/issue-72690.stderr14
-rw-r--r--tests/ui/issues/issue-29147.stderr4
-rw-r--r--tests/ui/issues/issue-66923-show-error-for-correct-call.stderr6
-rw-r--r--tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr6
-rw-r--r--tests/ui/iterators/invalid-iterator-chain.stderr30
-rw-r--r--tests/ui/methods/issues/issue-61525.stderr4
-rw-r--r--tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr6
-rw-r--r--tests/ui/on-unimplemented/sum.stderr12
-rw-r--r--tests/ui/suggestions/assoc-const-as-fn.stderr6
-rw-r--r--tests/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr6
-rw-r--r--tests/ui/traits/bad-method-typaram-kind.stderr4
-rw-r--r--tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr6
-rw-r--r--tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr6
-rw-r--r--tests/ui/traits/issue-77982.stderr20
-rw-r--r--tests/ui/traits/new-solver/specialization-unconstrained.stderr4
-rw-r--r--tests/ui/traits/reservation-impl/no-use.next.stderr6
-rw-r--r--tests/ui/traits/reservation-impl/no-use.old.stderr6
-rw-r--r--tests/ui/traits/suggest-where-clause.stderr12
-rw-r--r--tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr6
24 files changed, 125 insertions, 137 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
index 5be67a4b14e..2acb43c51da 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
@@ -43,6 +43,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             _ => return false,
         };
 
+        let direct_param = if let ty::ClauseKind::Trait(pred) = unsubstituted_pred.kind().skip_binder()
+            && let ty = pred.trait_ref.self_ty()
+            && let ty::Param(_param) = ty.kind()
+            && let Some(arg) = predicate_args.get(0)
+            && let ty::GenericArgKind::Type(arg_ty) = arg.unpack()
+            && arg_ty == ty
+        {
+            Some(*arg)
+        } else {
+            None
+        };
         let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
             predicate_args.iter().find_map(|arg| {
                 arg.walk().find_map(|arg| {
@@ -63,32 +74,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             })
         };
 
-        // Account for enum variant constructors, where the type param corresponds to the enum
-        // itself.
-        let enum_def_id =
-            if let DefKind::Ctor(hir::def::CtorOf::Variant, _) = self.tcx.def_kind(def_id) {
-                // `def_id` corresponds to a constructor, and its parent is the variant, and we want
-                // the enum.
-                Some(self.tcx.parent(self.tcx.parent(def_id)))
-            } else {
-                None
-            };
-        let variant_param_to_point_at = find_param_matching(&|param_term| {
-            // FIXME: It would be nice to make this not use string manipulation,
-            // but it's pretty hard to do this, since `ty::ParamTy` is missing
-            // sufficient info to determine if it is synthetic, and we don't
-            // always have a convenient way of getting `ty::Generics` at the call
-            // sites we invoke `IsSuggestable::is_suggestable`.
-            let include = match param_term {
-                ty::ParamTerm::Ty(param_ty) => !param_ty.name.as_str().starts_with("impl "),
-                _ => true,
-            };
-            // Account for enum variant constructors, where the type param corresponds to the enum
-            // itself.
-            let def_id = if let Some(def_id) = enum_def_id { def_id } else { def_id };
-            self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) == def_id
-                && include
-        });
         // Prefer generics that are local to the fn item, since these are likely
         // to be the cause of the unsatisfied predicate.
         let mut param_to_point_at = find_param_matching(&|param_term| {
@@ -134,20 +119,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         };
 
         if let Some(qpath) = qpath {
-            let def_id = if let Some(def_id) = enum_def_id { def_id } else { def_id };
-            if let hir::QPath::Resolved(None, path) = qpath {
-                for segment in path.segments {
-                    if let Some(param) = variant_param_to_point_at
-                        && self.point_at_generic_if_possible(error, def_id, param, segment)
-                    {
-                        return true;
-                    }
-                }
-            }
-            if let hir::QPath::TypeRelative(_ty, segment) = qpath {
-                if let Some(param) = variant_param_to_point_at
-                    && self.point_at_generic_if_possible(error, def_id, param, segment)
-                {
+            if let Some(param) = direct_param {
+                if self.point_at_path_if_possible(error, def_id, param, &qpath) {
                     return true;
                 }
             }
@@ -195,6 +168,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
         match expr.map(|e| e.kind) {
             Some(hir::ExprKind::MethodCall(segment, receiver, args, ..)) => {
+                if let Some(param) = direct_param
+                    && self.point_at_generic_if_possible(error, def_id, param, segment)
+                {
+                    error.obligation.cause.map_code(|parent_code| {
+                        ObligationCauseCode::FunctionArgumentObligation {
+                            arg_hir_id: receiver.hir_id,
+                            call_hir_id: hir_id,
+                            parent_code,
+                        }
+                    });
+                    return true;
+                }
                 for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
                     .into_iter()
                     .flatten()
@@ -251,9 +236,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     }
                 }
 
-                for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
-                    .into_iter()
-                    .flatten()
+                for param in [
+                    direct_param,
+                    param_to_point_at,
+                    fallback_param_to_point_at,
+                    self_param_to_point_at,
+                ]
+                .into_iter()
+                .flatten()
                 {
                     if self.point_at_path_if_possible(error, def_id, param, qpath) {
                         return true;
@@ -485,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     }
 
     /**
-     * Recursively searches for the most-specific blamable expression.
+     * Recursively searches for the most-specific blameable expression.
      * For example, if you have a chain of constraints like:
      * - want `Vec<i32>: Copy`
      * - because `Option<Vec<i32>>: Copy` needs `Vec<i32>: Copy` because `impl <T: Copy> Copy for Option<T>`
diff --git a/tests/ui/argument-suggestions/issue-100154.stderr b/tests/ui/argument-suggestions/issue-100154.stderr
index 2504f616fb7..966f56e2a15 100644
--- a/tests/ui/argument-suggestions/issue-100154.stderr
+++ b/tests/ui/argument-suggestions/issue-100154.stderr
@@ -14,12 +14,10 @@ LL | fn foo(i: impl std::fmt::Display) {}
    = note: `impl Trait` cannot be explicitly specified as a generic argument
 
 error[E0277]: `()` doesn't implement `std::fmt::Display`
-  --> $DIR/issue-100154.rs:4:15
+  --> $DIR/issue-100154.rs:4:11
    |
 LL |     foo::<()>(());
-   |     --------- ^^ `()` cannot be formatted with the default formatter
-   |     |
-   |     required by a bound introduced by this call
+   |           ^^ `()` cannot be formatted with the default formatter
    |
    = help: the trait `std::fmt::Display` is not implemented for `()`
    = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
diff --git a/tests/ui/associated-types/associated-types-invalid-trait-ref-issue-18865.stderr b/tests/ui/associated-types/associated-types-invalid-trait-ref-issue-18865.stderr
index 02906e821c5..fc63f4b3e30 100644
--- a/tests/ui/associated-types/associated-types-invalid-trait-ref-issue-18865.stderr
+++ b/tests/ui/associated-types/associated-types-invalid-trait-ref-issue-18865.stderr
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `T: Foo<usize>` is not satisfied
-  --> $DIR/associated-types-invalid-trait-ref-issue-18865.rs:10:22
+  --> $DIR/associated-types-invalid-trait-ref-issue-18865.rs:10:13
    |
 LL |     let u: <T as Foo<usize>>::Bar = t.get_bar();
-   |                      ^^^^^ the trait `Foo<usize>` is not implemented for `T`
+   |             ^ the trait `Foo<usize>` is not implemented for `T`
    |
 help: consider further restricting this bound
    |
diff --git a/tests/ui/associated-types/associated-types-issue-20346.stderr b/tests/ui/associated-types/associated-types-issue-20346.stderr
index d8b0433d3e8..b1708b96e52 100644
--- a/tests/ui/associated-types/associated-types-issue-20346.stderr
+++ b/tests/ui/associated-types/associated-types-issue-20346.stderr
@@ -1,11 +1,13 @@
 error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
-  --> $DIR/associated-types-issue-20346.rs:34:33
+  --> $DIR/associated-types-issue-20346.rs:34:36
    |
 LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
    |                 - this type parameter
 ...
 LL |     is_iterator_of::<Option<T>, _>(&adapter);
-   |                                 ^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
+   |     ------------------------------ ^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
+   |     |
+   |     required by a bound introduced by this call
    |
 note: expected this to be `Option<T>`
   --> $DIR/associated-types-issue-20346.rs:23:17
diff --git a/tests/ui/const-generics/exhaustive-value.stderr b/tests/ui/const-generics/exhaustive-value.stderr
index 0828f7896dc..deb65ddba70 100644
--- a/tests/ui/const-generics/exhaustive-value.stderr
+++ b/tests/ui/const-generics/exhaustive-value.stderr
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `(): Foo<N>` is not satisfied
-  --> $DIR/exhaustive-value.rs:262:16
+  --> $DIR/exhaustive-value.rs:262:6
    |
 LL |     <() as Foo<N>>::test()
-   |                ^ the trait `Foo<N>` is not implemented for `()`
+   |      ^^ the trait `Foo<N>` is not implemented for `()`
    |
    = help: the following other types implement trait `Foo<N>`:
              <() as Foo<0>>
diff --git a/tests/ui/inference/issue-72690.stderr b/tests/ui/inference/issue-72690.stderr
index 8eda71ec09b..9b96e6dd89b 100644
--- a/tests/ui/inference/issue-72690.stderr
+++ b/tests/ui/inference/issue-72690.stderr
@@ -2,7 +2,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:7:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -71,7 +71,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:21:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -97,7 +97,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:28:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -123,7 +123,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:37:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -149,7 +149,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:46:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -175,7 +175,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:53:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
@@ -201,7 +201,7 @@ error[E0283]: type annotations needed
   --> $DIR/issue-72690.rs:62:5
    |
 LL |     String::from("x".as_ref());
-   |     ^^^^^^^^^^^^ cannot infer type for reference `&_`
+   |     ^^^^^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
            - impl<> From<&String> for String;
diff --git a/tests/ui/issues/issue-29147.stderr b/tests/ui/issues/issue-29147.stderr
index 138d477dc6b..d0d9485310b 100644
--- a/tests/ui/issues/issue-29147.stderr
+++ b/tests/ui/issues/issue-29147.stderr
@@ -1,8 +1,8 @@
 error[E0283]: type annotations needed
-  --> $DIR/issue-29147.rs:22:13
+  --> $DIR/issue-29147.rs:22:14
    |
 LL |     let _ = <S5<_>>::xxx;
-   |             ^^^^^^^^^^^^ cannot infer type for struct `S5<_>`
+   |              ^^^^^ cannot infer type for struct `S5<_>`
    |
 note: multiple `impl`s satisfying `S5<_>: Foo` found
   --> $DIR/issue-29147.rs:18:1
diff --git a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr
index cec482a53ba..22b1da64cb3 100644
--- a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr
+++ b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr
@@ -17,10 +17,12 @@ note: required by a bound in `collect`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `Vec<f64>` cannot be built from an iterator over elements of type `&f64`
-  --> $DIR/issue-66923-show-error-for-correct-call.rs:12:29
+  --> $DIR/issue-66923-show-error-for-correct-call.rs:12:39
    |
 LL |     let x3 = x1.into_iter().collect::<Vec<f64>>();
-   |                             ^^^^^^^ value of type `Vec<f64>` cannot be built from `std::iter::Iterator<Item=&f64>`
+   |                             -------   ^^^^^^^^ value of type `Vec<f64>` cannot be built from `std::iter::Iterator<Item=&f64>`
+   |                             |
+   |                             required by a bound introduced by this call
    |
    = help: the trait `FromIterator<&f64>` is not implemented for `Vec<f64>`
    = help: the trait `FromIterator<T>` is implemented for `Vec<T>`
diff --git a/tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr b/tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr
index 7f1b9c38e67..e728fec2910 100644
--- a/tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr
+++ b/tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr
@@ -1,8 +1,10 @@
 error[E0277]: a value of type `f32` cannot be made by summing an iterator over elements of type `{integer}`
-  --> $DIR/invalid-iterator-chain-with-int-infer.rs:2:41
+  --> $DIR/invalid-iterator-chain-with-int-infer.rs:2:47
    |
 LL |     let x = Some(()).iter().map(|()| 1).sum::<f32>();
-   |                                         ^^^ value of type `f32` cannot be made by summing a `std::iter::Iterator<Item={integer}>`
+   |                                         ---   ^^^ value of type `f32` cannot be made by summing a `std::iter::Iterator<Item={integer}>`
+   |                                         |
+   |                                         required by a bound introduced by this call
    |
    = help: the trait `Sum<{integer}>` is not implemented for `f32`
    = help: the following other types implement trait `Sum<A>`:
diff --git a/tests/ui/iterators/invalid-iterator-chain.stderr b/tests/ui/iterators/invalid-iterator-chain.stderr
index a2688107d10..b355da5cb76 100644
--- a/tests/ui/iterators/invalid-iterator-chain.stderr
+++ b/tests/ui/iterators/invalid-iterator-chain.stderr
@@ -17,10 +17,12 @@ note: required by a bound in `collect`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()`
-  --> $DIR/invalid-iterator-chain.rs:15:27
+  --> $DIR/invalid-iterator-chain.rs:15:33
    |
 LL |     println!("{}", scores.sum::<i32>());
-   |                           ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |                           ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |                           |
+   |                           required by a bound introduced by this call
    |
    = help: the trait `Sum<()>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
@@ -42,10 +44,12 @@ note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()`
-  --> $DIR/invalid-iterator-chain.rs:26:14
+  --> $DIR/invalid-iterator-chain.rs:26:20
    |
 LL |             .sum::<i32>(),
-   |              ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |              ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |              |
+   |              required by a bound introduced by this call
    |
    = help: the trait `Sum<()>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
@@ -74,10 +78,12 @@ note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64`
-  --> $DIR/invalid-iterator-chain.rs:36:14
+  --> $DIR/invalid-iterator-chain.rs:36:20
    |
 LL |             .sum::<i32>(),
-   |              ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=f64>`
+   |              ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=f64>`
+   |              |
+   |              required by a bound introduced by this call
    |
    = help: the trait `Sum<f64>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
@@ -102,10 +108,12 @@ note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()`
-  --> $DIR/invalid-iterator-chain.rs:38:54
+  --> $DIR/invalid-iterator-chain.rs:38:60
    |
 LL |     println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
-   |                                                      ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |                                                      ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>`
+   |                                                      |
+   |                                                      required by a bound introduced by this call
    |
    = help: the trait `Sum<()>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
@@ -123,10 +131,12 @@ note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()`
-  --> $DIR/invalid-iterator-chain.rs:39:40
+  --> $DIR/invalid-iterator-chain.rs:39:46
    |
 LL |     println!("{}", vec![(), ()].iter().sum::<i32>());
-   |                                        ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>`
+   |                                        ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>`
+   |                                        |
+   |                                        required by a bound introduced by this call
    |
    = help: the trait `Sum<&()>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
diff --git a/tests/ui/methods/issues/issue-61525.stderr b/tests/ui/methods/issues/issue-61525.stderr
index a8afdeb8401..a329b52e373 100644
--- a/tests/ui/methods/issues/issue-61525.stderr
+++ b/tests/ui/methods/issues/issue-61525.stderr
@@ -1,8 +1,8 @@
 error[E0277]: the size for values of type `dyn ToString` cannot be known at compilation time
-  --> $DIR/issue-61525.rs:14:33
+  --> $DIR/issue-61525.rs:14:19
    |
 LL |         1.query::<dyn ToString>("")
-   |           -----                 ^^ doesn't have a size known at compile-time
+   |           -----   ^^^^^^^^^^^^ doesn't have a size known at compile-time
    |           |
    |           required by a bound introduced by this call
    |
diff --git a/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr b/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
index 06e902bca70..54c16230fe6 100644
--- a/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
+++ b/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
@@ -1,10 +1,8 @@
 error[E0277]: the trait bound `E: From<()>` is not satisfied
-  --> $DIR/never-value-fallback-issue-66757.rs:28:26
+  --> $DIR/never-value-fallback-issue-66757.rs:28:6
    |
 LL |     <E as From<_>>::from(never);
-   |     -------------------- ^^^^^ the trait `From<()>` is not implemented for `E`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^ the trait `From<()>` is not implemented for `E`
    |
    = help: the trait `From<!>` is implemented for `E`
 
diff --git a/tests/ui/on-unimplemented/sum.stderr b/tests/ui/on-unimplemented/sum.stderr
index a2357e49b07..257dec20074 100644
--- a/tests/ui/on-unimplemented/sum.stderr
+++ b/tests/ui/on-unimplemented/sum.stderr
@@ -1,8 +1,10 @@
 error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()`
-  --> $DIR/sum.rs:4:25
+  --> $DIR/sum.rs:4:31
    |
 LL |     vec![(), ()].iter().sum::<i32>();
-   |                         ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>`
+   |                         ---   ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>`
+   |                         |
+   |                         required by a bound introduced by this call
    |
    = help: the trait `Sum<&()>` is not implemented for `i32`
    = help: the following other types implement trait `Sum<A>`:
@@ -19,10 +21,12 @@ note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
 error[E0277]: a value of type `i32` cannot be made by multiplying all elements of type `&()` from an iterator
-  --> $DIR/sum.rs:7:25
+  --> $DIR/sum.rs:7:35
    |
 LL |     vec![(), ()].iter().product::<i32>();
-   |                         ^^^^^^^ value of type `i32` cannot be made by multiplying all elements from a `std::iter::Iterator<Item=&()>`
+   |                         -------   ^^^ value of type `i32` cannot be made by multiplying all elements from a `std::iter::Iterator<Item=&()>`
+   |                         |
+   |                         required by a bound introduced by this call
    |
    = help: the trait `Product<&()>` is not implemented for `i32`
    = help: the following other types implement trait `Product<A>`:
diff --git a/tests/ui/suggestions/assoc-const-as-fn.stderr b/tests/ui/suggestions/assoc-const-as-fn.stderr
index 3b6e947c59f..d55d968b600 100644
--- a/tests/ui/suggestions/assoc-const-as-fn.stderr
+++ b/tests/ui/suggestions/assoc-const-as-fn.stderr
@@ -1,10 +1,8 @@
 error[E0277]: the trait bound `T: GlUniformScalar` is not satisfied
-  --> $DIR/assoc-const-as-fn.rs:14:40
+  --> $DIR/assoc-const-as-fn.rs:14:6
    |
 LL |     <T as GlUniformScalar>::FACTORY(1, value);
-   |     -------------------------------    ^^^^^ the trait `GlUniformScalar` is not implemented for `T`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^ the trait `GlUniformScalar` is not implemented for `T`
    |
 help: consider further restricting this bound
    |
diff --git a/tests/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr b/tests/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr
index 11f94c604a1..fc5a521746a 100644
--- a/tests/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr
+++ b/tests/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr
@@ -1,8 +1,10 @@
 error[E0277]: the trait bound `for<'b> &'b S: Trait` is not satisfied
-  --> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:11
+  --> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:14
    |
 LL |     foo::<S>(s);
-   |           ^ the trait `for<'b> Trait` is not implemented for `&'b S`
+   |     -------- ^ the trait `for<'b> Trait` is not implemented for `&'b S`
+   |     |
+   |     required by a bound introduced by this call
    |
    = help: the trait `Trait` is implemented for `&'a mut S`
    = note: `for<'b> Trait` is implemented for `&'b mut S`, but not for `&'b S`
diff --git a/tests/ui/traits/bad-method-typaram-kind.stderr b/tests/ui/traits/bad-method-typaram-kind.stderr
index 074284cbdd4..bdcfbe79558 100644
--- a/tests/ui/traits/bad-method-typaram-kind.stderr
+++ b/tests/ui/traits/bad-method-typaram-kind.stderr
@@ -2,7 +2,9 @@ error[E0277]: `T` cannot be sent between threads safely
   --> $DIR/bad-method-typaram-kind.rs:2:13
    |
 LL |     1.bar::<T>();
-   |             ^ `T` cannot be sent between threads safely
+   |       ---   ^ `T` cannot be sent between threads safely
+   |       |
+   |       required by a bound introduced by this call
    |
    = note: consider using `std::sync::Arc<T>`; for more information visit <https://doc.rust-lang.org/book/ch16-03-shared-state.html>
 note: required by a bound in `Bar::bar`
diff --git a/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr b/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr
index 934d20b2267..263c59ee327 100644
--- a/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr
+++ b/tests/ui/traits/dont-autoderef-ty-with-escaping-var.stderr
@@ -5,12 +5,10 @@ LL |     <i32 as RefFoo<i32>>::ref_foo(unknown);
    |                                   ^^^^^^^ not found in this scope
 
 error[E0277]: the trait bound `for<'a> &'a mut Vec<&'a u32>: Foo<'static, i32>` is not satisfied
-  --> $DIR/dont-autoderef-ty-with-escaping-var.rs:17:35
+  --> $DIR/dont-autoderef-ty-with-escaping-var.rs:17:6
    |
 LL |     <i32 as RefFoo<i32>>::ref_foo(unknown);
-   |     ----------------------------- ^^^^^^^ the trait `for<'a> Foo<'static, i32>` is not implemented for `&'a mut Vec<&'a u32>`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^^^ the trait `for<'a> Foo<'static, i32>` is not implemented for `&'a mut Vec<&'a u32>`
    |
 note: required for `i32` to implement `RefFoo<i32>`
   --> $DIR/dont-autoderef-ty-with-escaping-var.rs:9:9
diff --git a/tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr b/tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr
index 656e0d0bf26..7027fa69e03 100644
--- a/tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr
+++ b/tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr
@@ -24,12 +24,10 @@ LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
    |                               ++++++++++++++++
 
 error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
-  --> $DIR/repeated-supertrait-ambig.rs:34:37
+  --> $DIR/repeated-supertrait-ambig.rs:34:6
    |
 LL |     <dyn CompareToInts>::same_as(c, 22)
-   |     ----------------------------    ^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
    |
    = help: the following other types implement trait `CompareTo<T>`:
              <i64 as CompareTo<i64>>
diff --git a/tests/ui/traits/issue-77982.stderr b/tests/ui/traits/issue-77982.stderr
index d4fea05fe4b..33cc186ac0b 100644
--- a/tests/ui/traits/issue-77982.stderr
+++ b/tests/ui/traits/issue-77982.stderr
@@ -35,23 +35,12 @@ help: consider specifying the generic argument
 LL |     opts.get::<Q>(opt.as_ref());
    |             +++++
 
-error[E0283]: type annotations needed
+error[E0282]: type annotations needed
   --> $DIR/issue-77982.rs:13:59
    |
 LL |     let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect();
-   |                                            ---------      ^^^^
-   |                                            |
-   |                                            required by a bound introduced by this call
-   |
-   = note: multiple `impl`s satisfying `u32: From<_>` found in the `core` crate:
-           - impl From<Ipv4Addr> for u32;
-           - impl From<NonZeroU32> for u32;
-           - impl From<bool> for u32;
-           - impl From<char> for u32;
-           - impl From<u16> for u32;
-           - impl From<u8> for u32;
-           - impl<T> From<!> for T;
-           - impl<T> From<T> for T;
+   |                                                           ^^^^
+   |
 help: try using a fully qualified path to specify the expected types
    |
 LL |     let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect();
@@ -95,4 +84,5 @@ LL |     let _: Box<T> = (&()).bar();
 
 error: aborting due to 5 previous errors
 
-For more information about this error, try `rustc --explain E0283`.
+Some errors have detailed explanations: E0282, E0283.
+For more information about an error, try `rustc --explain E0282`.
diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.stderr b/tests/ui/traits/new-solver/specialization-unconstrained.stderr
index ff0440d51ad..9915da1a27a 100644
--- a/tests/ui/traits/new-solver/specialization-unconstrained.stderr
+++ b/tests/ui/traits/new-solver/specialization-unconstrained.stderr
@@ -15,10 +15,10 @@ LL |    default type Id = T;
    |                      ^ cannot infer type for associated type `<T as Default>::Id`
 
 error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id == ()`
-  --> $DIR/specialization-unconstrained.rs:20:12
+  --> $DIR/specialization-unconstrained.rs:20:5
    |
 LL |     test::<u32, ()>();
-   |            ^^^ cannot satisfy `<u32 as Default>::Id == ()`
+   |     ^^^^^^^^^^^^^^^ cannot satisfy `<u32 as Default>::Id == ()`
    |
 note: required by a bound in `test`
   --> $DIR/specialization-unconstrained.rs:17:20
diff --git a/tests/ui/traits/reservation-impl/no-use.next.stderr b/tests/ui/traits/reservation-impl/no-use.next.stderr
index 542e3a28adf..632f0f81624 100644
--- a/tests/ui/traits/reservation-impl/no-use.next.stderr
+++ b/tests/ui/traits/reservation-impl/no-use.next.stderr
@@ -1,10 +1,8 @@
 error[E0277]: the trait bound `(): MyTrait` is not satisfied
-  --> $DIR/no-use.rs:11:26
+  --> $DIR/no-use.rs:11:6
    |
 LL |     <() as MyTrait>::foo(&());
-   |     -------------------- ^^^ the trait `MyTrait` is not implemented for `()`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^^ the trait `MyTrait` is not implemented for `()`
    |
    = help: the trait `MyTrait` is implemented for `()`
 
diff --git a/tests/ui/traits/reservation-impl/no-use.old.stderr b/tests/ui/traits/reservation-impl/no-use.old.stderr
index 542e3a28adf..632f0f81624 100644
--- a/tests/ui/traits/reservation-impl/no-use.old.stderr
+++ b/tests/ui/traits/reservation-impl/no-use.old.stderr
@@ -1,10 +1,8 @@
 error[E0277]: the trait bound `(): MyTrait` is not satisfied
-  --> $DIR/no-use.rs:11:26
+  --> $DIR/no-use.rs:11:6
    |
 LL |     <() as MyTrait>::foo(&());
-   |     -------------------- ^^^ the trait `MyTrait` is not implemented for `()`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^^ the trait `MyTrait` is not implemented for `()`
    |
    = help: the trait `MyTrait` is implemented for `()`
 
diff --git a/tests/ui/traits/suggest-where-clause.stderr b/tests/ui/traits/suggest-where-clause.stderr
index 5a539884873..e3bbf768c6e 100644
--- a/tests/ui/traits/suggest-where-clause.stderr
+++ b/tests/ui/traits/suggest-where-clause.stderr
@@ -38,10 +38,10 @@ LL + fn check<T: Iterator, U>() {
    |
 
 error[E0277]: the trait bound `u64: From<T>` is not satisfied
-  --> $DIR/suggest-where-clause.rs:15:18
+  --> $DIR/suggest-where-clause.rs:15:6
    |
 LL |     <u64 as From<T>>::from;
-   |                  ^ the trait `From<T>` is not implemented for `u64`
+   |      ^^^ the trait `From<T>` is not implemented for `u64`
    |
 help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
    |
@@ -49,10 +49,10 @@ LL | fn check<T: Iterator, U: ?Sized>() where u64: From<T> {
    |                                    ++++++++++++++++++
 
 error[E0277]: the trait bound `u64: From<<T as Iterator>::Item>` is not satisfied
-  --> $DIR/suggest-where-clause.rs:18:18
+  --> $DIR/suggest-where-clause.rs:18:6
    |
 LL |     <u64 as From<<T as Iterator>::Item>>::from;
-   |                  ^^^^^^^^^^^^^^^^^^^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `u64`
+   |      ^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `u64`
    |
 help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
    |
@@ -60,10 +60,10 @@ LL | fn check<T: Iterator, U: ?Sized>() where u64: From<<T as Iterator>::Item> {
    |                                    ++++++++++++++++++++++++++++++++++++++
 
 error[E0277]: the trait bound `Misc<_>: From<T>` is not satisfied
-  --> $DIR/suggest-where-clause.rs:23:22
+  --> $DIR/suggest-where-clause.rs:23:6
    |
 LL |     <Misc<_> as From<T>>::from;
-   |                      ^ the trait `From<T>` is not implemented for `Misc<_>`
+   |      ^^^^^^^ the trait `From<T>` is not implemented for `Misc<_>`
 
 error[E0277]: the size for values of type `[T]` cannot be known at compilation time
   --> $DIR/suggest-where-clause.rs:28:20
diff --git a/tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr b/tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr
index 85adf775139..ae0a06e6328 100644
--- a/tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr
+++ b/tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr
@@ -1,10 +1,8 @@
 error[E0277]: cannot add `u32` to `i32`
-  --> $DIR/ufcs-qpath-self-mismatch.rs:4:31
+  --> $DIR/ufcs-qpath-self-mismatch.rs:4:6
    |
 LL |     <i32 as Add<u32>>::add(1, 2);
-   |     ----------------------    ^ no implementation for `i32 + u32`
-   |     |
-   |     required by a bound introduced by this call
+   |      ^^^ no implementation for `i32 + u32`
    |
    = help: the trait `Add<u32>` is not implemented for `i32`
    = help: the following other types implement trait `Add<Rhs>`: