From cdd96bc6626c342528b6f6578de176fd6c09f381 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Jan 2024 19:33:09 +0100 Subject: [PATCH] Update ui tests for `useless_asref` lint extension --- tests/ui/map_clone.fixed | 7 ++++- tests/ui/map_clone.rs | 7 ++++- tests/ui/map_clone.stderr | 20 +++++++++++--- tests/ui/useless_asref.fixed | 14 ++++++---- tests/ui/useless_asref.rs | 14 ++++++---- tests/ui/useless_asref.stderr | 51 ++++++++++++++++++----------------- 6 files changed, 73 insertions(+), 40 deletions(-) diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index b7cf12c1a84..74e4ea5ce01 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -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()` } diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 693914ec30a..0aac8024f67 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -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()` } diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index e6192a487ab..aae4dae634a 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -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 diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index 9083ae2d0b8..88b95095bc0 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -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 + AsRef + ?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() { diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index 65f361dc2ae..504dc1f5cbf 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -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 + AsRef + ?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() { diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index e91a9db4e3d..deb5d90f2f6 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -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