Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ use super::deconstruct_pat::{Constructor, DeconstructedPat, Fields, SplitWildcar
use rustc_data_structures::captures::Captures;

use rustc_arena::TypedArena;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::DefId;
use rustc_hir::HirId;
use rustc_middle::ty::{self, Ty, TyCtxt};
Expand Down Expand Up @@ -808,8 +809,9 @@ fn is_useful<'p, 'tcx>(
// We try each or-pattern branch in turn.
let mut matrix = matrix.clone();
for v in v.expand_or_pat() {
let usefulness =
is_useful(cx, &matrix, &v, witness_preference, hir_id, is_under_guard, false);
let usefulness = ensure_sufficient_stack(|| {
is_useful(cx, &matrix, &v, witness_preference, hir_id, is_under_guard, false)
});
ret.extend(usefulness);
// If pattern has a guard don't add it to the matrix.
if !is_under_guard {
Expand Down Expand Up @@ -840,8 +842,9 @@ fn is_useful<'p, 'tcx>(
// We cache the result of `Fields::wildcards` because it is used a lot.
let spec_matrix = start_matrix.specialize_constructor(pcx, &ctor);
let v = v.pop_head_constructor(cx, &ctor);
let usefulness =
is_useful(cx, &spec_matrix, &v, witness_preference, hir_id, is_under_guard, false);
let usefulness = ensure_sufficient_stack(|| {
is_useful(cx, &spec_matrix, &v, witness_preference, hir_id, is_under_guard, false)
});
let usefulness = usefulness.apply_constructor(pcx, start_matrix, &ctor);

// When all the conditions are met we have a match with a `non_exhaustive` enum
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/pattern/usefulness/issue-88747.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// check-pass: this used to be a stack overflow because of recursion in `usefulness.rs`

macro_rules! long_tuple_arg {
([$($t:tt)*]#$($h:tt)*) => {
long_tuple_arg!{[$($t)*$($t)*]$($h)*}
};
([$([$t:tt $y:tt])*]) => {
pub fn _f(($($t,)*): ($($y,)*)) {}
}
}

long_tuple_arg!{[[_ u8]]########## ###}

fn main() {}