Skip to content

Commit 2705d62

Browse files
committed
Modify tests to account for the new allow-by-default needless_pass_by_ref_mut
1 parent 3f0da4d commit 2705d62

13 files changed

+80
-74
lines changed

tests/ui/infinite_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@no-rustfix
2+
#![warn(clippy::needless_pass_by_ref_mut)]
23

34
fn fn_val(i: i32) -> i32 {
45
unimplemented!()

tests/ui/infinite_loop.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: variables in the condition are not mutated in the loop body
2-
--> $DIR/infinite_loop.rs:24:11
2+
--> $DIR/infinite_loop.rs:25:11
33
|
44
LL | while y < 10 {
55
| ^^^^^^
@@ -8,71 +8,71 @@ LL | while y < 10 {
88
= note: `#[deny(clippy::while_immutable_condition)]` on by default
99

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

1818
error: variables in the condition are not mutated in the loop body
19-
--> $DIR/infinite_loop.rs:40:11
19+
--> $DIR/infinite_loop.rs:41:11
2020
|
2121
LL | while !cond {
2222
| ^^^^^
2323
|
2424
= note: this may lead to an infinite or to a never running loop
2525

2626
error: variables in the condition are not mutated in the loop body
27-
--> $DIR/infinite_loop.rs:86:11
27+
--> $DIR/infinite_loop.rs:87:11
2828
|
2929
LL | while i < 3 {
3030
| ^^^^^
3131
|
3232
= note: this may lead to an infinite or to a never running loop
3333

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

4242
error: variables in the condition are not mutated in the loop body
43-
--> $DIR/infinite_loop.rs:99:11
43+
--> $DIR/infinite_loop.rs:100:11
4444
|
4545
LL | while i < 3 {
4646
| ^^^^^
4747
|
4848
= note: this may lead to an infinite or to a never running loop
4949

5050
error: variables in the condition are not mutated in the loop body
51-
--> $DIR/infinite_loop.rs:116:11
51+
--> $DIR/infinite_loop.rs:117:11
5252
|
5353
LL | while i < 3 {
5454
| ^^^^^
5555
|
5656
= note: this may lead to an infinite or to a never running loop
5757

5858
error: variables in the condition are not mutated in the loop body
59-
--> $DIR/infinite_loop.rs:123:11
59+
--> $DIR/infinite_loop.rs:124:11
6060
|
6161
LL | while i < 3 {
6262
| ^^^^^
6363
|
6464
= note: this may lead to an infinite or to a never running loop
6565

6666
error: variables in the condition are not mutated in the loop body
67-
--> $DIR/infinite_loop.rs:191:15
67+
--> $DIR/infinite_loop.rs:192:15
6868
|
6969
LL | while self.count < n {
7070
| ^^^^^^^^^^^^^^
7171
|
7272
= note: this may lead to an infinite or to a never running loop
7373

7474
error: variables in the condition are not mutated in the loop body
75-
--> $DIR/infinite_loop.rs:201:11
75+
--> $DIR/infinite_loop.rs:202:11
7676
|
7777
LL | while y < 10 {
7878
| ^^^^^^
@@ -82,7 +82,7 @@ LL | while y < 10 {
8282
= help: rewrite it as `if cond { loop { } }`
8383

8484
error: variables in the condition are not mutated in the loop body
85-
--> $DIR/infinite_loop.rs:210:11
85+
--> $DIR/infinite_loop.rs:211:11
8686
|
8787
LL | while y < 10 {
8888
| ^^^^^^
@@ -92,7 +92,7 @@ LL | while y < 10 {
9292
= help: rewrite it as `if cond { loop { } }`
9393

9494
error: this argument is a mutable reference, but not used mutably
95-
--> $DIR/infinite_loop.rs:9:17
95+
--> $DIR/infinite_loop.rs:10:17
9696
|
9797
LL | fn fn_mutref(i: &mut i32) {
9898
| ^^^^^^^^ help: consider changing to: `&i32`

tests/ui/let_underscore_future.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(clippy::needless_pass_by_ref_mut)]
12
use std::future::Future;
23
//@no-rustfix
34
async fn some_async_fn() {}

tests/ui/let_underscore_future.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: non-binding `let` on a future
2-
--> $DIR/let_underscore_future.rs:16:5
2+
--> $DIR/let_underscore_future.rs:17:5
33
|
44
LL | let _ = some_async_fn();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -9,23 +9,23 @@ LL | let _ = some_async_fn();
99
= help: to override `-D warnings` add `#[allow(clippy::let_underscore_future)]`
1010

1111
error: non-binding `let` on a future
12-
--> $DIR/let_underscore_future.rs:18:5
12+
--> $DIR/let_underscore_future.rs:19:5
1313
|
1414
LL | let _ = custom();
1515
| ^^^^^^^^^^^^^^^^^
1616
|
1717
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`
1818

1919
error: non-binding `let` on a future
20-
--> $DIR/let_underscore_future.rs:23:5
20+
--> $DIR/let_underscore_future.rs:24:5
2121
|
2222
LL | let _ = future;
2323
| ^^^^^^^^^^^^^^^
2424
|
2525
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`
2626

2727
error: this argument is a mutable reference, but not used mutably
28-
--> $DIR/let_underscore_future.rs:11:35
28+
--> $DIR/let_underscore_future.rs:12:35
2929
|
3030
LL | fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future<Output = ()>`

tests/ui/mut_key.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(clippy::needless_pass_by_ref_mut)]
12
use std::cell::Cell;
23
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
34
use std::hash::{Hash, Hasher};

tests/ui/mut_key.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: mutable key type
2-
--> $DIR/mut_key.rs:31:32
2+
--> $DIR/mut_key.rs:32:32
33
|
44
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,103 +8,103 @@ LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> Hash
88
= help: to override `-D warnings` add `#[allow(clippy::mutable_key_type)]`
99

1010
error: mutable key type
11-
--> $DIR/mut_key.rs:31:72
11+
--> $DIR/mut_key.rs:32:72
1212
|
1313
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
1414
| ^^^^^^^^^^^^
1515

1616
error: mutable key type
17-
--> $DIR/mut_key.rs:37:5
17+
--> $DIR/mut_key.rs:38:5
1818
|
1919
LL | let _other: HashMap<Key, bool> = HashMap::new();
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2121

2222
error: mutable key type
23-
--> $DIR/mut_key.rs:65:22
23+
--> $DIR/mut_key.rs:66:22
2424
|
2525
LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
error: mutable key type
29-
--> $DIR/mut_key.rs:78:5
29+
--> $DIR/mut_key.rs:79:5
3030
|
3131
LL | let _map = HashMap::<Cell<usize>, usize>::new();
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333

3434
error: mutable key type
35-
--> $DIR/mut_key.rs:80:5
35+
--> $DIR/mut_key.rs:81:5
3636
|
3737
LL | let _map = HashMap::<&mut Cell<usize>, usize>::new();
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: mutable key type
41-
--> $DIR/mut_key.rs:82:5
41+
--> $DIR/mut_key.rs:83:5
4242
|
4343
LL | let _map = HashMap::<&mut usize, usize>::new();
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545

4646
error: mutable key type
47-
--> $DIR/mut_key.rs:85:5
47+
--> $DIR/mut_key.rs:86:5
4848
|
4949
LL | let _map = HashMap::<Vec<Cell<usize>>, usize>::new();
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
error: mutable key type
53-
--> $DIR/mut_key.rs:87:5
53+
--> $DIR/mut_key.rs:88:5
5454
|
5555
LL | let _map = HashMap::<BTreeMap<Cell<usize>, ()>, usize>::new();
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5757

5858
error: mutable key type
59-
--> $DIR/mut_key.rs:89:5
59+
--> $DIR/mut_key.rs:90:5
6060
|
6161
LL | let _map = HashMap::<BTreeMap<(), Cell<usize>>, usize>::new();
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363

6464
error: mutable key type
65-
--> $DIR/mut_key.rs:91:5
65+
--> $DIR/mut_key.rs:92:5
6666
|
6767
LL | let _map = HashMap::<BTreeSet<Cell<usize>>, usize>::new();
6868
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969

7070
error: mutable key type
71-
--> $DIR/mut_key.rs:93:5
71+
--> $DIR/mut_key.rs:94:5
7272
|
7373
LL | let _map = HashMap::<Option<Cell<usize>>, usize>::new();
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7575

7676
error: mutable key type
77-
--> $DIR/mut_key.rs:95:5
77+
--> $DIR/mut_key.rs:96:5
7878
|
7979
LL | let _map = HashMap::<Option<Vec<Cell<usize>>>, usize>::new();
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8181

8282
error: mutable key type
83-
--> $DIR/mut_key.rs:97:5
83+
--> $DIR/mut_key.rs:98:5
8484
|
8585
LL | let _map = HashMap::<Result<&mut usize, ()>, usize>::new();
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
error: mutable key type
89-
--> $DIR/mut_key.rs:100:5
89+
--> $DIR/mut_key.rs:101:5
9090
|
9191
LL | let _map = HashMap::<Box<Cell<usize>>, usize>::new();
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9393

9494
error: mutable key type
95-
--> $DIR/mut_key.rs:102:5
95+
--> $DIR/mut_key.rs:103:5
9696
|
9797
LL | let _map = HashMap::<Rc<Cell<usize>>, usize>::new();
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9999

100100
error: mutable key type
101-
--> $DIR/mut_key.rs:104:5
101+
--> $DIR/mut_key.rs:105:5
102102
|
103103
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new();
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105105

106106
error: this argument is a mutable reference, but not used mutably
107-
--> $DIR/mut_key.rs:31:32
107+
--> $DIR/mut_key.rs:32:32
108108
|
109109
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&HashMap<Key, usize>`

tests/ui/mut_reference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(unused_variables, dead_code)]
2+
#![warn(clippy::needless_pass_by_ref_mut)]
23
//@no-rustfix
34
fn takes_an_immutable_reference(a: &i32) {}
45
fn takes_a_mutable_reference(a: &mut i32) {}

tests/ui/mut_reference.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
2-
--> $DIR/mut_reference.rs:32:34
2+
--> $DIR/mut_reference.rs:33:34
33
|
44
LL | takes_an_immutable_reference(&mut 42);
55
| ^^^^^^^
@@ -8,19 +8,19 @@ LL | takes_an_immutable_reference(&mut 42);
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]`
99

1010
error: the function `as_ptr` doesn't need a mutable reference
11-
--> $DIR/mut_reference.rs:36:12
11+
--> $DIR/mut_reference.rs:37:12
1212
|
1313
LL | as_ptr(&mut 42);
1414
| ^^^^^^^
1515

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

2222
error: this argument is a mutable reference, but not used mutably
23-
--> $DIR/mut_reference.rs:24:44
23+
--> $DIR/mut_reference.rs:25:44
2424
|
2525
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
2626
| ^^^^^^^^ help: consider changing to: `&i32`

tests/ui/needless_pass_by_ref_mut.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)]
2+
#![warn(clippy::needless_pass_by_ref_mut)]
23
#![feature(lint_reasons)]
34
//@no-rustfix
45
use std::ptr::NonNull;

0 commit comments

Comments
 (0)