rust-lang / rust-lang/rust-clippy
False positive on 'useless_let_if_seq'
Open
Nobody has claimed this yet.
S-needs-discussion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
When I ran cargo clippy against rustfmt repository, I got the following suggestion, which is incorrect:
warning: `if _ { .. } else { .. }` is an expression
--> src/visitor.rs:189:9
|
189 | / let mut unindent_comment = self.is_if_else_block && !b.stmts.is_empty();
190 | | if unindent_comment {
191 | | let end_pos = source!(self, b.span).hi() - brace_compensation - remove_len;
192 | | let snippet = self.snippet(mk_sp(self.last_pos, end_pos));
193 | | unindent_comment = snippet.contains("//") || snippet.contains("/*");
194 | | }
| |_________^ help: it is more idiomatic to write: `let <mut> unindent_comment = if unindent_comment { ..; snippet.contains("//") || snippet.contains("/*") } else { self.is_if_else_block && !b.stmts.is_empty() };`
|
= note: #[warn(useless_let_if_seq)] on by default
= note: you might not need `mut` at all
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.166/index.html#useless_let_if_seq
This looks similar to #975.
I am using 0.0.166.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report by running cargo clippy against the rustfmt repository, then inspect src/visitor.rs around line 189 and the useless_let_if_seq lint. Compare the behavior with issue #975; done means the shown conditional reassignment no longer produces an incorrect suggestion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100