Skip to content

Commit af2a85b

Browse files
committed
Ensure stack in Parser::parse_ty
This solve a stack overflow found on Fedora s390x when building `tests/ui/associated-consts/issue-93775.rs`.
1 parent 925e761 commit af2a85b

File tree

1 file changed

+12
-8
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+12
-8
lines changed

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::{
77
Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty,
88
TyKind, UnsafeBinderTy,
99
};
10+
use rustc_data_structures::stack::ensure_sufficient_stack;
1011
use rustc_errors::{Applicability, Diag, PResult};
1112
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
1213
use thin_vec::{ThinVec, thin_vec};
@@ -104,14 +105,17 @@ fn can_begin_dyn_bound_in_edition_2015(t: &Token) -> bool {
104105
impl<'a> Parser<'a> {
105106
/// Parses a type.
106107
pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
107-
self.parse_ty_common(
108-
AllowPlus::Yes,
109-
AllowCVariadic::No,
110-
RecoverQPath::Yes,
111-
RecoverReturnSign::Yes,
112-
None,
113-
RecoverQuestionMark::Yes,
114-
)
108+
// Make sure deeply nested types don't overflow the stack.
109+
ensure_sufficient_stack(|| {
110+
self.parse_ty_common(
111+
AllowPlus::Yes,
112+
AllowCVariadic::No,
113+
RecoverQPath::Yes,
114+
RecoverReturnSign::Yes,
115+
None,
116+
RecoverQuestionMark::Yes,
117+
)
118+
})
115119
}
116120

117121
pub(super) fn parse_ty_with_generics_recovery(

0 commit comments

Comments
 (0)