Skip to content

Commit 8d92e49

Browse files
Register opaque types even when equated with infer variables
1 parent 039a6ad commit 8d92e49

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

compiler/rustc_infer/src/infer/equate.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,8 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
8080
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
8181

8282
match (a.kind(), b.kind()) {
83-
(&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => {
84-
infcx.inner.borrow_mut().type_variables().equate(a_id, b_id);
85-
}
86-
87-
(&ty::Infer(TyVar(a_id)), _) => {
88-
self.fields.instantiate(b, RelationDir::EqTo, a_id, self.a_is_expected)?;
89-
}
90-
91-
(_, &ty::Infer(TyVar(b_id))) => {
92-
self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?;
93-
}
94-
9583
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
96-
self.fields.infcx.super_combine_tys(self, a, b)?;
84+
self.infcx.super_combine_tys(self, a, b)
9785
}
9886
(&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..))
9987
if self.fields.define_opaque_types && did.is_local() =>
@@ -111,6 +99,18 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
11199
);
112100
}
113101

102+
(&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => {
103+
infcx.inner.borrow_mut().type_variables().equate(a_id, b_id);
104+
}
105+
106+
(&ty::Infer(TyVar(a_id)), _) => {
107+
self.fields.instantiate(b, RelationDir::EqTo, a_id, self.a_is_expected)?;
108+
}
109+
110+
(_, &ty::Infer(TyVar(b_id))) => {
111+
self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?;
112+
}
113+
114114
_ => {
115115
self.fields.infcx.super_combine_tys(self, a, b)?;
116116
}

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
184184
} else if let Some(res) = process(b, a) {
185185
res
186186
} else {
187-
// Rerun equality check, but this time error out due to
188-
// different types.
189-
match self.at(cause, param_env).define_opaque_types(false).eq(a, b) {
190-
Ok(_) => span_bug!(
191-
cause.span,
192-
"opaque types are never equal to anything but themselves: {:#?}",
193-
(a.kind(), b.kind())
194-
),
195-
Err(e) => Err(e),
196-
}
187+
self.at(cause, param_env).define_opaque_types(false).eq(a, b)
197188
}
198189
}
199190

compiler/rustc_infer/src/infer/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
9090
// Shouldn't have any LBR here, so we can safely put
9191
// this under a binder below without fear of accidental
9292
// capture.
93-
assert!(!a.has_escaping_bound_vars());
93+
assert!(!a.has_escaping_bound_vars());
9494
assert!(!b.has_escaping_bound_vars());
9595

9696
// can't make progress on `A <: B` if both A and B are

0 commit comments

Comments
 (0)