-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
False dead_code warning on struct pattern match #56750
Comments
Issue can be followed at rust-lang/rust#56750.
@nvzqz Thanks for the report! We recently changed the wording to say "never constructed" rather than "never used" in the hopes of clarifying that the liveness analysis doesn't consider destructuring patterns as "live," but the existence of this Issue would seem to suggest that this still isn't clear enough. 🙁 Part of me was tempted to call this #wontfix (as it wasn't obvious to me why it's useful to have a struct pattern without the struct being constructed anywhere else—what would realistically be on the other side of the match/assignment?), but your linked commit being a real-world counterexample makes me more sympathetic to changing the analysis to consider patterns "live." (As you point out, |
I noticed the warning for Thanks for taking my real-world case in that commit into account! |
Using a struct only for it to be destructured right away does indeed have its use cases, see also: https://github.com/danielhenrymantilla/fstrings-rs/blob/2de1a3db8d6bf6f9e33ea6eeef8468d75b329c83/src/proc_macro/mod.rs#L91-L94: let Args {
format_literal,
mut extra_args,
} = parse_macro_input!(input); // Args : Parse
|
Triage: no change |
Clippy v0.1.78 identifies this as dead code. However, further down in the same file, there is clearly a user: impl Handler<Result, Result> for Add { This might be yet another incarnation of rust-lang/rust#56750 Let's just mark it as intentionally dead-code, even if this is untrue, to make clippy happy again. Signed-off-by: Johannes Schindelin <[email protected]>
Clippy v0.1.78 identifies this as dead code. However, further down in the same file, there is clearly a user: impl Handler<Result, Result> for Add { This might be yet another incarnation of rust-lang/rust#56750 Let's just mark it as intentionally dead-code, even if this is untrue, to make clippy happy again. Signed-off-by: Johannes Schindelin <[email protected]>
* Enclose Markdown links in brackets The current clippy version (v0.1.78) says "you should put bare URLs between `<`/`>` or make a proper Markdown link" and refers to https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown Signed-off-by: Johannes Schindelin <[email protected]> * Enclose documentation item in backticks Clippy v0.1.78 complains about the IPv6 network mask, insisting that it is missing backticks. So backticks it gets. Signed-off-by: Johannes Schindelin <[email protected]> * Avoid error claiming `Add(usize)` is dead code Clippy v0.1.78 identifies this as dead code. However, further down in the same file, there is clearly a user: impl Handler<Result, Result> for Add { This might be yet another incarnation of rust-lang/rust#56750 Let's just mark it as intentionally dead-code, even if this is untrue, to make clippy happy again. Signed-off-by: Johannes Schindelin <[email protected]> --------- Signed-off-by: Johannes Schindelin <[email protected]>
The following code will emit a
dead_code
warning (playground):It states that
Value
is never constructed when in fact it has been within thelet Value { a, b }
pattern match.The text was updated successfully, but these errors were encountered: