Skip to content

Commit

Permalink
Update UI tests with new needless_pass_by_ref_mut lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 24, 2023
1 parent 12ac6d4 commit 335a34d
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 96 deletions.
1 change: 1 addition & 0 deletions tests/ui-toml/toml_trivially_copy/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"

#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(clippy::needless_pass_by_ref_mut)]

#[derive(Copy, Clone)]
struct Foo(u8);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-toml/toml_trivially_copy/test.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:14:11
--> $DIR/test.rs:15:11
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16`
Expand All @@ -11,7 +11,7 @@ LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:14:20
--> $DIR/test.rs:15:20
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `Foo`
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/borrow_box.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![deny(clippy::borrowed_box)]
#![allow(dead_code, unused_variables)]
#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
#![allow(
clippy::uninlined_format_args,
clippy::disallowed_names,
clippy::needless_pass_by_ref_mut
)]

use std::fmt::Display;

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/borrow_box.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> $DIR/borrow_box.rs:20:14
--> $DIR/borrow_box.rs:24:14
|
LL | let foo: &Box<bool>;
| ^^^^^^^^^^ help: try: `&bool`
Expand All @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
| ^^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> $DIR/borrow_box.rs:105:25
--> $DIR/borrow_box.rs:109:25
|
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/infinite_loop.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
error: this argument is a mutable reference, but not used mutably
--> $DIR/infinite_loop.rs:7: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`

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

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

10 changes: 9 additions & 1 deletion tests/ui/let_underscore_future.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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`

error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:14:5
|
Expand All @@ -23,5 +31,5 @@ LL | let _ = future;
|
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`

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

7 changes: 6 additions & 1 deletion tests/ui/must_use_candidates.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//@run-rustfix
#![feature(never_type)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![allow(
unused_mut,
unused_tuple_struct_fields,
clippy::redundant_allocation,
clippy::needless_pass_by_ref_mut
)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/must_use_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//@run-rustfix
#![feature(never_type)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![allow(
unused_mut,
unused_tuple_struct_fields,
clippy::redundant_allocation,
clippy::needless_pass_by_ref_mut
)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/must_use_candidates.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: this function could have a `#[must_use]` attribute
--> $DIR/must_use_candidates.rs:12:1
--> $DIR/must_use_candidates.rs:17:1
|
LL | pub fn pure(i: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
|
= note: `-D clippy::must-use-candidate` implied by `-D warnings`

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

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

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

error: this function could have a `#[must_use]` attribute
--> $DIR/must_use_candidates.rs:68:1
--> $DIR/must_use_candidates.rs:73:1
|
LL | pub fn arcd(_x: Arc<u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mut_from_ref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused, clippy::needless_lifetimes)]
#![allow(unused, clippy::needless_lifetimes, clippy::needless_pass_by_ref_mut)]
#![warn(clippy::mut_from_ref)]

struct Foo;
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/mut_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ error: mutable key type
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^

error: this argument is a mutable reference, but not used mutably
--> $DIR/mut_key.rs:30: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`

error: mutable key type
--> $DIR/mut_key.rs:31:5
|
Expand Down Expand Up @@ -102,5 +110,5 @@ error: mutable key type
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

7 changes: 6 additions & 1 deletion tests/ui/mut_mut.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
//@aux-build:proc_macros.rs
#![warn(clippy::mut_mut)]
#![allow(unused)]
#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
#![allow(
clippy::no_effect,
clippy::uninlined_format_args,
clippy::unnecessary_operation,
clippy::needless_pass_by_ref_mut
)]

extern crate proc_macros;
use proc_macros::{external, inline_macros};
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/mut_mut.stderr
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
error: generally you want to avoid `&mut &mut _` if possible
--> $DIR/mut_mut.rs:9:11
--> $DIR/mut_mut.rs:14:11
|
LL | fn fun(x: &mut &mut u32) -> bool {
| ^^^^^^^^^^^^^
|
= note: `-D clippy::mut-mut` implied by `-D warnings`

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

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

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

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

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

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

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

error: generally you want to avoid `&mut &mut _` if possible
--> $DIR/mut_mut.rs:37:21
--> $DIR/mut_mut.rs:42:21
|
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^
Expand Down
16 changes: 15 additions & 1 deletion tests/ui/mut_reference.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
error: this argument is a mutable reference, but not used mutably
--> $DIR/mut_reference.rs:4:33
|
LL | fn takes_a_mutable_reference(a: &mut i32) {}
| ^^^^^^^^ help: consider changing to: `&i32`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`

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

error: the function `takes_an_immutable_reference` doesn't need a mutable reference
--> $DIR/mut_reference.rs:17:34
|
Expand All @@ -18,5 +32,5 @@ error: the method `takes_an_immutable_reference` doesn't need a mutable referenc
LL | my_struct.takes_an_immutable_reference(&mut 42);
| ^^^^^^^

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

3 changes: 2 additions & 1 deletion tests/ui/ptr_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
unused,
clippy::many_single_char_names,
clippy::needless_lifetimes,
clippy::redundant_clone
clippy::redundant_clone,
clippy::needless_pass_by_ref_mut
)]
#![warn(clippy::ptr_arg)]

Expand Down
Loading

0 comments on commit 335a34d

Please sign in to comment.