Update ui tests for `useless_asref` lint extension

This commit is contained in:
Guillaume Gomez 2024-01-06 19:33:09 +01:00
parent 4ab6924bca
commit cdd96bc662
6 changed files with 73 additions and 40 deletions

View File

@ -63,6 +63,11 @@ fn main() {
}
let x = Some(String::new());
let y = x.as_ref().cloned();
let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint.
let y = x.cloned();
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.cloned();
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.cloned();
//~^ ERROR: you are explicitly cloning with `.map()`
}

View File

@ -63,6 +63,11 @@ fn main() {
}
let x = Some(String::new());
let y = x.as_ref().map(|x| String::clone(x));
let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint.
let y = x.map(|x| String::clone(x));
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.map(Clone::clone);
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.map(String::clone);
//~^ ERROR: you are explicitly cloning with `.map()`
}

View File

@ -38,10 +38,22 @@ LL | let _ = std::env::args().map(|v| v.clone());
| ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call
error: you are explicitly cloning with `.map()`
--> $DIR/map_clone.rs:66:13
--> $DIR/map_clone.rs:67:13
|
LL | let y = x.as_ref().map(|x| String::clone(x));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
LL | let y = x.map(|x| String::clone(x));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
error: aborting due to 7 previous errors
error: you are explicitly cloning with `.map()`
--> $DIR/map_clone.rs:69:13
|
LL | let y = x.map(Clone::clone);
| ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
error: you are explicitly cloning with `.map()`
--> $DIR/map_clone.rs:71:13
|
LL | let y = x.map(String::clone);
| ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
error: aborting due to 9 previous errors

View File

@ -2,7 +2,9 @@
#![allow(
clippy::explicit_auto_deref,
clippy::uninlined_format_args,
clippy::needless_pass_by_ref_mut
clippy::map_clone,
clippy::needless_pass_by_ref_mut,
clippy::redundant_closure
)]
use std::fmt::Debug;
@ -134,10 +136,12 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
fn foo() {
let x = Some(String::new());
let y = x.as_ref().cloned();
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.as_ref().cloned();
//~^ ERROR: you are explicitly cloning with `.map()`
let z = x.clone();
//~^ ERROR: this call to `as_ref.map(...)` does nothing
let z = x.clone();
//~^ ERROR: this call to `as_ref.map(...)` does nothing
let z = x.clone();
//~^ ERROR: this call to `as_ref.map(...)` does nothing
}
fn main() {

View File

@ -2,7 +2,9 @@
#![allow(
clippy::explicit_auto_deref,
clippy::uninlined_format_args,
clippy::needless_pass_by_ref_mut
clippy::map_clone,
clippy::needless_pass_by_ref_mut,
clippy::redundant_closure
)]
use std::fmt::Debug;
@ -134,10 +136,12 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
fn foo() {
let x = Some(String::new());
let y = x.as_ref().map(Clone::clone);
//~^ ERROR: you are explicitly cloning with `.map()`
let y = x.as_ref().map(String::clone);
//~^ ERROR: you are explicitly cloning with `.map()`
let z = x.as_ref().map(String::clone);
//~^ ERROR: this call to `as_ref.map(...)` does nothing
let z = x.as_ref().map(|z| z.clone());
//~^ ERROR: this call to `as_ref.map(...)` does nothing
let z = x.as_ref().map(|z| String::clone(z));
//~^ ERROR: this call to `as_ref.map(...)` does nothing
}
fn main() {

View File

@ -1,5 +1,5 @@
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:46:18
--> $DIR/useless_asref.rs:48:18
|
LL | foo_rstr(rstr.as_ref());
| ^^^^^^^^^^^^^ help: try: `rstr`
@ -11,79 +11,82 @@ LL | #![deny(clippy::useless_asref)]
| ^^^^^^^^^^^^^^^^^^^^^
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:48:20
--> $DIR/useless_asref.rs:50:20
|
LL | foo_rslice(rslice.as_ref());
| ^^^^^^^^^^^^^^^ help: try: `rslice`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:52:21
--> $DIR/useless_asref.rs:54:21
|
LL | foo_mrslice(mrslice.as_mut());
| ^^^^^^^^^^^^^^^^ help: try: `mrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:54:20
--> $DIR/useless_asref.rs:56:20
|
LL | foo_rslice(mrslice.as_ref());
| ^^^^^^^^^^^^^^^^ help: try: `mrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:61:20
--> $DIR/useless_asref.rs:63:20
|
LL | foo_rslice(rrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:63:18
--> $DIR/useless_asref.rs:65:18
|
LL | foo_rstr(rrrrrstr.as_ref());
| ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:68:21
--> $DIR/useless_asref.rs:70:21
|
LL | foo_mrslice(mrrrrrslice.as_mut());
| ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:70:20
--> $DIR/useless_asref.rs:72:20
|
LL | foo_rslice(mrrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:74:16
--> $DIR/useless_asref.rs:76:16
|
LL | foo_rrrrmr((&&&&MoreRef).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:124:13
--> $DIR/useless_asref.rs:126:13
|
LL | foo_mrt(mrt.as_mut());
| ^^^^^^^^^^^^ help: try: `mrt`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:126:12
--> $DIR/useless_asref.rs:128:12
|
LL | foo_rt(mrt.as_ref());
| ^^^^^^^^^^^^ help: try: `mrt`
error: you are explicitly cloning with `.map()`
--> $DIR/useless_asref.rs:137:13
|
LL | let y = x.as_ref().map(Clone::clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
|
= note: `-D clippy::map-clone` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::map_clone)]`
error: you are explicitly cloning with `.map()`
error: this call to `as_ref.map(...)` does nothing
--> $DIR/useless_asref.rs:139:13
|
LL | let y = x.as_ref().map(String::clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
LL | let z = x.as_ref().map(String::clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
error: aborting due to 13 previous errors
error: this call to `as_ref.map(...)` does nothing
--> $DIR/useless_asref.rs:141:13
|
LL | let z = x.as_ref().map(|z| z.clone());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
error: this call to `as_ref.map(...)` does nothing
--> $DIR/useless_asref.rs:143:13
|
LL | let z = x.as_ref().map(|z| String::clone(z));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
error: aborting due to 14 previous errors