Skip to content

Commit

Permalink
Modify tests to account for the new allow-by-default `needless_pass_b…
Browse files Browse the repository at this point in the history
…y_ref_mut`
  • Loading branch information
blyxyas committed Oct 2, 2023
1 parent 3f0da4d commit 2705d62
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 74 deletions.
1 change: 1 addition & 0 deletions tests/ui/infinite_loop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@no-rustfix
#![warn(clippy::needless_pass_by_ref_mut)]

fn fn_val(i: i32) -> i32 {
unimplemented!()
Expand Down
24 changes: 12 additions & 12 deletions 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:25: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:32: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:41: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:87: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:94: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:100: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:117: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:124: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:192: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:202: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:211:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -92,7 +92,7 @@ LL | while y < 10 {
= help: rewrite it as `if cond { loop { } }`

error: this argument is a mutable reference, but not used mutably
--> $DIR/infinite_loop.rs:9:17
--> $DIR/infinite_loop.rs:10:17
|
LL | fn fn_mutref(i: &mut i32) {
| ^^^^^^^^ help: consider changing to: `&i32`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/let_underscore_future.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![warn(clippy::needless_pass_by_ref_mut)]
use std::future::Future;
//@no-rustfix
async fn some_async_fn() {}
Expand Down
8 changes: 4 additions & 4 deletions 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:17:5
|
LL | let _ = some_async_fn();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,23 +9,23 @@ 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:19: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:24: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
--> $DIR/let_underscore_future.rs:12:35
|
LL | fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future<Output = ()>`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/mut_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![warn(clippy::needless_pass_by_ref_mut)]
use std::cell::Cell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::{Hash, Hasher};
Expand Down
36 changes: 18 additions & 18 deletions tests/ui/mut_key.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: mutable key type
--> $DIR/mut_key.rs:31:32
--> $DIR/mut_key.rs:32:32
|
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,103 +8,103 @@ LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> Hash
= help: to override `-D warnings` add `#[allow(clippy::mutable_key_type)]`

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

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

error: mutable key type
--> $DIR/mut_key.rs:65:22
--> $DIR/mut_key.rs:66: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:79:5
|
LL | let _map = HashMap::<Cell<usize>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

error: mutable key type
--> $DIR/mut_key.rs:104:5
--> $DIR/mut_key.rs:105: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
--> $DIR/mut_key.rs:32:32
|
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&HashMap<Key, usize>`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/mut_reference.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(unused_variables, dead_code)]
#![warn(clippy::needless_pass_by_ref_mut)]
//@no-rustfix
fn takes_an_immutable_reference(a: &i32) {}
fn takes_a_mutable_reference(a: &mut i32) {}
Expand Down
8 changes: 4 additions & 4 deletions 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:33:34
|
LL | takes_an_immutable_reference(&mut 42);
| ^^^^^^^
Expand All @@ -8,19 +8,19 @@ 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:37: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:42: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
--> $DIR/mut_reference.rs:25:44
|
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
| ^^^^^^^^ help: consider changing to: `&i32`
Expand Down
1 change: 1 addition & 0 deletions 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 2705d62

Please sign in to comment.