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

+24-4
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

+3
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

+3
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

+3
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

+2
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

+3-1
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

+3-1
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

+3-1
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

+3-1
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

+3-1
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

tests/ui/const-generics/generic_const_exprs/issue-85848.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ note: required for `&C` to implement `Contains<(), true>`
1111
--> $DIR/issue-85848.rs:21:12
1212
|
1313
LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {}
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ ------------ unsatisfied trait bound introduced here
1515
note: required for `&C` to implement `Delegates<()>`
1616
--> $DIR/issue-85848.rs:12:12
1717
|
1818
LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {}
19-
| ^^^^^^^^^^^^ ^
19+
| ^^^^^^^^^^^^ ^ ----------------- unsatisfied trait bound introduced here
2020
note: required by a bound in `writes_to_specific_path`
2121
--> $DIR/issue-85848.rs:30:31
2222
|
@@ -36,12 +36,14 @@ note: required for `&C` to implement `Contains<(), true>`
3636
--> $DIR/issue-85848.rs:21:12
3737
|
3838
LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {}
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
39+
| ^^^^^^^^^^^^----------------------^ ^
40+
| |
41+
| unsatisfied trait bound introduced here
4042
note: required for `&C` to implement `Delegates<()>`
4143
--> $DIR/issue-85848.rs:12:12
4244
|
4345
LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {}
44-
| ^^^^^^^^^^^^ ^
46+
| ^^^^^^^^^^^^ ^ ----------------- unsatisfied trait bound introduced here
4547
note: required by a bound in `writes_to_specific_path`
4648
--> $DIR/issue-85848.rs:30:31
4749
|

tests/ui/consts/const-blocks/trait-error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: required for `Foo<String>` to implement `Copy`
88
--> $DIR/trait-error.rs:1:10
99
|
1010
LL | #[derive(Copy, Clone)]
11-
| ^^^^
11+
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
1212
= note: the `Copy` trait is required because this value will be copied for each element of the array
1313
= help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];`
1414
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information

tests/ui/derives/deriving-copyclone.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: required for `B<C>` to implement `Copy`
1010
--> $DIR/deriving-copyclone.rs:9:10
1111
|
1212
LL | #[derive(Copy, Clone)]
13-
| ^^^^
13+
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
1414
note: required by a bound in `is_copy`
1515
--> $DIR/deriving-copyclone.rs:18:15
1616
|
@@ -34,7 +34,7 @@ note: required for `B<C>` to implement `Clone`
3434
--> $DIR/deriving-copyclone.rs:9:16
3535
|
3636
LL | #[derive(Copy, Clone)]
37-
| ^^^^^
37+
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
3838
note: required by a bound in `is_clone`
3939
--> $DIR/deriving-copyclone.rs:19:16
4040
|
@@ -58,7 +58,7 @@ note: required for `B<D>` to implement `Copy`
5858
--> $DIR/deriving-copyclone.rs:9:10
5959
|
6060
LL | #[derive(Copy, Clone)]
61-
| ^^^^
61+
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
6262
note: required by a bound in `is_copy`
6363
--> $DIR/deriving-copyclone.rs:18:15
6464
|

tests/ui/error-codes/E0275.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: required for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<
99
--> $DIR/E0275.rs:6:9
1010
|
1111
LL | impl<T> Foo for T where Bar<T>: Foo {}
12-
| ^^^ ^
12+
| ^^^ ^ --- unsatisfied trait bound introduced here
1313
= note: the full type name has been written to '$TEST_BUILD_DIR/error-codes/E0275/E0275.long-type-hash.txt'
1414
= note: 127 redundant requirements hidden
1515
= note: required for `Bar<T>` to implement `Foo`

tests/ui/generic-associated-types/impl_bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ note: required for `Fooy<T>` to implement `Copy`
3131
--> $DIR/impl_bounds.rs:10:10
3232
|
3333
LL | #[derive(Copy, Clone)]
34-
| ^^^^
34+
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
3535
note: the requirement `Fooy<T>: Copy` appears on the `impl`'s associated type `C` but not on the corresponding trait's associated type
3636
--> $DIR/impl_bounds.rs:6:10
3737
|
@@ -56,7 +56,7 @@ note: required for `Fooy<T>` to implement `Copy`
5656
--> $DIR/impl_bounds.rs:10:10
5757
|
5858
LL | #[derive(Copy, Clone)]
59-
| ^^^^
59+
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
6060
note: the requirement `Fooy<T>: Copy` appears on the `impl`'s method `d` but not on the corresponding trait's method
6161
--> $DIR/impl_bounds.rs:7:8
6262
|

tests/ui/generic-associated-types/issue-101020.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: required for `&'a mut ()` to implement `for<'a> FuncInput<'a, &'a mut ()>`
88
--> $DIR/issue-101020.rs:27:20
99
|
1010
LL | impl<'a, T, F: 'a> FuncInput<'a, F> for T where F: Foo<T> {}
11-
| ^^^^^^^^^^^^^^^^ ^
11+
| ^^^^^^^^^^^^^^^^ ^ ------ unsatisfied trait bound introduced here
1212
note: required by a bound in `LendingIterator::consume`
1313
--> $DIR/issue-101020.rs:9:33
1414
|

tests/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ note: required for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]>` to i
4949
|
5050
LL | impl<'a, A, T> T0<'a, A> for L<T>
5151
| ^^^^^^^^^ ^^^^
52+
LL | where
53+
LL | T: FnMut(A) -> Unit3,
54+
| ----- unsatisfied trait bound introduced here
5255
note: required by a bound in `T1::m`
5356
--> $DIR/issue-62203-hrtb-ice.rs:27:12
5457
|

tests/ui/higher-rank-trait-bounds/normalize-under-binder/issue-89118.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>
88
--> $DIR/issue-89118.rs:5:23
99
|
1010
LL | impl<B: BufferMut, C> BufferUdpStateContext<B> for C {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^
11+
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^ ^
12+
| |
13+
| unsatisfied trait bound introduced here
1214
note: required by a bound in `StackContext`
1315
--> $DIR/issue-89118.rs:9:14
1416
|
@@ -28,7 +30,9 @@ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>
2830
--> $DIR/issue-89118.rs:5:23
2931
|
3032
LL | impl<B: BufferMut, C> BufferUdpStateContext<B> for C {}
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^
33+
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^ ^
34+
| |
35+
| unsatisfied trait bound introduced here
3236
note: required by a bound in `EthernetWorker`
3337
--> $DIR/issue-89118.rs:28:14
3438
|
@@ -48,7 +52,9 @@ note: required for `Ctx<()>` to implement `for<'a> BufferUdpStateContext<&'a ()>
4852
--> $DIR/issue-89118.rs:5:23
4953
|
5054
LL | impl<B: BufferMut, C> BufferUdpStateContext<B> for C {}
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^
55+
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^ ^
56+
| |
57+
| unsatisfied trait bound introduced here
5258
note: required by a bound in `StackContext`
5359
--> $DIR/issue-89118.rs:9:14
5460
|

tests/ui/impl-trait/nested-return-type2-tait2.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ note: required for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7]` to i
99
--> $DIR/nested-return-type2-tait2.rs:14:31
1010
|
1111
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
12-
| ^^^^^ ^
12+
| --- ^^^^^ ^
13+
| |
14+
| unsatisfied trait bound introduced here
1315

1416
error: aborting due to previous error
1517

tests/ui/impl-trait/nested-return-type2-tait3.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ note: required for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:7]` to i
99
--> $DIR/nested-return-type2-tait3.rs:14:31
1010
|
1111
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
12-
| ^^^^^ ^
12+
| --- ^^^^^ ^
13+
| |
14+
| unsatisfied trait bound introduced here
1315

1416
error: aborting due to previous error
1517

tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: required for `()` to implement `Test`
1313
--> $DIR/projection-mismatch-in-impl-where-clause.rs:11:9
1414
|
1515
LL | impl<T> Test for T where T: Super<Assoc = ()> {}
16-
| ^^^^ ^
16+
| ^^^^ ^ ---------- unsatisfied trait bound introduced here
1717

1818
error: aborting due to previous error
1919

tests/ui/inference/issue-80816.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub trait Access<T> {
3030
}
3131
impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
3232
//~^ NOTE: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>`
33+
//~| NOTE unsatisfied trait bound introduced here
3334
type Guard = A::Guard;
3435
}
3536
impl<T> Access<T> for ArcSwapAny<T> {

tests/ui/inference/issue-80816.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0283]: type annotations needed
2-
--> $DIR/issue-80816.rs:49:38
2+
--> $DIR/issue-80816.rs:50:38
33
|
44
LL | let guard: Guard<Arc<usize>> = s.load();
55
| ^^^^
66
|
77
note: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: Access<_>` found
8-
--> $DIR/issue-80816.rs:35:1
8+
--> $DIR/issue-80816.rs:36:1
99
|
1010
LL | impl<T> Access<T> for ArcSwapAny<T> {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,9 @@ note: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `Access<_>`
1616
--> $DIR/issue-80816.rs:31:45
1717
|
1818
LL | impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
19-
| ^^^^^^^^^ ^
19+
| --------- ^^^^^^^^^ ^
20+
| |
21+
| unsatisfied trait bound introduced here
2022
help: try using a fully qualified path to specify the expected types
2123
|
2224
LL | let guard: Guard<Arc<usize>> = <Arc<ArcSwapAny<Arc<usize>>> as Access<T>>::load(&s);

tests/ui/issues/issue-20413.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ note: required for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoDa
1818
--> $DIR/issue-20413.rs:9:9
1919
|
2020
LL | impl<T> Foo for T where NoData<T>: Foo {
21-
| ^^^ ^
21+
| ^^^ ^ --- unsatisfied trait bound introduced here
2222
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
2323
= note: 127 redundant requirements hidden
2424
= note: required for `NoData<T>` to implement `Foo`
@@ -34,13 +34,13 @@ note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNo
3434
--> $DIR/issue-20413.rs:28:9
3535
|
3636
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
37-
| ^^^ ^
37+
| ^^^ ^ --- unsatisfied trait bound introduced here
3838
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
3939
note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<...>>>>>>>` to implement `Baz`
4040
--> $DIR/issue-20413.rs:35:9
4141
|
4242
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
43-
| ^^^ ^
43+
| ^^^ ^ --- unsatisfied trait bound introduced here
4444
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
4545
= note: 126 redundant requirements hidden
4646
= note: required for `EvenLessData<T>` to implement `Baz`
@@ -56,13 +56,13 @@ note: required for `EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLess
5656
--> $DIR/issue-20413.rs:35:9
5757
|
5858
LL | impl<T> Baz for T where AlmostNoData<T>: Bar {
59-
| ^^^ ^
59+
| ^^^ ^ --- unsatisfied trait bound introduced here
6060
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
6161
note: required for `AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<EvenLessData<AlmostNoData<...>>>>>>>` to implement `Bar`
6262
--> $DIR/issue-20413.rs:28:9
6363
|
6464
LL | impl<T> Bar for T where EvenLessData<T>: Baz {
65-
| ^^^ ^
65+
| ^^^ ^ --- unsatisfied trait bound introduced here
6666
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-20413/issue-20413.long-type-hash.txt'
6767
= note: 126 redundant requirements hidden
6868
= note: required for `AlmostNoData<T>` to implement `Bar`

0 commit comments

Comments
 (0)