Skip to content

Commit dd14f34

Browse files
Revert "Fix stack overflow in exhaustiveness due to recursive HIR opaque type values"
This reverts commit b08e9c2.
1 parent 7d82b60 commit dd14f34

File tree

1 file changed

+5
-35
lines changed
  • compiler/rustc_pattern_analysis/src

1 file changed

+5
-35
lines changed

compiler/rustc_pattern_analysis/src/rustc.rs

+5-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt;
22
use std::iter::once;
3-
use std::ops::ControlFlow;
43

54
use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx};
65
use rustc_arena::DroplessArena;
@@ -12,8 +11,7 @@ use rustc_middle::mir::{self, Const};
1211
use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary};
1312
use rustc_middle::ty::layout::IntegerExt;
1413
use rustc_middle::ty::{
15-
self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
16-
TypeVisitableExt, TypeVisitor, VariantDef,
14+
self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeVisitableExt, VariantDef,
1715
};
1816
use rustc_middle::{bug, span_bug};
1917
use rustc_session::lint;
@@ -137,22 +135,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
137135
/// Returns the hidden type corresponding to this key if the body under analysis is allowed to
138136
/// know it.
139137
fn reveal_opaque_key(&self, key: OpaqueTypeKey<'tcx>) -> Option<Ty<'tcx>> {
140-
if let Some(hidden_ty) = self.typeck_results.concrete_opaque_types.get(&key.def_id) {
141-
let ty = ty::EarlyBinder::bind(hidden_ty.ty).instantiate(self.tcx, key.args);
142-
if ty.visit_with(&mut RecursiveOpaque { def_id: key.def_id.into() }).is_continue() {
143-
Some(ty)
144-
} else {
145-
// HACK: We skip revealing opaque types which recursively expand
146-
// to themselves. This is because we may infer hidden types like
147-
// `Opaque<T> = Opaque<Opaque<T>>` or `Opaque<T> = Opaque<(T,)>`
148-
// in hir typeck.
149-
None
150-
}
151-
} else {
152-
None
153-
}
138+
self.typeck_results
139+
.concrete_opaque_types
140+
.get(&key.def_id)
141+
.map(|x| ty::EarlyBinder::bind(x.ty).instantiate(self.tcx, key.args))
154142
}
155-
156143
// This can take a non-revealed `Ty` because it reveals opaques itself.
157144
pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
158145
!ty.inhabited_predicate(self.tcx).apply_revealing_opaque(
@@ -1118,20 +1105,3 @@ pub fn analyze_match<'p, 'tcx>(
11181105

11191106
Ok(report)
11201107
}
1121-
1122-
struct RecursiveOpaque {
1123-
def_id: DefId,
1124-
}
1125-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for RecursiveOpaque {
1126-
type Result = ControlFlow<()>;
1127-
1128-
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1129-
if let ty::Alias(ty::Opaque, alias_ty) = t.kind() {
1130-
if alias_ty.def_id == self.def_id {
1131-
return ControlFlow::Break(());
1132-
}
1133-
}
1134-
1135-
if t.has_opaque_types() { t.super_visit_with(self) } else { ControlFlow::Continue(()) }
1136-
}
1137-
}

0 commit comments

Comments
 (0)