rust-clippy/tests
bors 062b66d45c Auto merge of #12892 - meithecatte:needless-borrows-mutrefs, r=xFrednet
needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in #12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, #12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus #12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes #12856

changelog: none
2024-07-25 18:48:27 +00:00
..
test_utils
ui Auto merge of #12892 - meithecatte:needless-borrows-mutrefs, r=xFrednet 2024-07-25 18:48:27 +00:00
ui-cargo Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into clippy-subtree-update 2024-06-27 18:56:04 +02:00
ui-internal Refactor for using config values: 2024-07-17 14:05:49 -04:00
ui-toml Refactor for using config values: 2024-07-17 14:05:49 -04:00
workspace_test
check-fmt.rs
clippy.toml
compile-test.rs Fix running compile-test under cargo nextest 2024-07-23 16:15:54 +00:00
dogfood.rs Show progress while running dogfood test 2024-07-17 12:29:18 +00:00
headers.rs
integration.rs [pathbuf_init_then_push]: Checks for calls to push immediately after creating a new PathBuf 2024-07-21 14:22:48 +08:00
lint_message_convention.rs Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00
missing-test-files.rs Merge commit '93f0a9a91f58c9b2153868f458402155fb6265bb' into clippy-subtree-update 2024-03-07 17:19:29 +01:00
versioncheck.rs
workspace.rs Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00