Skip to content

Commit b220750

Browse files
Make sure that predicates with unmentioned bound vars are still considered global in the old solver
1 parent adda05f commit b220750

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

compiler/rustc_middle/src/ty/erase_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ impl<'tcx> TyCtxt<'tcx> {
2020
where
2121
T: TypeFoldable<TyCtxt<'tcx>>,
2222
{
23-
// If there's nothing to erase avoid performing the query at all
24-
if !value.has_type_flags(TypeFlags::HAS_LATE_BOUND | TypeFlags::HAS_FREE_REGIONS) {
23+
// If there's nothing to erase or anonymize, avoid performing the query at all
24+
if !value.has_type_flags(TypeFlags::HAS_BINDER_VARS | TypeFlags::HAS_FREE_REGIONS) {
2525
return value;
2626
}
2727
debug!("erase_regions({:?})", value);

compiler/rustc_middle/src/ty/flags.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,6 @@ impl FlagComputation {
3434
result.flags
3535
}
3636

37-
pub fn bound_var_flags(vars: &ty::List<ty::BoundVariableKind>) -> FlagComputation {
38-
let mut computation = FlagComputation::new();
39-
40-
for bv in vars {
41-
match bv {
42-
ty::BoundVariableKind::Ty(_) => {
43-
computation.flags |= TypeFlags::HAS_TY_LATE_BOUND;
44-
}
45-
ty::BoundVariableKind::Region(_) => {
46-
computation.flags |= TypeFlags::HAS_RE_LATE_BOUND;
47-
}
48-
ty::BoundVariableKind::Const => {
49-
computation.flags |= TypeFlags::HAS_CT_LATE_BOUND;
50-
}
51-
}
52-
}
53-
54-
computation
55-
}
56-
5737
fn add_flags(&mut self, flags: TypeFlags) {
5838
self.flags = self.flags | flags;
5939
}
@@ -77,7 +57,11 @@ impl FlagComputation {
7757
where
7858
F: FnOnce(&mut Self, T),
7959
{
80-
let mut computation = FlagComputation::bound_var_flags(value.bound_vars());
60+
let mut computation = FlagComputation::new();
61+
62+
if !value.bound_vars().is_empty() {
63+
computation.add_flags(TypeFlags::HAS_BINDER_VARS);
64+
}
8165

8266
f(&mut computation, value.skip_binder());
8367

compiler/rustc_middle/src/ty/visit.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasTypeFlagsVisitor {
494494
&mut self,
495495
t: &Binder<'tcx, T>,
496496
) -> ControlFlow<Self::BreakTy> {
497-
// If we're looking for any of the HAS_*_LATE_BOUND flags, we need to
498-
// additionally consider the bound vars on the binder itself, even if
499-
// the contents of a the binder (e.g. a `TraitRef`) doesn't reference
500-
// the bound vars.
501-
if self.flags.intersects(TypeFlags::HAS_LATE_BOUND) {
502-
let bound_var_flags = FlagComputation::bound_var_flags(t.bound_vars());
503-
if bound_var_flags.flags.intersects(self.flags) {
504-
return ControlFlow::Break(FoundFlags);
505-
}
497+
// If we're looking for the HAS_BINDER_VARS flag, check if the
498+
// binder has vars. This won't be present in the binder's bound
499+
// value, so we need to check here too.
500+
if self.flags.intersects(TypeFlags::HAS_BINDER_VARS) && !t.bound_vars().is_empty() {
501+
return ControlFlow::Break(FoundFlags);
506502
}
507503

508504
t.super_visit_with(self)

compiler/rustc_type_ir/src/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,8 @@ bitflags! {
115115

116116
/// Does this have `Coroutine` or `CoroutineWitness`?
117117
const HAS_TY_COROUTINE = 1 << 23;
118+
119+
/// Does this have any binders with bound vars (e.g. that need to be anonymized)?
120+
const HAS_BINDER_VARS = 1 << 24;
118121
}
119122
}

0 commit comments

Comments
 (0)