Skip to content

Commit 34f7cbe

Browse files
Revert "Fix stack overflow in exhaustiveness due to recursive HIR opaque type values"
This reverts commit b08e9c2.
1 parent a1f3ba0 commit 34f7cbe

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 5 additions & 35 deletions
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(
@@ -1177,20 +1164,3 @@ fn detect_mixed_deref_pat_ctors<'p, 'tcx>(
11771164
}
11781165
Ok(())
11791166
}
1180-
1181-
struct RecursiveOpaque {
1182-
def_id: DefId,
1183-
}
1184-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for RecursiveOpaque {
1185-
type Result = ControlFlow<()>;
1186-
1187-
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1188-
if let ty::Alias(ty::Opaque, alias_ty) = t.kind() {
1189-
if alias_ty.def_id == self.def_id {
1190-
return ControlFlow::Break(());
1191-
}
1192-
}
1193-
1194-
if t.has_opaque_types() { t.super_visit_with(self) } else { ControlFlow::Continue(()) }
1195-
}
1196-
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
//@ known-bug: #139817
1+
#![feature(type_alias_impl_trait)]
2+
23
fn enum_upvar() {
34
type T = impl Copy;
45
let foo: T = Some((42, std::marker::PhantomData::<T>));
56
let x = move || match foo {
67
None => (),
8+
//~^ ERROR cannot resolve opaque type
79
};
810
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)