Provide better suggestions for T == &T and &T == T

This commit is contained in:
sjwang05
2023-12-16 17:34:52 -08:00
parent de686cbc65
commit 2618e0f805
13 changed files with 670 additions and 176 deletions

View File

@@ -429,8 +429,10 @@ pub enum ObligationCauseCode<'tcx> {
MatchImpl(ObligationCause<'tcx>, DefId),
BinOp {
lhs_hir_id: hir::HirId,
rhs_hir_id: Option<hir::HirId>,
rhs_span: Option<Span>,
is_lit: bool,
rhs_is_lit: bool,
output_ty: Option<Ty<'tcx>>,
},
@@ -510,6 +512,21 @@ impl<'tcx> ObligationCauseCode<'tcx> {
base_cause
}
/// Returns the base obligation and the base trait predicate, if any, ignoring
/// derived obligations.
pub fn peel_derives_with_predicate(&self) -> (&Self, Option<ty::PolyTraitPredicate<'tcx>>) {
let mut base_cause = self;
let mut base_trait_pred = None;
while let Some((parent_code, parent_pred)) = base_cause.parent() {
base_cause = parent_code;
if let Some(parent_pred) = parent_pred {
base_trait_pred = Some(parent_pred);
}
}
(base_cause, base_trait_pred)
}
pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> {
match self {
FunctionArgumentObligation { parent_code, .. } => Some((parent_code, None)),