Skip to content

Commit 82e7773

Browse files
committed
Subtype predicates only exist on inference types, so we can allow them to register opaque types within them.
1 parent 0230848 commit 82e7773

File tree

1 file changed

+15
-2
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+15
-2
lines changed

compiler/rustc_infer/src/infer/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,27 @@ impl<'tcx> InferCtxt<'tcx> {
945945
(&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => {
946946
return Err((a_vid, b_vid));
947947
}
948+
// We don't silently want to constrain hidden types here, so we assert that either one side is
949+
// an infer var, so it'll get constrained to whatever the other side is, or there are no opaque
950+
// types involved.
951+
// We don't expect this to actually get hit, but if it does, we now at least know how to write
952+
// a test for it.
953+
(_, ty::Infer(ty::TyVar(_))) => {}
954+
(ty::Infer(ty::TyVar(_)), _) => {}
955+
_ if (r_a, r_b).has_opaque_types() => {
956+
span_bug!(
957+
cause.span(),
958+
"opaque types got hidden types registered from within subtype predicate: {r_a:?} vs {r_b:?}"
959+
)
960+
}
948961
_ => {}
949962
}
950963

951964
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
952965
if a_is_expected {
953-
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
966+
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
954967
} else {
955-
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
968+
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a))
956969
}
957970
})
958971
}

0 commit comments

Comments
 (0)