-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
Actually... on a second thought, this could still has FP when the some_macro!(vec![x, x, x, x, x]); But then if I check the first expanded macro call it will have FP with: vec![some_macro_that_reduces_x_frequency!(x;5)]; So, what will be the best approach here, do I need to check all the macro calls? |
We could check if the span of the |
Ok I see~ should I keep that newly added utils function tho? Since this solution won't need it anymore. oh wait... you meant check the root macro to see if it's |
I like the new function, it makes the code cleaner, so please keep it.
I meant to check the span of |
2d1d7b2
to
5824c4c
Compare
well... I though I can write such function-like macro to only produce some tokens, in this case So I'm guessing the |
There is the
I'd say so. We can just run lintcheck and see what it spits out :D |
6630ead
to
efef920
Compare
…t_macro_call` function in `clippy_utils`
027b1b3
to
e70c892
Compare
…r false help messages if in one.
let y = proc_macros::make_it_big!([x; 1]); | ||
//~^ ERROR: allocating a local array larger than 512000 bytes |
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.
Well... in this test case, the expr
being checked is [x; 1]
, but I guess since the span of 1
was used in quote_spanned
(?), for some reason even is_from_proc_macro(cx, expr)
fails.
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.
oh, runing lintcheck
has no differences unfortunately, both gives 4
occurrences lol
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 would guess that those occurrences are the result of incorrect quote_spanned
usage. Let's get this version merged for now.
/// Check if the span of `ArrayLen` of a repeat expression is within the expr's span, | ||
/// if not, meaning this repeat expr is definitely from some proc-macro. | ||
/// | ||
/// This is a fail-safe to a case where even the `is_from_proc_macro` is unable to determain the | ||
/// correct result. | ||
fn repeat_expr_might_be_expanded<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool { | ||
let ExprKind::Repeat(_, ArrayLen::Body(anon_const)) = expr.kind else { | ||
return false; | ||
}; | ||
let len_span = cx.tcx.def_span(anon_const.def_id); | ||
!expr.span.contains(len_span) | ||
} |
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 of quote_spanned
understand what they're doing
Thank you for the update :D @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #12586
this PR also adds a wrapper function
matching_root_macro_call
toclippy_utils::macros
, considering how often that same pattern appears in the codebase.(I'm always very indecisive towards naming, so, if anyone have better idea of how that function should be named, feel free to suggest it)
changelog: fix [
large_stack_arrays
] linting invec
macro; addmatching_root_macro_call
to clippy_utils