Skip to content

Commit c62c7fa

Browse files
Update UI tests with new needless_pass_by_ref_mut lint
1 parent a43bea1 commit c62c7fa

26 files changed

+180
-96
lines changed

tests/ui-toml/toml_trivially_copy/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
33

44
#![warn(clippy::trivially_copy_pass_by_ref)]
5+
#![allow(clippy::needless_pass_by_ref_mut)]
56

67
#[derive(Copy, Clone)]
78
struct Foo(u8);

tests/ui-toml/toml_trivially_copy/test.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
2-
--> $DIR/test.rs:14:11
2+
--> $DIR/test.rs:15:11
33
|
44
LL | fn bad(x: &u16, y: &Foo) {}
55
| ^^^^ help: consider passing by value instead: `u16`
66
|
77
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
88

99
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
10-
--> $DIR/test.rs:14:20
10+
--> $DIR/test.rs:15:20
1111
|
1212
LL | fn bad(x: &u16, y: &Foo) {}
1313
| ^^^^ help: consider passing by value instead: `Foo`

tests/ui/borrow_box.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#![deny(clippy::borrowed_box)]
22
#![allow(dead_code, unused_variables)]
3-
#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
3+
#![allow(
4+
clippy::uninlined_format_args,
5+
clippy::disallowed_names,
6+
clippy::needless_pass_by_ref_mut
7+
)]
48

59
use std::fmt::Display;
610

tests/ui/borrow_box.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
2-
--> $DIR/borrow_box.rs:20:14
2+
--> $DIR/borrow_box.rs:24:14
33
|
44
LL | let foo: &Box<bool>;
55
| ^^^^^^^^^^ help: try: `&bool`
@@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
14-
--> $DIR/borrow_box.rs:24:10
14+
--> $DIR/borrow_box.rs:28:10
1515
|
1616
LL | foo: &'a Box<bool>,
1717
| ^^^^^^^^^^^^^ help: try: `&'a bool`
1818

1919
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
20-
--> $DIR/borrow_box.rs:28:17
20+
--> $DIR/borrow_box.rs:32:17
2121
|
2222
LL | fn test4(a: &Box<bool>);
2323
| ^^^^^^^^^^ help: try: `&bool`
2424

2525
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
26-
--> $DIR/borrow_box.rs:94:25
26+
--> $DIR/borrow_box.rs:98:25
2727
|
2828
LL | pub fn test14(_display: &Box<dyn Display>) {}
2929
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
3030

3131
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
32-
--> $DIR/borrow_box.rs:95:25
32+
--> $DIR/borrow_box.rs:99:25
3333
|
3434
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
3636

3737
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
38-
--> $DIR/borrow_box.rs:96:29
38+
--> $DIR/borrow_box.rs:100:29
3939
|
4040
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
4242

4343
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
44-
--> $DIR/borrow_box.rs:98:25
44+
--> $DIR/borrow_box.rs:102:25
4545
|
4646
LL | pub fn test17(_display: &Box<impl Display>) {}
4747
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
4848

4949
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
50-
--> $DIR/borrow_box.rs:99:25
50+
--> $DIR/borrow_box.rs:103:25
5151
|
5252
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
5454

5555
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
56-
--> $DIR/borrow_box.rs:100:29
56+
--> $DIR/borrow_box.rs:104:29
5757
|
5858
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
6060

6161
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
62-
--> $DIR/borrow_box.rs:105:25
62+
--> $DIR/borrow_box.rs:109:25
6363
|
6464
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`

tests/ui/infinite_loop.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: this argument is a mutable reference, but not used mutably
2+
--> $DIR/infinite_loop.rs:7:17
3+
|
4+
LL | fn fn_mutref(i: &mut i32) {
5+
| ^^^^^^^^ help: consider changing to: `&i32`
6+
|
7+
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
8+
19
error: variables in the condition are not mutated in the loop body
210
--> $DIR/infinite_loop.rs:20:11
311
|
@@ -91,5 +99,5 @@ LL | while y < 10 {
9199
= note: this loop contains `return`s or `break`s
92100
= help: rewrite it as `if cond { loop { } }`
93101

94-
error: aborting due to 11 previous errors
102+
error: aborting due to 12 previous errors
95103

tests/ui/let_underscore_future.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: this argument is a mutable reference, but not used mutably
2+
--> $DIR/let_underscore_future.rs:11:35
3+
|
4+
LL | fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future<Output = ()>`
6+
|
7+
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
8+
19
error: non-binding `let` on a future
210
--> $DIR/let_underscore_future.rs:14:5
311
|
@@ -23,5 +31,5 @@ LL | let _ = future;
2331
|
2432
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`
2533

26-
error: aborting due to 3 previous errors
34+
error: aborting due to 4 previous errors
2735

tests/ui/must_use_candidates.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//@run-rustfix
22
#![feature(never_type)]
3-
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
3+
#![allow(
4+
unused_mut,
5+
unused_tuple_struct_fields,
6+
clippy::redundant_allocation,
7+
clippy::needless_pass_by_ref_mut
8+
)]
49
#![warn(clippy::must_use_candidate)]
510
use std::rc::Rc;
611
use std::sync::atomic::{AtomicBool, Ordering};

tests/ui/must_use_candidates.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//@run-rustfix
22
#![feature(never_type)]
3-
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
3+
#![allow(
4+
unused_mut,
5+
unused_tuple_struct_fields,
6+
clippy::redundant_allocation,
7+
clippy::needless_pass_by_ref_mut
8+
)]
49
#![warn(clippy::must_use_candidate)]
510
use std::rc::Rc;
611
use std::sync::atomic::{AtomicBool, Ordering};

tests/ui/must_use_candidates.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: this function could have a `#[must_use]` attribute
2-
--> $DIR/must_use_candidates.rs:12:1
2+
--> $DIR/must_use_candidates.rs:17:1
33
|
44
LL | pub fn pure(i: u8) -> u8 {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
66
|
77
= note: `-D clippy::must-use-candidate` implied by `-D warnings`
88

99
error: this method could have a `#[must_use]` attribute
10-
--> $DIR/must_use_candidates.rs:17:5
10+
--> $DIR/must_use_candidates.rs:22:5
1111
|
1212
LL | pub fn inherent_pure(&self) -> u8 {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
1414

1515
error: this function could have a `#[must_use]` attribute
16-
--> $DIR/must_use_candidates.rs:48:1
16+
--> $DIR/must_use_candidates.rs:53:1
1717
|
1818
LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool`
2020

2121
error: this function could have a `#[must_use]` attribute
22-
--> $DIR/must_use_candidates.rs:60:1
22+
--> $DIR/must_use_candidates.rs:65:1
2323
|
2424
LL | pub fn rcd(_x: Rc<u32>) -> bool {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc<u32>) -> bool`
2626

2727
error: this function could have a `#[must_use]` attribute
28-
--> $DIR/must_use_candidates.rs:68:1
28+
--> $DIR/must_use_candidates.rs:73:1
2929
|
3030
LL | pub fn arcd(_x: Arc<u32>) -> bool {
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`

tests/ui/mut_from_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused, clippy::needless_lifetimes)]
1+
#![allow(unused, clippy::needless_lifetimes, clippy::needless_pass_by_ref_mut)]
22
#![warn(clippy::mut_from_ref)]
33

44
struct Foo;

tests/ui/mut_key.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ error: mutable key type
1212
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
1313
| ^^^^^^^^^^^^
1414

15+
error: this argument is a mutable reference, but not used mutably
16+
--> $DIR/mut_key.rs:30:32
17+
|
18+
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&HashMap<Key, usize>`
20+
|
21+
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
22+
1523
error: mutable key type
1624
--> $DIR/mut_key.rs:31:5
1725
|
@@ -102,5 +110,5 @@ error: mutable key type
102110
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new();
103111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104112

105-
error: aborting due to 17 previous errors
113+
error: aborting due to 18 previous errors
106114

tests/ui/mut_mut.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//@aux-build:proc_macros.rs:proc-macro
22
#![warn(clippy::mut_mut)]
33
#![allow(unused)]
4-
#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
4+
#![allow(
5+
clippy::no_effect,
6+
clippy::uninlined_format_args,
7+
clippy::unnecessary_operation,
8+
clippy::needless_pass_by_ref_mut
9+
)]
510

611
extern crate proc_macros;
712
use proc_macros::{external, inline_macros};

tests/ui/mut_mut.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
error: generally you want to avoid `&mut &mut _` if possible
2-
--> $DIR/mut_mut.rs:9:11
2+
--> $DIR/mut_mut.rs:14:11
33
|
44
LL | fn fun(x: &mut &mut u32) -> bool {
55
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::mut-mut` implied by `-D warnings`
88

99
error: generally you want to avoid `&mut &mut _` if possible
10-
--> $DIR/mut_mut.rs:26:17
10+
--> $DIR/mut_mut.rs:31:17
1111
|
1212
LL | let mut x = &mut &mut 1u32;
1313
| ^^^^^^^^^^^^^^
1414

1515
error: generally you want to avoid `&mut &mut _` if possible
16-
--> $DIR/mut_mut.rs:41:25
16+
--> $DIR/mut_mut.rs:46:25
1717
|
1818
LL | let mut z = inline!(&mut $(&mut 3u32));
1919
| ^
2020
|
2121
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

2323
error: this expression mutably borrows a mutable reference. Consider reborrowing
24-
--> $DIR/mut_mut.rs:28:21
24+
--> $DIR/mut_mut.rs:33:21
2525
|
2626
LL | let mut y = &mut x;
2727
| ^^^^^^
2828

2929
error: generally you want to avoid `&mut &mut _` if possible
30-
--> $DIR/mut_mut.rs:32:32
30+
--> $DIR/mut_mut.rs:37:32
3131
|
3232
LL | let y: &mut &mut u32 = &mut &mut 2;
3333
| ^^^^^^^^^^^
3434

3535
error: generally you want to avoid `&mut &mut _` if possible
36-
--> $DIR/mut_mut.rs:32:16
36+
--> $DIR/mut_mut.rs:37:16
3737
|
3838
LL | let y: &mut &mut u32 = &mut &mut 2;
3939
| ^^^^^^^^^^^^^
4040

4141
error: generally you want to avoid `&mut &mut _` if possible
42-
--> $DIR/mut_mut.rs:37:37
42+
--> $DIR/mut_mut.rs:42:37
4343
|
4444
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
4545
| ^^^^^^^^^^^^^^^^
4646

4747
error: generally you want to avoid `&mut &mut _` if possible
48-
--> $DIR/mut_mut.rs:37:16
48+
--> $DIR/mut_mut.rs:42:16
4949
|
5050
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
5151
| ^^^^^^^^^^^^^^^^^^
5252

5353
error: generally you want to avoid `&mut &mut _` if possible
54-
--> $DIR/mut_mut.rs:37:21
54+
--> $DIR/mut_mut.rs:42:21
5555
|
5656
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
5757
| ^^^^^^^^^^^^^

tests/ui/mut_reference.stderr

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
error: this argument is a mutable reference, but not used mutably
2+
--> $DIR/mut_reference.rs:4:33
3+
|
4+
LL | fn takes_a_mutable_reference(a: &mut i32) {}
5+
| ^^^^^^^^ help: consider changing to: `&i32`
6+
|
7+
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
8+
9+
error: this argument is a mutable reference, but not used mutably
10+
--> $DIR/mut_reference.rs:11:44
11+
|
12+
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
13+
| ^^^^^^^^ help: consider changing to: `&i32`
14+
115
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
216
--> $DIR/mut_reference.rs:17:34
317
|
@@ -18,5 +32,5 @@ error: the method `takes_an_immutable_reference` doesn't need a mutable referenc
1832
LL | my_struct.takes_an_immutable_reference(&mut 42);
1933
| ^^^^^^^
2034

21-
error: aborting due to 3 previous errors
35+
error: aborting due to 5 previous errors
2236

tests/ui/ptr_arg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
unused,
44
clippy::many_single_char_names,
55
clippy::needless_lifetimes,
6-
clippy::redundant_clone
6+
clippy::redundant_clone,
7+
clippy::needless_pass_by_ref_mut
78
)]
89
#![warn(clippy::ptr_arg)]
910

0 commit comments

Comments
 (0)