Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 90f9c68

Browse files
authoredJan 11, 2023
Rollup merge of #106703 - compiler-errors:impl-derived-span, r=estebank
Note predicate span on `ImplDerivedObligation` Seems obvious to point out the where-clause that introduces the `ImplDerivedObligation` :) r? `@estebank`
2 parents 88765b0 + 9a39d7e commit 90f9c68

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

0 commit comments

Comments
 (0)
Please sign in to comment.