Invalid null usage v2
This is continuation of #6192 after inactivity.
I plan to move paths into the compiler as diagnostic items after this is merged.
fixes#1703
changelog: none
consider mutability on useless_vec suggestions
fixes#7035
changelog: Now the suggested by `useless_vec` considers mutability to suggest either `&[]`, as before, or `&mut []` if the used reference is mutable.
Don't trigger `same_item_push` if the vec is used in the loop body
fixes#6987
changelog: `same_item_push`: Don't trigger if the `vec` is used in the loop body
fix `missing_panics_doc` not detecting `assert_eq!` and `assert_ne!`
fixes#6997
changelog: `missing_panics_doc` detects `assert_eq!` and `assert_ne!`
---
searching for `assert_eq!` and `assert_ne!` in `FindPanicUnwrap`
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
Remove author requirement for `cargo_common_metadata`
This PR follows https://github.com/rust-lang/cargo/pull/9282, I'm not fully informed about all of this, it would be great if somebody knowledgeable about this topic agrees.
changelog: Changed `cargo_common_metadata` to stop linting on the optional author field.
* Added expression check for shared_code_in_if_blocks
* Finishing touches for the shared_code_in_if_blocks lint
* Applying PR suggestions
* Update lints yay
* Moved test into subfolder
Fix `redundant_clone` fp
fixes: #5973fixes: #5595fixes: #6998
changelog: Fix `redundant_clone` fp where the cloned value is modified while the clone is in use.
Lint: filter(Option::is_some).map(Option::unwrap)
Fixes#6061
*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog:
* add new lint for filter(Option::is_some).map(Option::unwrap)
First Rust PR, so I'm sure I've violated some idioms. Happy to change anything.
I'm getting one test failure locally -- a stderr diff for `compile_test`. I'm having a hard time seeing how I could be causing it, so I'm tentatively opening this in the hopes that it's an artifact of my local setup against `rustc`. Hoping it can at least still be reviewed in the meantime.
I'm gathering that since this is a method lint, and `.filter(...).map(...)` is already checked, the means of implementation needs to be a little different, so I didn't exactly follow the setup boilerplate. My way of checking for method calls seems a little too direct (ie, "is the second element of the expression literally the path for `Option::is_some`?"), but it seems like that's how some other lints work, so I went with it. I'm assuming we're not concerned about, eg, closures that just end up equivalent to `Option::is_some` by eta reduction.