Skip to content

Commit 6a8c50f

Browse files
committed
!! (WIP) pat_references_error
1 parent 8893940 commit 6a8c50f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

compiler/rustc_middle/src/thir.rs

+13
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,19 @@ impl<'tcx> Thir<'tcx> {
689689
}
690690
}
691691

692+
pub fn pat_references_error(&self, pat: &Pat<'tcx>) -> bool {
693+
use rustc_type_ir::visit::TypeVisitableExt;
694+
695+
let mut references_error = TypeVisitableExt::references_error(pat);
696+
if !references_error {
697+
for_each_immediate_subpat(self, pat, |p| {
698+
references_error = references_error || self.pat_references_error(p);
699+
});
700+
}
701+
702+
references_error
703+
}
704+
692705
/// Walk the pattern in left-to-right order.
693706
///
694707
/// If you always want to recurse, prefer this method over `walk`.

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1010
use rustc_infer::traits::Obligation;
1111
use rustc_middle::mir::interpret::ErrorHandled;
1212
use rustc_middle::thir::{FieldPat, Pat, PatKind, Thir};
13-
use rustc_middle::ty::{
14-
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitableExt, TypeVisitor, ValTree,
15-
};
13+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, ValTree};
1614
use rustc_middle::{mir, span_bug};
1715
use rustc_span::def_id::DefId;
1816
use rustc_span::{Span, sym};
@@ -194,7 +192,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
194192
// Convert the valtree to a const.
195193
let inlined_const_as_pat = self.valtree_to_pat(valtree, ty);
196194

197-
if !inlined_const_as_pat.references_error() {
195+
if !self.thir.pat_references_error(&inlined_const_as_pat) {
198196
// Always check for `PartialEq` if we had no other errors yet.
199197
if !type_has_partial_eq_impl(self.tcx, typing_env, ty).has_impl {
200198
let mut err = self.tcx.dcx().create_err(TypeNotPartialEq { span: self.span, ty });

0 commit comments

Comments
 (0)