Skip to content

Commit 24653a5

Browse files
committed
Remove a HACK by instead inferring opaque types during expected/formal type checking
1 parent 0c60779 commit 24653a5

File tree

2 files changed

+1
-27
lines changed

2 files changed

+1
-27
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

-26
Original file line numberDiff line numberDiff line change
@@ -711,32 +711,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711711
let formal_ret = self.resolve_vars_with_obligations(formal_ret);
712712
let ret_ty = expected_ret.only_has_type(self)?;
713713

714-
// HACK(oli-obk): This is a hack to keep RPIT and TAIT in sync wrt their behaviour.
715-
// Without it, the inference
716-
// variable will get instantiated with the opaque type. The inference variable often
717-
// has various helpful obligations registered for it that help closures figure out their
718-
// signature. If we infer the inference var to the opaque type, the closure won't be able
719-
// to find those obligations anymore, and it can't necessarily find them from the opaque
720-
// type itself. We could be more powerful with inference if we *combined* the obligations
721-
// so that we got both the obligations from the opaque type and the ones from the inference
722-
// variable. That will accept more code than we do right now, so we need to carefully consider
723-
// the implications.
724-
// Note: this check is pessimistic, as the inference type could be matched with something other
725-
// than the opaque type, but then we need a new `TypeRelation` just for this specific case and
726-
// can't re-use `sup` below.
727-
// See tests/ui/impl-trait/hidden-type-is-opaque.rs and
728-
// tests/ui/impl-trait/hidden-type-is-opaque-2.rs for examples that hit this path.
729-
if formal_ret.has_infer_types() {
730-
for ty in ret_ty.walk() {
731-
if let ty::GenericArgKind::Type(ty) = ty.unpack()
732-
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *ty.kind()
733-
&& self.can_define_opaque_ty(def_id)
734-
{
735-
return None;
736-
}
737-
}
738-
}
739-
740714
let expect_args = self
741715
.fudge_inference_if_ok(|| {
742716
let ocx = ObligationCtxt::new(self);

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
297297
// 3. Check if the formal type is a supertype of the checked one
298298
// and register any such obligations for future type checks
299299
let supertype_error = self.at(&self.misc(provided_arg.span), self.param_env).sup(
300-
DefineOpaqueTypes::No,
300+
DefineOpaqueTypes::Yes,
301301
formal_input_ty,
302302
coerced_ty,
303303
);

0 commit comments

Comments
 (0)