1
Fork 0

Account for unmet T: !Copy in E0277 message

This commit is contained in:
Esteban Küber 2024-02-29 16:30:01 +00:00
parent d89c2c569a
commit 7f97dfe700
2 changed files with 16 additions and 9 deletions

View file

@ -4773,11 +4773,18 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
Some(desc) => format!(" {desc}"),
None => String::new(),
};
format!(
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
trait_predicate.print_modifiers_and_trait_path(),
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
)
if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
format!(
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
trait_predicate.print_modifiers_and_trait_path(),
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
)
} else {
// "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is
// not implemented for `T`".
// FIXME: add note explaining explicit negative trait bounds.
format!("{pre_message}the trait bound `{trait_predicate}` is not satisfied{post}")
}
}
}