-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix [large_stack_arrays
] linting in vec
macro
#12624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
//@aux-build:proc_macros.rs | ||
#![warn(clippy::large_stack_arrays)] | ||
#![allow(clippy::large_enum_variant)] | ||
|
||
extern crate proc_macros; | ||
|
||
#[derive(Clone, Copy)] | ||
struct S { | ||
pub data: [u64; 32], | ||
|
@@ -55,3 +58,48 @@ fn main() { | |
[(); 20_000_000], | ||
); | ||
} | ||
|
||
#[allow(clippy::useless_vec)] | ||
fn issue_12586() { | ||
macro_rules! dummy { | ||
($n:expr) => { | ||
$n | ||
}; | ||
// Weird rule to test help messages. | ||
($a:expr => $b:expr) => { | ||
[$a, $b, $a, $b] | ||
//~^ ERROR: allocating a local array larger than 512000 bytes | ||
}; | ||
($id:ident; $n:literal) => { | ||
dummy!(::std::vec![$id;$n]) | ||
}; | ||
($($id:expr),+ $(,)?) => { | ||
::std::vec![$($id),*] | ||
} | ||
} | ||
macro_rules! create_then_move { | ||
($id:ident; $n:literal) => {{ | ||
let _x_ = [$id; $n]; | ||
//~^ ERROR: allocating a local array larger than 512000 bytes | ||
_x_ | ||
}}; | ||
} | ||
|
||
let x = [0u32; 50_000]; | ||
let y = vec![x, x, x, x, x]; | ||
let y = vec![dummy![x, x, x, x, x]]; | ||
let y = vec![dummy![[x, x, x, x, x]]]; | ||
let y = dummy![x, x, x, x, x]; | ||
let y = [x, x, dummy!(x), x, x]; | ||
//~^ ERROR: allocating a local array larger than 512000 bytes | ||
let y = dummy![x => x]; | ||
let y = dummy![x;5]; | ||
let y = dummy!(vec![dummy![x, x, x, x, x]]); | ||
let y = dummy![[x, x, x, x, x]]; | ||
//~^ ERROR: allocating a local array larger than 512000 bytes | ||
|
||
let y = proc_macros::make_it_big!([x; 1]); | ||
//~^ ERROR: allocating a local array larger than 512000 bytes | ||
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well... in this test case, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, runing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess that those occurrences are the result of incorrect |
||
let y = vec![proc_macros::make_it_big!([x; 10])]; | ||
let y = vec![create_then_move![x; 5]; 5]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
therefore I have to use this hacky way to check, but I don't know if this can always work or just coincidentally succeed in my specific test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this hack is good enough.
quote_spanned
is sadly pretty bad for rust tools, we just have to hope that users ofquote_spanned
understand what they're doing