-
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
unused_variables
and unused_assignments
lints do not catch array usage
#65467
Comments
Adding T-Lang for the "do we want to do this" aspect of the lint beyond it's execution (T-Compiler).
The current behavior is expected. These lints are defined through a liveness analysis done on HIR rather than MIR and understanding arrays specially on HIR might not be worth the impl complexity. |
However, @eddyb suggested that we rewrite liveness to work on MIR instead and then we should be able to make this work and then some. Cc @nikomatsakis @matthewjasper @tmandry |
If we extend |
My opinion is that it would be good to detect cases like this -- probably we could say that any write to the 'owned content' of a variable suffices. I agree it'd probably be somewhat easier to do this sort of thing on MIR -- certainly I consider the existing 'liveness' code to be in need of a rewrite. There are some questions as to how smart we want to be. One could imagine for example warning on a case like this let mut foo =(0, 0);
foo.0 = 22;
println!("{}", foo.1); Here, the write to |
It seems to me that declaring |
More examples, here neither #[derive(Copy, Clone)]
pub struct Foo {
pub foo: usize,
}
pub fn foo(src: Foo) {
let mut q = src;
q.foo = 12;
} let mut foo = (0, 0);
foo.0 = 22; |
I've linked a couple Clippy issues to this, for more examples. Also it might be good to detect unused |
I recently had a problem where I was accidentally implicitly copying an array with
if let
bindings, and the writes to the original array were never made (I needed to addref
in my bindings). I thought it was strange that there was no warnings for this, and noticed this is true for these lints in general. Here's a small reproduction (also on the playground).I would expect these lints to fire here, is this expected behavior? I tried a quick search and wasn't able to find an existing issue.
The text was updated successfully, but these errors were encountered: