diff options
| author | bors <bors@rust-lang.org> | 2021-04-05 19:00:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-05 19:00:41 +0000 |
| commit | d91da405df2dc33a8baf0a580ad564b94e53d835 (patch) | |
| tree | d1d12a0e10cc58e40c43e249670b0a2be843f36f /compiler/rustc_codegen_llvm/src | |
| parent | 1a45e437b8abb3f0e9fa056c26e8e52ed5d0ebd0 (diff) | |
| parent | a6f54f5dfdfdf0017ffecfbcd6f43352b8b71ca1 (diff) | |
| download | rust-d91da405df2dc33a8baf0a580ad564b94e53d835.tar.gz rust-d91da405df2dc33a8baf0a580ad564b94e53d835.zip | |
Auto merge of #6463 - xFrednet:5234-shared-code-in-if-blocks, r=phansch
New Lint: `branches_sharing_code`
This lint checks if all `if`-blocks contain some statements that are the same and can be moved out of the blocks to prevent code duplication. Here is an example:
```rust
let _ = if ... {
println!("Start"); // <-- Lint for code duplication
let _a = 99;
println!("End"); // <-- Lint for code duplication
false
} else {
println!("Start");
let _b = 17;
println!("End");
false
};
```
This could be written as:
```rust
println!("Start");
let _ = if ... {
let _a = 99;
false
} else {
let _b = 17;
false
};
println!("End");
```
---
This lint will get masked by the `IF_SAME_THEN_ELSE` lint. I think it makes more sense to only emit one lint per if block. This means that the folloing example:
```rust
if ... {
let _a = 17;
} else {
let _a = 17;
}
```
Will only trigger the `IF_SAME_THEN_ELSE` lint and not the `SHARED_CODE_IN_IF_BLOCKS` lint.
---
closes: #5234
changelog: Added a new lint: `branches_sharing_code`
And hello to the one that is writing the changelog for this release :D
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
