fix 5707
changelog: ``[`redundant_clone`]``, fix#5707
# Root problem of #5707 :
```
&2:&mut HashMap = &mut _4;
&3:&str = & _5;
_1 = HashMap::insert(move _2,move _3, _);
```
generate PossibleBorrower(_2,_1) and PossibleBorrower(_3,_1).
However, it misses PossibleBorrower(_3,_2).
# My solution to #5707 :
When meet a function call, we should:
1. build PossibleBorrower between borrow parameters and return value (currently)
2. build PossibleBorrower between immutable borrow parameters and mutable borrow parameters (*add*)
3. build PossibleBorrower inside mutable borrow parameters (*add*)
For example:
```
_2: &mut _22;
_3: &mut _;
_4: & _;
_5: & _;
_1 = call(move _2, move _3, move _4, move _5);
```
we need to build
1. return value with parameter(current implementataion)
PossibleBorrower(_2,_1)
PossibleBorrower(_3,_1)
PossibleBorrower(_4,_1)
PossibleBorrower(_5,_1)
2. between mutable borrow and immutable borrow
PossibleBorrower(_4,_2)
PossibleBorrower(_5,_2)
PossibleBorrower(_4,_3)
PossibleBorrower(_5,_3)
3. between mutable borrow and mutable borrow
PossibleBorrower(_3,_2)
PossibleBorrower(_2,_3)
But that's not enough.
Modification to _2 actually apply to _22.
So I write a `PossibleBorrowed` visitor, which tracks (borrower => possible borrowed) relation.
For example (_2 => _22).
However, a lot of problems exist here.
## Known Problems:
1. not sure all `&mut`'s origin are collected.
I'm not sure how to deal with `&mut` when meet a function call, so I didn't do it currently.
Also, my implement is not flow sensitive, so it's not accurate.
```
foo(_2:&mut _, _3: &_)
```
This pr doesn't count _3 as origin of _2.
2. introduce false negative
`foo(_2, _3)` will emit PossibleBorrower(_3,_2) in this pr, but _3 and _2 may not have relation.
Clippy may feel that _3 is still in use because of _2, but actually, _3 is on longer needed and can be moved.
## Insight
The key problem is determine where every `&mut` come from accurately.
I think Polonius is an elegant solution to it. Polonius is flow sensitive and accurate.
But I'm uncertain about whether we can import Polonius in rust-clippy currently.
This pr actually is part of Polonius' functionality, I think.
# TODO
1. `cargo test` can't pass yet due to similar variable name
Fix internal `default_hash_types` lint to use resolved path
I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
Refactor `format_args!` expansion parsing
Introduces `FormatExpn::parse` and `FormatArgsExpn::parse`. Motivated by rust-lang/rust#83302, so I only have to change Clippy in one place. Fixed an FP along the way.
I also allowed `needless_bool` in macros because I often want to do `if_chain! { .. then { true } else { false } }`.
changelog: Fix false positive in `useless_format` when some text is appended or prepended to a single string with some useless formatting params
changelog: Allow `needless_bool` in macros
Remove lints_enabled
r? `@camsteffen`
cc https://github.com/rust-lang/rust-clippy/pull/7448#issuecomment-876497862
I haven't added a variant with `last_node_with_lint_attrs` yet, since I didn't see a usecase for this. Also this field is not documented, so I'm wondering how it behaves with command line lints and so on.
changelog: none
Rename run_lints -> lints_enabled
Just a quick rename of a utilities function. `run_lints` kinda suggested that the lints were run by this function. But the only thing this function does is to check if the lints are enabled in the context of the `hir_id`
changelog: none
Fix false-positive `assert` in `panic`
This PR fixes a false-positive in `clippy::panic` when using the `assert` macro with its optional message parameter.
Fixes: #7433
changelog: `panic_unimplemented.rs`: added condition to exclude `assert` macro, similar to `debug_assert`
changelog: `panicking_macros.rs`: relevant tests to check for `assert` usage.
Add new lint: `strlen_on_c_strings`
~~This is WIP, linting in case of `CString` has been added, but for `CStr`, its diagnostic item needs to be available for clippy.
[PR that adds diagnostic item for CStr on rust repo](https://github.com/rust-lang/rust/pull/85439).~~
Ready for the review. Please take a look.
fixes#7145
changelog: Add new lint: `strlen_on_c_strings`, that lints on `libc::strlen(some_cstring.as_ptr())`
Downgrade nonstandard_macro_braces to nursery
Due to the large number of crates impacted by #7422, I don't think this lint can be enabled by default right now until the false positive is fixed.
---
changelog: remove [`nonstandard_macro_braces`] from default set of enabled lints