diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 7db1d5f4e8a..c1f901af6fb 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2312,14 +2312,17 @@ fn note_obligation_cause_code( _ => self.tcx.typeck(parent_id), }; let ty = typeck_results.expr_ty_adjusted(expr); - err.span_label( - expr.peel_blocks().span, - &if ty.references_error() { - String::new() - } else { - format!("this tail expression is of type `{:?}`", ty) - }, - ); + let span = expr.peel_blocks().span; + if Some(span) != err.span.primary_span() { + err.span_label( + span, + &if ty.references_error() { + String::new() + } else { + format!("this tail expression is of type `{:?}`", ty) + }, + ); + } } if let Some(Node::Expr(hir::Expr { kind: @@ -2328,7 +2331,9 @@ fn note_obligation_cause_code( .. })) = hir.find(call_hir_id) { - err.span_label(*span, "required by a bound introduced by this call"); + if Some(*span) != err.span.primary_span() { + err.span_label(*span, "required by a bound introduced by this call"); + } } ensure_sufficient_stack(|| { self.note_obligation_cause_code( diff --git a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr index f686aa9d0e2..c5bc50e407b 100644 --- a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr @@ -5,10 +5,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion ... LL | x: Error - | ^^^^^^^^ - | | - | the trait `Clone` is not implemented for `Error` - | required by a bound introduced by this call + | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | note: required by `clone` --> $SRC_DIR/core/src/clone.rs:LL:COL diff --git a/src/test/ui/derives/derives-span-Clone-enum.stderr b/src/test/ui/derives/derives-span-Clone-enum.stderr index 21d5c62bffc..a6dc818eb6f 100644 --- a/src/test/ui/derives/derives-span-Clone-enum.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum.stderr @@ -5,10 +5,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion ... LL | Error - | ^^^^^ - | | - | the trait `Clone` is not implemented for `Error` - | required by a bound introduced by this call + | ^^^^^ the trait `Clone` is not implemented for `Error` | note: required by `clone` --> $SRC_DIR/core/src/clone.rs:LL:COL diff --git a/src/test/ui/derives/derives-span-Clone-struct.stderr b/src/test/ui/derives/derives-span-Clone-struct.stderr index c462244f0d7..cf7b9ec276e 100644 --- a/src/test/ui/derives/derives-span-Clone-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-struct.stderr @@ -5,10 +5,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion LL | struct Struct { LL | x: Error - | ^^^^^^^^ - | | - | the trait `Clone` is not implemented for `Error` - | required by a bound introduced by this call + | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | note: required by `clone` --> $SRC_DIR/core/src/clone.rs:LL:COL diff --git a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr index 7c117c425aa..80733d62730 100644 --- a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr @@ -5,10 +5,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion LL | struct Struct( LL | Error - | ^^^^^ - | | - | the trait `Clone` is not implemented for `Error` - | required by a bound introduced by this call + | ^^^^^ the trait `Clone` is not implemented for `Error` | note: required by `clone` --> $SRC_DIR/core/src/clone.rs:LL:COL diff --git a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr index 730dc1ad680..b97f87da4bf 100644 --- a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr +++ b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr @@ -29,10 +29,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion LL | struct C { LL | x: NoCloneOrEq - | ^^^^^^^^^^^^^^ - | | - | the trait `Clone` is not implemented for `NoCloneOrEq` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq` | note: required by `clone` --> $SRC_DIR/core/src/clone.rs:LL:COL diff --git a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr index 605b678bd23..f8eaf61d7d7 100644 --- a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr +++ b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr @@ -6,10 +6,7 @@ LL | #[test] LL | / fn can_parse_zero_as_f32() -> Result { LL | | "0".parse() LL | | } - | | ^ - | | | - | |_`main` can only return types that implement `Termination` - | required by a bound introduced by this call + | |_^ `main` can only return types that implement `Termination` | = help: the trait `Termination` is not implemented for `Result` note: required by a bound in `assert_test_result` diff --git a/src/test/ui/traits/issue-71136.stderr b/src/test/ui/traits/issue-71136.stderr index 77feff30911..23b78d023b6 100644 --- a/src/test/ui/traits/issue-71136.stderr +++ b/src/test/ui/traits/issue-71136.stderr @@ -5,10 +5,7 @@ LL | #[derive(Clone)] | ----- in this derive macro expansion LL | struct FooHolster { LL | the_foos: Vec, - | ^^^^^^^^^^^^^^^^^^ - | | - | expected an implementor of trait `Clone` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone` | = note: required because of the requirements on the impl of `Clone` for `Vec` note: required by `clone`