Tweak span in E0599

This commit is contained in:
Esteban Küber
2026-01-19 21:33:39 +00:00
parent 879633f97b
commit 8543404e8d
4 changed files with 45 additions and 24 deletions
+32 -18
View File
@@ -1752,16 +1752,30 @@ fn handle_unsatisfied_predicates(
for (p, parent_p, cause) in unsatisfied_predicates {
// Extract the predicate span and parent def id of the cause,
// if we have one.
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
Some(ObligationCauseCode::ImplDerived(data)) => {
(data.impl_or_alias_def_id, data.span)
}
Some(
ObligationCauseCode::WhereClauseInExpr(def_id, span, _, _)
| ObligationCauseCode::WhereClause(def_id, span),
) if !span.is_dummy() => (*def_id, *span),
_ => continue,
};
let (item_def_id, cause_span, cause_msg) =
match cause.as_ref().map(|cause| cause.code()) {
Some(ObligationCauseCode::ImplDerived(data)) => {
let msg = if let DefKind::Impl { of_trait: true } =
self.tcx.def_kind(data.impl_or_alias_def_id)
{
format!(
"type parameter would need to implement `{}`",
self.tcx
.item_name(self.tcx.impl_trait_id(data.impl_or_alias_def_id))
)
} else {
format!("unsatisfied bound `{p}` introduced here")
};
(data.impl_or_alias_def_id, data.span, msg)
}
Some(
ObligationCauseCode::WhereClauseInExpr(def_id, span, _, _)
| ObligationCauseCode::WhereClause(def_id, span),
) if !span.is_dummy() => {
(*def_id, *span, format!("unsatisfied bound `{p}` introduced here"))
}
_ => continue,
};
// Don't point out the span of `WellFormed` predicates.
if !matches!(
@@ -1792,10 +1806,10 @@ fn handle_unsatisfied_predicates(
let entry = entry.or_insert_with(|| {
(FxIndexSet::default(), FxIndexSet::default(), Vec::new())
});
entry.0.insert(span);
entry.0.insert(cause_span);
entry.1.insert((
span,
"unsatisfied trait bound introduced in this `derive` macro",
cause_span,
cause_msg,
));
entry.2.push(p);
skip_list.insert(p);
@@ -1844,7 +1858,7 @@ fn handle_unsatisfied_predicates(
entry.2.push(p);
if cause_span != *item_span {
entry.0.insert(cause_span);
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
entry.1.insert((cause_span, "unsatisfied trait bound introduced here".to_string()));
} else {
if let Some(of_trait) = of_trait {
entry.0.insert(of_trait.trait_ref.path.span);
@@ -1852,9 +1866,9 @@ fn handle_unsatisfied_predicates(
entry.0.insert(self_ty.span);
};
if let Some(of_trait) = of_trait {
entry.1.insert((of_trait.trait_ref.path.span, ""));
entry.1.insert((of_trait.trait_ref.path.span, String::new()));
}
entry.1.insert((self_ty.span, ""));
entry.1.insert((self_ty.span, String::new()));
}
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, rustc_ast::ast::IsAuto::Yes, ..),
@@ -1883,8 +1897,8 @@ fn handle_unsatisfied_predicates(
(FxIndexSet::default(), FxIndexSet::default(), Vec::new())
});
entry.0.insert(cause_span);
entry.1.insert((ident.span, ""));
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
entry.1.insert((ident.span, String::new()));
entry.1.insert((cause_span, "unsatisfied trait bound introduced here".to_string()));
entry.2.push(p);
}
_ => {
@@ -11,10 +11,12 @@ LL | Bar::<NotClone> { x: 1 }.clone();
| ^^^^^ method cannot be called on `Bar<NotClone>` due to unsatisfied trait bounds
|
note: trait bound `NotClone: Clone` was not satisfied
--> $DIR/derive-assoc-type-not-impl.rs:6:10
--> $DIR/derive-assoc-type-not-impl.rs:7:12
|
LL | #[derive(Clone)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
| ----- in this derive macro expansion
LL | struct Bar<T: Foo> {
| ^ type parameter would need to implement `Clone`
= help: consider manually implementing the trait to avoid undesired bounds
help: consider annotating `NotClone` with `#[derive(Clone)]`
|
@@ -21,10 +21,13 @@ LL | let x: Foo<NonCopy> = Foo(NonCopy, NonCopy, NonCopy);
note: the following trait bounds were not satisfied:
`NonCopy: Clone`
`NonCopy: Copy`
--> $DIR/deriving-with-repr-packed-2.rs:5:16
--> $DIR/deriving-with-repr-packed-2.rs:7:16
|
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
| ----- in this derive macro expansion
LL | #[repr(packed)]
LL | pub struct Foo<T>(T, T, T);
| ^ type parameter would need to implement `Clone`
= help: consider manually implementing the trait to avoid undesired bounds
help: consider annotating `NonCopy` with `#[derive(Clone, Copy)]`
|
+4 -2
View File
@@ -25,10 +25,12 @@ LL | let w = u.clone();
| ^^^^^ method cannot be called on `U5<CloneNoCopy>` due to unsatisfied trait bounds
|
note: trait bound `CloneNoCopy: Copy` was not satisfied
--> $DIR/union-derive-clone.rs:25:10
--> $DIR/union-derive-clone.rs:26:10
|
LL | #[derive(Clone, Copy)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
| ----- in this derive macro expansion
LL | union U5<T> {
| ^ type parameter would need to implement `Clone`
= help: consider manually implementing the trait to avoid undesired bounds
help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
|