Consider unfulfilled obligations in binop errors
When encountering a binop where the types would have been accepted, if all the predicates had been fulfilled, include information about the predicates and suggest appropriate `#[derive]`s if possible. Point at trait(s) that needs to be `impl`emented.
This commit is contained in:
@@ -2171,10 +2171,26 @@ impl fmt::Debug for TraitRefPrintOnlyTraitPath<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only
|
||||
/// the trait name. That is, it will print `Trait` instead of
|
||||
/// `<T as Trait<U>>`.
|
||||
#[derive(Copy, Clone, TypeFoldable, Lift)]
|
||||
pub struct TraitRefPrintOnlyTraitName<'tcx>(ty::TraitRef<'tcx>);
|
||||
|
||||
impl fmt::Debug for TraitRefPrintOnlyTraitName<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ty::TraitRef<'tcx> {
|
||||
pub fn print_only_trait_path(self) -> TraitRefPrintOnlyTraitPath<'tcx> {
|
||||
TraitRefPrintOnlyTraitPath(self)
|
||||
}
|
||||
|
||||
pub fn print_only_trait_name(self) -> TraitRefPrintOnlyTraitName<'tcx> {
|
||||
TraitRefPrintOnlyTraitName(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ty::Binder<'tcx, ty::TraitRef<'tcx>> {
|
||||
@@ -2193,6 +2209,7 @@ forward_display_to_print! {
|
||||
ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>,
|
||||
ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
ty::Binder<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
|
||||
ty::Binder<'tcx, TraitRefPrintOnlyTraitName<'tcx>>,
|
||||
ty::Binder<'tcx, ty::FnSig<'tcx>>,
|
||||
ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
|
||||
ty::Binder<'tcx, ty::SubtypePredicate<'tcx>>,
|
||||
@@ -2255,6 +2272,10 @@ define_print_and_forward_display! {
|
||||
p!(print_def_path(self.0.def_id, self.0.substs));
|
||||
}
|
||||
|
||||
TraitRefPrintOnlyTraitName<'tcx> {
|
||||
p!(print_def_path(self.0.def_id, &[]));
|
||||
}
|
||||
|
||||
ty::ParamTy {
|
||||
p!(write("{}", self.name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user