Skip to content

Commit 9a39d7e

Browse files
Note predicate span on ImplDerivedObligation
1 parent b22c152 commit 9a39d7e

File tree

52 files changed

+200
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+200
-68
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{
3636
TypeSuperFoldable, TypeVisitable, TypeckResults,
3737
};
3838
use rustc_span::symbol::{sym, Ident, Symbol};
39-
use rustc_span::{BytePos, DesugaringKind, ExpnKind, Span, DUMMY_SP};
39+
use rustc_span::{BytePos, DesugaringKind, ExpnKind, MacroKind, Span, DUMMY_SP};
4040
use rustc_target::spec::abi;
4141
use std::ops::Deref;
4242

@@ -2949,7 +2949,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29492949
// FIXME: we should do something else so that it works even on crate foreign
29502950
// auto traits.
29512951
is_auto_trait = matches!(is_auto, hir::IsAuto::Yes);
2952-
err.span_note(ident.span, &msg)
2952+
err.span_note(ident.span, &msg);
29532953
}
29542954
Some(Node::Item(hir::Item {
29552955
kind: hir::ItemKind::Impl(hir::Impl { of_trait, self_ty, .. }),
@@ -2960,9 +2960,29 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29602960
spans.push(trait_ref.path.span);
29612961
}
29622962
spans.push(self_ty.span);
2963-
err.span_note(spans, &msg)
2963+
let mut spans: MultiSpan = spans.into();
2964+
if matches!(
2965+
self_ty.span.ctxt().outer_expn_data().kind,
2966+
ExpnKind::Macro(MacroKind::Derive, _)
2967+
) || matches!(
2968+
of_trait.as_ref().map(|t| t.path.span.ctxt().outer_expn_data().kind),
2969+
Some(ExpnKind::Macro(MacroKind::Derive, _))
2970+
) {
2971+
spans.push_span_label(
2972+
data.span,
2973+
"unsatisfied trait bound introduced in this `derive` macro",
2974+
);
2975+
} else if !data.span.is_dummy() && !data.span.overlaps(self_ty.span) {
2976+
spans.push_span_label(
2977+
data.span,
2978+
"unsatisfied trait bound introduced here",
2979+
);
2980+
}
2981+
err.span_note(spans, &msg);
2982+
}
2983+
_ => {
2984+
err.note(&msg);
29642985
}
2965-
_ => err.note(&msg),
29662986
};
29672987

29682988
if let Some(file) = file {

tests/ui/associated-types/hr-associated-type-bound-2.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ note: required for `u32` to implement `for<'b> X<'b>`
1010
|
1111
LL | impl X<'_> for u32
1212
| ^^^^^ ^^^
13+
LL | where
14+
LL | for<'b> <Self as X<'b>>::U: Clone,
15+
| ----- unsatisfied trait bound introduced here
1316
= note: 128 redundant requirements hidden
1417
= note: required for `u32` to implement `for<'b> X<'b>`
1518

tests/ui/associated-types/impl-wf-cycle-1.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ note: required for `(T,)` to implement `Grault`
99
|
1010
LL | impl<T: Grault> Grault for (T,)
1111
| ^^^^^^ ^^^^
12+
...
13+
LL | Self::A: Baz,
14+
| --- unsatisfied trait bound introduced here
1215
= note: 1 redundant requirement hidden
1316
= note: required for `(T,)` to implement `Grault`
1417

tests/ui/associated-types/impl-wf-cycle-2.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ note: required for `(T,)` to implement `Grault`
99
|
1010
LL | impl<T: Grault> Grault for (T,)
1111
| ^^^^^^ ^^^^
12+
...
13+
LL | Self::A: Copy,
14+
| ---- unsatisfied trait bound introduced here
1215

1316
error: aborting due to previous error
1417

tests/ui/associated-types/issue-44153.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ note: required for `()` to implement `Visit`
1414
|
1515
LL | impl<'a> Visit for () where
1616
| ^^^^^ ^^
17+
LL | (): Array<Element=&'a ()>,
18+
| -------------- unsatisfied trait bound introduced here
1719

1820
error: aborting due to previous error
1921

tests/ui/associated-types/issue-65774-1.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ note: required for `&mut T` to implement `MyDisplay`
2222
--> $DIR/issue-65774-1.rs:5:24
2323
|
2424
LL | impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }
25-
| ^^^^^^^^^ ^^^^^^^^^
25+
| --------- ^^^^^^^^^ ^^^^^^^^^
26+
| |
27+
| unsatisfied trait bound introduced here
2628
= note: required for the cast from `&mut T` to the object type `dyn MyDisplay`
2729

2830
error: aborting due to 2 previous errors

tests/ui/associated-types/substs-ppaux.normal.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ note: required for `str` to implement `Foo<'_, '_, u8>`
8181
--> $DIR/substs-ppaux.rs:11:17
8282
|
8383
LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
84-
| ^^^^^^^^^^^^^^ ^
84+
| - ^^^^^^^^^^^^^^ ^
85+
| |
86+
| unsatisfied trait bound introduced here
8587

8688
error: aborting due to 5 previous errors
8789

tests/ui/associated-types/substs-ppaux.verbose.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ note: required for `str` to implement `Foo<'_#0r, '_#1r, u8>`
8181
--> $DIR/substs-ppaux.rs:11:17
8282
|
8383
LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
84-
| ^^^^^^^^^^^^^^ ^
84+
| - ^^^^^^^^^^^^^^ ^
85+
| |
86+
| unsatisfied trait bound introduced here
8587

8688
error: aborting due to 5 previous errors
8789

tests/ui/auto-traits/typeck-default-trait-impl-precedence.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ note: required for `&'static u32` to implement `Defaulted`
99
--> $DIR/typeck-default-trait-impl-precedence.rs:10:19
1010
|
1111
LL | impl<'a,T:Signed> Defaulted for &'a T { }
12-
| ^^^^^^^^^ ^^^^^
12+
| ------ ^^^^^^^^^ ^^^^^
13+
| |
14+
| unsatisfied trait bound introduced here
1315
note: required by a bound in `is_defaulted`
1416
--> $DIR/typeck-default-trait-impl-precedence.rs:12:19
1517
|

tests/ui/block-result/issue-22645.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ note: required for `Bob` to implement `Add<{integer}>`
99
--> $DIR/issue-22645.rs:8:19
1010
|
1111
LL | impl<RHS: Scalar> Add <RHS> for Bob {
12-
| ^^^^^^^^^ ^^^
12+
| ------ ^^^^^^^^^ ^^^
13+
| |
14+
| unsatisfied trait bound introduced here
1315

1416
error[E0308]: mismatched types
1517
--> $DIR/issue-22645.rs:15:3

0 commit comments

Comments
 (0)