-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Cargo fix will rename unused idents in macros even when used elsewhere #117284
Comments
I went ahead and ran #[allow(unused)]
struct MyStruct {
var: i32,
}
fn main() {
let s = MyStruct { var: 42 };
let var = s.var;
} (I cleaned up the expanded code slightly, but it is the same) Looking at the expanded code, it makes me think that macro_rules! make_var {
($struct:ident, $var:ident) => {
let var2 = $struct.$var;
};
}
#[allow(unused)]
struct MyStruct {
var: i32,
}
fn main() {
let s = MyStruct { var: 42 };
make_var!(s, var);
}
To me, this seems like a problem with |
Transferred to rust-lang/rust, since the suggestions are generated by the compiler. |
@Muscraft rust/compiler/rustc_passes/src/liveness.rs Line 1660 in 160fd3c
Maybe we only point out that there is an unused variable coming from |
The quick and straightforward way to fix this would be to only emit the suggestion in this lint if the span has the root context, but then a subset of valid suggestions wouldn't be emitted. I had an older PR that I'm having trouble finding that would automatically do that for every diagnostic, but IIRC it had some negative perf impact when not implementing it very simplistic. In this rust/compiler/rustc_passes/src/liveness.rs Lines 1660 to 1675 in 160fd3c
we can probably instead check that all of the spans involved have the same |
…d-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? `@estebank`
…d-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? ``@estebank``
…d-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? ```@estebank```
…d-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? ````@estebank````
Rollup merge of rust-lang#117390 - chenyukang:yukang-fix-117284-unused-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? ````@estebank````
Problem
Consider the following
src/main.rs
file in a cargo package:Cargo will warn that
var
is not used. Upon runningcargo fix
, cargo will change the second parameter fromvar
to_var
, making the compilation fail. Even worse, ifMyStruct
contained a field_var
thencargo fix
would change the variable without producing any warning.Steps
main.rs
cargo fix
(presumably with--allow-dirty
)Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: