account for doc visibility
This fixes#4608.
Also I noticed that the lint failed to look at trait and impl items. There's a small bit of fallout in the code, too, but not enough to warrant its own commit.
changelog: check docs of trait items and impl items, also make `missing_safety_doc` account for visibility
Fix false-positive of redundant_clone and move to clippy::perf
This PR introduces dataflow analysis to `redundant_clone` lint to filter out borrowed variables, which had been incorrectly detected.
Depends on https://github.com/rust-lang/rust/pull/64207.
changelog: Moved `redundant_clone` lint to `perf` group
# What this lint catches
## `clone`/`to_owned`
```rust
let s = String::new();
let t = s.clone();
```
```rust
// MIR
_1 = String::new();
_2 = &_1;
_3 = clone(_2); // (*)
```
We can turn this `clone` call into a move if
1. `_2` is the sole borrow of `_1` at the statement `(*)`
2. `_1` is not used hereafter
## `Deref` + type-specific `to_owned` method
```rust
let s = std::path::PathBuf::new();
let t = s.to_path_buf();
```
```rust
// MIR
_1 = PathBuf::new();
_2 = &1;
_3 = call deref(_2);
_4 = _3; // Copies borrow
StorageDead(_2);
_5 = Path::to_path_buf(_4); // (*)
```
We can turn this `to_path_buf` call into a move if
1. `_3` `_4` are the sole borrow of `_1` at `(*)`
2. `_1` is not used hereafter
# What this PR introduces
1. `MaybeStorageLive` that determines whether a local lives at a particular location
2. `PossibleBorrowerVisitor` that constructs [`TransitiveRelation`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/transitive_relation/struct.TransitiveRelation.html) of possible borrows, e.g. visiting `_2 = &1; _3 = &_2:` will result in `_3 -> _2 -> _1` relation. Then `_3` and `_2` will be counted as possible borrowers of `_1` in the sole-borrow analysis above.
Our lint deprecation previously didn't work for tool lints, because
`register_removed` was registering lints to be removed _without_ the
`clippy` prefix.
This adds a check to `clippy_dev` that enforces a maximum line count for
`stderr` files. CI will fail if the line count is exceeded. It's
currently set to `320` lines.
Ideally this would be implemented in `compiletest-rs` but there are
plans to move Rust's `compiletest` into the `compiletest-rs` repository
and I don't want to do the work in `compiletest` twice. However, I also
don't want to wait until the move is done, so I added the check to
`clippy_dev` until it makes sense to add it to compiletest-rs.
cc #2038
This finishes up the rewrite of `update_lints.py` in Rust. More
specifically, this
* adds the `--check` flag and handling to clippy_dev
* tracks file changes over the different calls to `replace_region_in_file`
* only writes changes to files if the `--check` flag is *not* used
* runs `./util/dev update_lints --check` on CI instead of the old script
* replaces usage of the `update_lints.py` script with an error
`./util/dev update_lints` behaves 99% the same as the python script.
The only difference that I'm aware of is an ordering change to
`clippy_lints/src/lib.rs` because underscores seem to be sorted
differently in Rust and in Python.
🏁
3399: RIIR update lints: Generate modules section and lint group sections r=flip1995 a=phansch
This adds the last missing parts of the generating code.
cc #2882
Co-authored-by: Philipp Hansch <dev@phansch.net>
The update script now also generates the 'register_removed' section in
`clippy_lints/src/lib.rs`.
Also, instead of using `let mut store ...`, I added a new identifier
line so that the replacement will continue to work in case `let mut
store ...` ever changes.