fix: Guard SizeSkeleton::compute against stack overflow#156235
fix: Guard SizeSkeleton::compute against stack overflow#156235rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // Bail out if we've recursed too deeply (issue #156137); a cyclic type | ||
| // alias can otherwise blow the stack here. | ||
| if !tcx.recursion_limit().value_within_limit(depth) { | ||
| return Err(tcx.arena.alloc(LayoutError::Unknown(ty))); |
There was a problem hiding this comment.
We should just raise a recursion limit error here. There's a function for doing that, several other recursion limit checks should be doing that, too.
There was a problem hiding this comment.
you mean the emit_err(RecursionLimitReached{...}) pattern used in struct_tail_raw?
but SizeSkeleton::compute has no span. should I add it and create RecursionLimitReachedSizeSkeleton diagnostic in error.rs?
There was a problem hiding this comment.
You can pass span in from SizeSkeleton::compute's call sites. If there's no span outside, then fallback to DUMMY_SP.
There're multiple RecursionLimitReached errors in different crates. If reusing doesn't make sense, you can create your own one to tailor the message. But @oli-obk might know a generic function for that?
|
@adwinwhite @oli-obk Implemented this for now, Is there a more generic utility you had in mind, or does this approach look good? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a8c7309 to
7a900df
Compare
|
@bors r+ rollup |
…_fix, r=adwinwhite fix: Guard SizeSkeleton::compute against stack overflow Fixes rust-lang#156137 Fix: extract the recursion into a private `compute_inner` that carries a depth counter. When depth exceeds the crate's recursion limit, return `LayoutError::Unknown` and let the existing transmute size-check produce a normal error instead of crashing. A regression test is included in `tests/ui/transmute/`.
Rollup of 5 pull requests Successful merges: - #156354 (Update example code of `std::array::from_fn`) - #156359 (use `cfg_select!` in integer `{to, from}_{le, be}`) - #156124 (Make stable hashing names consistent (part 2)) - #156235 (fix: Guard SizeSkeleton::compute against stack overflow) - #156353 (resolve: Set correct parent and expansion for `self` declarations)
Rollup merge of #156235 - rajgandhi1:compiler_stack_overflow_fix, r=adwinwhite fix: Guard SizeSkeleton::compute against stack overflow Fixes #156137 Fix: extract the recursion into a private `compute_inner` that carries a depth counter. When depth exceeds the crate's recursion limit, return `LayoutError::Unknown` and let the existing transmute size-check produce a normal error instead of crashing. A regression test is included in `tests/ui/transmute/`.
Fixes #156137
Fix: extract the recursion into a private
compute_innerthat carries a depth counter. When depth exceeds the crate's recursion limit, returnLayoutError::Unknownand let the existing transmute size-check produce a normal error instead of crashing.A regression test is included in
tests/ui/transmute/.