Skip to content

Commit

Permalink
Auto merge of #117757 - flip1995:clippy-beta-backport, r=cuviper
Browse files Browse the repository at this point in the history
[beta] Clippy beta backport

Follow-up to the stable backport done in
- #116364: d3f6573

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed Nov 10, 2023
2 parents fbf0758 + a46e1c9 commit 22d4a4f
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.72.0"]
pub NEEDLESS_PASS_BY_REF_MUT,
suspicious,
nursery,
"using a `&mut` argument when it's not mutated"
}

Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/infinite_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fn fn_constref(i: &i32) -> i32 {
unimplemented!()
}
fn fn_mutref(i: &mut i32) {
//~^ ERROR: this argument is a mutable reference, but not used mutably
//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
unimplemented!()
}
fn fooi() -> i32 {
Expand Down
33 changes: 12 additions & 21 deletions src/tools/clippy/tests/ui/infinite_loop.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:24:11
--> $DIR/infinite_loop.rs:22:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -8,71 +8,71 @@ LL | while y < 10 {
= note: `#[deny(clippy::while_immutable_condition)]` on by default

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:31:11
--> $DIR/infinite_loop.rs:29:11
|
LL | while y < 10 && x < 3 {
| ^^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:40:11
--> $DIR/infinite_loop.rs:38:11
|
LL | while !cond {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:86:11
--> $DIR/infinite_loop.rs:84:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:93:11
--> $DIR/infinite_loop.rs:91:11
|
LL | while i < 3 && j > 0 {
| ^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:99:11
--> $DIR/infinite_loop.rs:97:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:116:11
--> $DIR/infinite_loop.rs:114:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:123:11
--> $DIR/infinite_loop.rs:121:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:191:15
--> $DIR/infinite_loop.rs:189:15
|
LL | while self.count < n {
| ^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:201:11
--> $DIR/infinite_loop.rs:199:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -82,7 +82,7 @@ LL | while y < 10 {
= help: rewrite it as `if cond { loop { } }`

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:210:11
--> $DIR/infinite_loop.rs:208:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -91,14 +91,5 @@ LL | while y < 10 {
= note: this loop contains `return`s or `break`s
= help: rewrite it as `if cond { loop { } }`

error: this argument is a mutable reference, but not used mutably
--> $DIR/infinite_loop.rs:9:17
|
LL | fn fn_mutref(i: &mut i32) {
| ^^^^^^^^ help: consider changing to: `&i32`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]`

error: aborting due to 12 previous errors
error: aborting due to 11 previous errors

2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/let_underscore_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fn custom() -> impl Future<Output = ()> {
}

fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
//~^ ERROR: this argument is a mutable reference, but not used mutably
//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`

fn main() {
let _ = some_async_fn();
Expand Down
17 changes: 4 additions & 13 deletions src/tools/clippy/tests/ui/let_underscore_future.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:16:5
--> $DIR/let_underscore_future.rs:14:5
|
LL | let _ = some_async_fn();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,29 +9,20 @@ LL | let _ = some_async_fn();
= help: to override `-D warnings` add `#[allow(clippy::let_underscore_future)]`

error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:18:5
--> $DIR/let_underscore_future.rs:16:5
|
LL | let _ = custom();
| ^^^^^^^^^^^^^^^^^
|
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`

error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:23:5
--> $DIR/let_underscore_future.rs:21:5
|
LL | let _ = future;
| ^^^^^^^^^^^^^^^
|
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`

error: this argument is a mutable reference, but not used mutably
--> $DIR/let_underscore_future.rs:11:35
|
LL | fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future<Output = ()>`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/mut_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<K
//~^ ERROR: mutable key type
//~| NOTE: `-D clippy::mutable-key-type` implied by `-D warnings`
//~| ERROR: mutable key type
//~| ERROR: this argument is a mutable reference, but not used mutably
//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
let _other: HashMap<Key, bool> = HashMap::new();
//~^ ERROR: mutable key type
m.keys().cloned().collect()
Expand Down
41 changes: 16 additions & 25 deletions src/tools/clippy/tests/ui/mut_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,103 +14,94 @@ LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> Hash
| ^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:37:5
--> $DIR/mut_key.rs:35:5
|
LL | let _other: HashMap<Key, bool> = HashMap::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:65:22
--> $DIR/mut_key.rs:63:22
|
LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:78:5
--> $DIR/mut_key.rs:76:5
|
LL | let _map = HashMap::<Cell<usize>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:80:5
--> $DIR/mut_key.rs:78:5
|
LL | let _map = HashMap::<&mut Cell<usize>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:82:5
--> $DIR/mut_key.rs:80:5
|
LL | let _map = HashMap::<&mut usize, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:85:5
--> $DIR/mut_key.rs:83:5
|
LL | let _map = HashMap::<Vec<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:87:5
--> $DIR/mut_key.rs:85:5
|
LL | let _map = HashMap::<BTreeMap<Cell<usize>, ()>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:89:5
--> $DIR/mut_key.rs:87:5
|
LL | let _map = HashMap::<BTreeMap<(), Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:91:5
--> $DIR/mut_key.rs:89:5
|
LL | let _map = HashMap::<BTreeSet<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:93:5
--> $DIR/mut_key.rs:91:5
|
LL | let _map = HashMap::<Option<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:95:5
--> $DIR/mut_key.rs:93:5
|
LL | let _map = HashMap::<Option<Vec<Cell<usize>>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:97:5
--> $DIR/mut_key.rs:95:5
|
LL | let _map = HashMap::<Result<&mut usize, ()>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:100:5
--> $DIR/mut_key.rs:98:5
|
LL | let _map = HashMap::<Box<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:102:5
--> $DIR/mut_key.rs:100:5
|
LL | let _map = HashMap::<Rc<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: mutable key type
--> $DIR/mut_key.rs:104:5
--> $DIR/mut_key.rs:102:5
|
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this argument is a mutable reference, but not used mutably
--> $DIR/mut_key.rs:31:32
|
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&HashMap<Key, usize>`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]`

error: aborting due to 18 previous errors
error: aborting due to 17 previous errors

2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/mut_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ impl MyStruct {
fn takes_an_immutable_reference(&self, a: &i32) {}

fn takes_a_mutable_reference(&self, a: &mut i32) {}
//~^ ERROR: this argument is a mutable reference, but not used mutably
//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
}

#[warn(clippy::unnecessary_mut_passed)]
Expand Down
17 changes: 4 additions & 13 deletions src/tools/clippy/tests/ui/mut_reference.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
--> $DIR/mut_reference.rs:32:34
--> $DIR/mut_reference.rs:30:34
|
LL | takes_an_immutable_reference(&mut 42);
| ^^^^^^^
Expand All @@ -8,25 +8,16 @@ LL | takes_an_immutable_reference(&mut 42);
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]`

error: the function `as_ptr` doesn't need a mutable reference
--> $DIR/mut_reference.rs:36:12
--> $DIR/mut_reference.rs:34:12
|
LL | as_ptr(&mut 42);
| ^^^^^^^

error: the method `takes_an_immutable_reference` doesn't need a mutable reference
--> $DIR/mut_reference.rs:41:44
--> $DIR/mut_reference.rs:39:44
|
LL | my_struct.takes_an_immutable_reference(&mut 42);
| ^^^^^^^

error: this argument is a mutable reference, but not used mutably
--> $DIR/mut_reference.rs:24:44
|
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
| ^^^^^^^^ help: consider changing to: `&i32`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)]
#![warn(clippy::needless_pass_by_ref_mut)]
#![feature(lint_reasons)]
//@no-rustfix
use std::ptr::NonNull;
Expand Down
Loading

0 comments on commit 22d4a4f

Please sign in to comment.