-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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:
rust/src/librustc/middle/recursion_limit.rs
Lines 19 to 33 in e9469a6
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.
estebank
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.