Unconditionally encode hidden types in typeck results
This commit is contained in:
parent
43c22af267
commit
5d15beb591
4 changed files with 43 additions and 47 deletions
|
@ -536,33 +536,29 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
let opaque_types =
|
let opaque_types =
|
||||||
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
||||||
for (opaque_type_key, decl) in opaque_types {
|
for (opaque_type_key, decl) in opaque_types {
|
||||||
let hidden_type = match decl.origin {
|
let hidden_type = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
|
||||||
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
|
|
||||||
let ty = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
|
struct RecursionChecker {
|
||||||
struct RecursionChecker {
|
def_id: LocalDefId,
|
||||||
def_id: LocalDefId,
|
}
|
||||||
}
|
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
||||||
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
type BreakTy = ();
|
||||||
type BreakTy = ();
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
if let ty::Opaque(def_id, _) = *t.kind() {
|
||||||
if let ty::Opaque(def_id, _) = *t.kind() {
|
if def_id == self.def_id.to_def_id() {
|
||||||
if def_id == self.def_id.to_def_id() {
|
return ControlFlow::Break(());
|
||||||
return ControlFlow::Break(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.super_visit_with(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ty
|
t.super_visit_with(self)
|
||||||
.visit_with(&mut RecursionChecker { def_id: opaque_type_key.def_id })
|
|
||||||
.is_break()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Some(ty)
|
|
||||||
}
|
}
|
||||||
hir::OpaqueTyOrigin::TyAlias => None,
|
}
|
||||||
};
|
if hidden_type
|
||||||
|
.visit_with(&mut RecursionChecker { def_id: opaque_type_key.def_id })
|
||||||
|
.is_break()
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
|
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -788,20 +788,15 @@ fn find_opaque_ty_constraints_for_rpit(
|
||||||
// the `concrete_opaque_types` table.
|
// the `concrete_opaque_types` table.
|
||||||
tcx.ty_error()
|
tcx.ty_error()
|
||||||
} else {
|
} else {
|
||||||
table
|
table.concrete_opaque_types.get(&def_id).copied().unwrap_or_else(|| {
|
||||||
.concrete_opaque_types
|
// We failed to resolve the opaque type or it
|
||||||
.get(&def_id)
|
// resolves to itself. We interpret this as the
|
||||||
.copied()
|
// no values of the hidden type ever being constructed,
|
||||||
.unwrap_or_else(|| {
|
// so we can just make the hidden type be `!`.
|
||||||
// We failed to resolve the opaque type or it
|
// For backwards compatibility reasons, we fall back to
|
||||||
// resolves to itself. We interpret this as the
|
// `()` until we the diverging default is changed.
|
||||||
// no values of the hidden type ever being constructed,
|
tcx.mk_diverging_default()
|
||||||
// so we can just make the hidden type be `!`.
|
})
|
||||||
// For backwards compatibility reasons, we fall back to
|
|
||||||
// `()` until we the diverging default is changed.
|
|
||||||
Some(tcx.mk_diverging_default())
|
|
||||||
})
|
|
||||||
.expect("RPIT always have a hidden type from typeck")
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,12 +539,10 @@ pub struct TypeckResults<'tcx> {
|
||||||
pub tainted_by_errors: Option<ErrorGuaranteed>,
|
pub tainted_by_errors: Option<ErrorGuaranteed>,
|
||||||
|
|
||||||
/// All the opaque types that have hidden types set
|
/// All the opaque types that have hidden types set
|
||||||
/// by this function. For return-position-impl-trait we also store the
|
/// by this function. We also store the
|
||||||
/// type here, so that mir-borrowck can figure out hidden types,
|
/// type here, so that mir-borrowck can use it as a hint for figuring out hidden types,
|
||||||
/// even if they are only set in dead code (which doesn't show up in MIR).
|
/// even if they are only set in dead code (which doesn't show up in MIR).
|
||||||
/// For type-alias-impl-trait, this map is only used to prevent query cycles,
|
pub concrete_opaque_types: VecMap<LocalDefId, Ty<'tcx>>,
|
||||||
/// so the hidden types are all `None`.
|
|
||||||
pub concrete_opaque_types: VecMap<LocalDefId, Option<Ty<'tcx>>>,
|
|
||||||
|
|
||||||
/// Tracks the minimum captures required for a closure;
|
/// Tracks the minimum captures required for a closure;
|
||||||
/// see `MinCaptureInformationMap` for more details.
|
/// see `MinCaptureInformationMap` for more details.
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
error: unconstrained opaque type
|
||||||
|
--> $DIR/issue-86800.rs:33:34
|
||||||
|
|
|
||||||
|
LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
=
|
||||||
|
|
||||||
|
|
||||||
stack backtrace:
|
stack backtrace:
|
||||||
|
|
||||||
|
@ -12,8 +20,7 @@ error: internal compiler error: unexpected panic
|
||||||
|
|
||||||
|
|
||||||
query stack during panic:
|
query stack during panic:
|
||||||
#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
|
#0 [type_of] computing type of `TransactionFuture::{opaque#0}`
|
||||||
#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
|
#1 [check_mod_item_types] checking item types in top-level module
|
||||||
#2 [check_mod_item_types] checking item types in top-level module
|
#2 [analysis] running analysis passes on this crate
|
||||||
#3 [analysis] running analysis passes on this crate
|
|
||||||
end of query stack
|
end of query stack
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue