Skip to content

Commit 568b316

Browse files
committed
Move predicate error early check to its own method
1 parent 124d6d8 commit 568b316

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub trait TypeErrCtxtExt<'tcx> {
104104
error: &SelectionError<'tcx>,
105105
);
106106

107+
fn fn_arg_obligation(&self, obligation: &PredicateObligation<'tcx>) -> bool;
108+
107109
fn report_const_param_not_wf(
108110
&self,
109111
ty: Ty<'tcx>,
@@ -434,20 +436,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
434436
{
435437
return;
436438
}
437-
if let ObligationCauseCode::FunctionArgumentObligation {
438-
arg_hir_id,
439-
..
440-
} = obligation.cause.code()
441-
&& let Some(Node::Expr(arg)) = self.tcx.hir().find(*arg_hir_id)
442-
&& let arg = arg.peel_borrows()
443-
&& let hir::ExprKind::Path(hir::QPath::Resolved(
444-
None,
445-
hir::Path { res: hir::def::Res::Local(hir_id), .. },
446-
)) = arg.kind
447-
&& let Some(Node::Pat(pat)) = self.tcx.hir().find(*hir_id)
448-
&& let Some(preds) = self.reported_trait_errors.borrow().get(&pat.span)
449-
&& preds.contains(&obligation.predicate)
450-
{
439+
if self.fn_arg_obligation(&obligation) {
451440
// Silence redundant errors on binding acccess that are already
452441
// reported on the binding definition (#56607).
453442
return;
@@ -948,6 +937,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
948937
err.emit();
949938
}
950939

940+
fn fn_arg_obligation(&self, obligation: &PredicateObligation<'tcx>) -> bool {
941+
if let ObligationCauseCode::FunctionArgumentObligation {
942+
arg_hir_id,
943+
..
944+
} = obligation.cause.code()
945+
&& let Some(Node::Expr(arg)) = self.tcx.hir().find(*arg_hir_id)
946+
&& let arg = arg.peel_borrows()
947+
&& let hir::ExprKind::Path(hir::QPath::Resolved(
948+
None,
949+
hir::Path { res: hir::def::Res::Local(hir_id), .. },
950+
)) = arg.kind
951+
&& let Some(Node::Pat(pat)) = self.tcx.hir().find(*hir_id)
952+
&& let Some(preds) = self.reported_trait_errors.borrow().get(&pat.span)
953+
&& preds.contains(&obligation.predicate)
954+
{
955+
return true;
956+
}
957+
false
958+
}
959+
951960
fn report_const_param_not_wf(
952961
&self,
953962
ty: Ty<'tcx>,

0 commit comments

Comments
 (0)