Skip to content

Recursion limit silently ignored if it overflows a usize #67265

Closed
@ecstatic-morse

Description

@ecstatic-morse

The following code fails to compile since it exceeds the default recursion limit. Using 2056 as the recursion limit works as expected.

#![recursion_limit = "99999999999999999999999999999999999999999999999999999"]
//#![recursion_limit = "2056"]

macro_rules! explode {
    (recurse; $head:tt $($tail:tt)*) => { explode!(recurse; $($tail)*); };
    (recurse;) => {};
    
    (0; $($tt:tt)*) => { explode!(1; $($tt)* $($tt)* $($tt)*); };
    (1; $($tt:tt)*) => { explode!(2; $($tt)* $($tt)* $($tt)*); };
    (2; $($tt:tt)*) => { explode!(3; $($tt)* $($tt)* $($tt)*); };
    (3; $($tt:tt)*) => { explode!(recurse; $($tt)* $($tt)* $($tt)*); };
}

explode!(0; a b c);

This is because we don't check for integer overflow errors when parsing limits:

fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: Symbol, default: usize) {
for attr in &krate.attrs {
if !attr.check_name(name) {
continue;
}
if let Some(s) = attr.value_str() {
if let Some(n) = s.as_str().parse().ok() {
limit.set(n);
return;
}
}
}
limit.set(default);
}

There's a few options here. My preference would be to silently default to usize::MAX when overflow occurs.

This issue has been assigned to @fisherdarling via this comment.

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions