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
[useless_vec
]: use the source span for initializer
#11081
Conversation
r? @Manishearth (rustbot has picked a reviewer for you, use r? to override) |
We could do with some tests for some various other macro combinations, e.g. macro_rules! in_macro {
($e:expr, $vec:expr) => {{
for _ in vec![1] {}
for _ in vec![$e] {}
for _ in $vec {}
}}
}
m!(1, vec![1]);
macro_rules! from_macro {
() => { vec![1, 2, 3] }
}
for _ in from_macro!() {} |
@Alexendoo Regarding the |
@bors r+ r=me to fix the issue but i agree that we should add more tests |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
[`useless_vec`]: add more tests and don't lint inside of macros Closes #11084. I realized that the fix I added in #11081 itself also causes an error in a suggestion when inside of a macro. Example: ```rs macro_rules! x { () => { for _ in vec![1, 2] {} } } x!(); ``` Here it would suggest replacing `vec![1, 2]` with `[x!()]`, because that's what the source callsite is (reminder: it does this to get the correct span of `x!()` for code like `for _ in vec![x!()]`), but that's wrong when *inside* macros, so I decided to make it not lint if the whole loop construct is inside a macro to avoid this issue. changelog: [`useless_vec`]: add more tests and don't lint inside of macros r? `@Alexendoo` since these were your tests, I figured it makes most sense to assign you
Fixes #11075.
changelog: [
useless_vec
]: use the source span for the initializer expression when inside of a macro