Skip to content

Commit cdd96bc

Browse files
Update ui tests for useless_asref lint extension
1 parent 4ab6924 commit cdd96bc

File tree

6 files changed

+71
-38
lines changed

6 files changed

+71
-38
lines changed

tests/ui/map_clone.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ fn main() {
6363
}
6464

6565
let x = Some(String::new());
66-
let y = x.as_ref().cloned();
66+
let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint.
67+
let y = x.cloned();
68+
//~^ ERROR: you are explicitly cloning with `.map()`
69+
let y = x.cloned();
70+
//~^ ERROR: you are explicitly cloning with `.map()`
71+
let y = x.cloned();
6772
//~^ ERROR: you are explicitly cloning with `.map()`
6873
}

tests/ui/map_clone.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ fn main() {
6363
}
6464

6565
let x = Some(String::new());
66-
let y = x.as_ref().map(|x| String::clone(x));
66+
let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint.
67+
let y = x.map(|x| String::clone(x));
68+
//~^ ERROR: you are explicitly cloning with `.map()`
69+
let y = x.map(Clone::clone);
70+
//~^ ERROR: you are explicitly cloning with `.map()`
71+
let y = x.map(String::clone);
6772
//~^ ERROR: you are explicitly cloning with `.map()`
6873
}

tests/ui/map_clone.stderr

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@ LL | let _ = std::env::args().map(|v| v.clone());
3838
| ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call
3939

4040
error: you are explicitly cloning with `.map()`
41-
--> $DIR/map_clone.rs:66:13
41+
--> $DIR/map_clone.rs:67:13
4242
|
43-
LL | let y = x.as_ref().map(|x| String::clone(x));
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
43+
LL | let y = x.map(|x| String::clone(x));
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
4545

46-
error: aborting due to 7 previous errors
46+
error: you are explicitly cloning with `.map()`
47+
--> $DIR/map_clone.rs:69:13
48+
|
49+
LL | let y = x.map(Clone::clone);
50+
| ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
51+
52+
error: you are explicitly cloning with `.map()`
53+
--> $DIR/map_clone.rs:71:13
54+
|
55+
LL | let y = x.map(String::clone);
56+
| ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()`
57+
58+
error: aborting due to 9 previous errors
4759

tests/ui/useless_asref.fixed

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#![allow(
33
clippy::explicit_auto_deref,
44
clippy::uninlined_format_args,
5-
clippy::needless_pass_by_ref_mut
5+
clippy::map_clone,
6+
clippy::needless_pass_by_ref_mut,
7+
clippy::redundant_closure
68
)]
79

810
use std::fmt::Debug;
@@ -134,10 +136,12 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
134136

135137
fn foo() {
136138
let x = Some(String::new());
137-
let y = x.as_ref().cloned();
138-
//~^ ERROR: you are explicitly cloning with `.map()`
139-
let y = x.as_ref().cloned();
140-
//~^ ERROR: you are explicitly cloning with `.map()`
139+
let z = x.clone();
140+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
141+
let z = x.clone();
142+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
143+
let z = x.clone();
144+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
141145
}
142146

143147
fn main() {

tests/ui/useless_asref.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#![allow(
33
clippy::explicit_auto_deref,
44
clippy::uninlined_format_args,
5-
clippy::needless_pass_by_ref_mut
5+
clippy::map_clone,
6+
clippy::needless_pass_by_ref_mut,
7+
clippy::redundant_closure
68
)]
79

810
use std::fmt::Debug;
@@ -134,10 +136,12 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
134136

135137
fn foo() {
136138
let x = Some(String::new());
137-
let y = x.as_ref().map(Clone::clone);
138-
//~^ ERROR: you are explicitly cloning with `.map()`
139-
let y = x.as_ref().map(String::clone);
140-
//~^ ERROR: you are explicitly cloning with `.map()`
139+
let z = x.as_ref().map(String::clone);
140+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
141+
let z = x.as_ref().map(|z| z.clone());
142+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
143+
let z = x.as_ref().map(|z| String::clone(z));
144+
//~^ ERROR: this call to `as_ref.map(...)` does nothing
141145
}
142146

143147
fn main() {

tests/ui/useless_asref.stderr

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this call to `as_ref` does nothing
2-
--> $DIR/useless_asref.rs:46:18
2+
--> $DIR/useless_asref.rs:48:18
33
|
44
LL | foo_rstr(rstr.as_ref());
55
| ^^^^^^^^^^^^^ help: try: `rstr`
@@ -11,79 +11,82 @@ LL | #![deny(clippy::useless_asref)]
1111
| ^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: this call to `as_ref` does nothing
14-
--> $DIR/useless_asref.rs:48:20
14+
--> $DIR/useless_asref.rs:50:20
1515
|
1616
LL | foo_rslice(rslice.as_ref());
1717
| ^^^^^^^^^^^^^^^ help: try: `rslice`
1818

1919
error: this call to `as_mut` does nothing
20-
--> $DIR/useless_asref.rs:52:21
20+
--> $DIR/useless_asref.rs:54:21
2121
|
2222
LL | foo_mrslice(mrslice.as_mut());
2323
| ^^^^^^^^^^^^^^^^ help: try: `mrslice`
2424

2525
error: this call to `as_ref` does nothing
26-
--> $DIR/useless_asref.rs:54:20
26+
--> $DIR/useless_asref.rs:56:20
2727
|
2828
LL | foo_rslice(mrslice.as_ref());
2929
| ^^^^^^^^^^^^^^^^ help: try: `mrslice`
3030

3131
error: this call to `as_ref` does nothing
32-
--> $DIR/useless_asref.rs:61:20
32+
--> $DIR/useless_asref.rs:63:20
3333
|
3434
LL | foo_rslice(rrrrrslice.as_ref());
3535
| ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice`
3636

3737
error: this call to `as_ref` does nothing
38-
--> $DIR/useless_asref.rs:63:18
38+
--> $DIR/useless_asref.rs:65:18
3939
|
4040
LL | foo_rstr(rrrrrstr.as_ref());
4141
| ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr`
4242

4343
error: this call to `as_mut` does nothing
44-
--> $DIR/useless_asref.rs:68:21
44+
--> $DIR/useless_asref.rs:70:21
4545
|
4646
LL | foo_mrslice(mrrrrrslice.as_mut());
4747
| ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
4848

4949
error: this call to `as_ref` does nothing
50-
--> $DIR/useless_asref.rs:70:20
50+
--> $DIR/useless_asref.rs:72:20
5151
|
5252
LL | foo_rslice(mrrrrrslice.as_ref());
5353
| ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
5454

5555
error: this call to `as_ref` does nothing
56-
--> $DIR/useless_asref.rs:74:16
56+
--> $DIR/useless_asref.rs:76:16
5757
|
5858
LL | foo_rrrrmr((&&&&MoreRef).as_ref());
5959
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)`
6060

6161
error: this call to `as_mut` does nothing
62-
--> $DIR/useless_asref.rs:124:13
62+
--> $DIR/useless_asref.rs:126:13
6363
|
6464
LL | foo_mrt(mrt.as_mut());
6565
| ^^^^^^^^^^^^ help: try: `mrt`
6666

6767
error: this call to `as_ref` does nothing
68-
--> $DIR/useless_asref.rs:126:12
68+
--> $DIR/useless_asref.rs:128:12
6969
|
7070
LL | foo_rt(mrt.as_ref());
7171
| ^^^^^^^^^^^^ help: try: `mrt`
7272

73-
error: you are explicitly cloning with `.map()`
74-
--> $DIR/useless_asref.rs:137:13
73+
error: this call to `as_ref.map(...)` does nothing
74+
--> $DIR/useless_asref.rs:139:13
7575
|
76-
LL | let y = x.as_ref().map(Clone::clone);
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
76+
LL | let z = x.as_ref().map(String::clone);
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
78+
79+
error: this call to `as_ref.map(...)` does nothing
80+
--> $DIR/useless_asref.rs:141:13
7881
|
79-
= note: `-D clippy::map-clone` implied by `-D warnings`
80-
= help: to override `-D warnings` add `#[allow(clippy::map_clone)]`
82+
LL | let z = x.as_ref().map(|z| z.clone());
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
8184

82-
error: you are explicitly cloning with `.map()`
83-
--> $DIR/useless_asref.rs:139:13
85+
error: this call to `as_ref.map(...)` does nothing
86+
--> $DIR/useless_asref.rs:143:13
8487
|
85-
LL | let y = x.as_ref().map(String::clone);
86-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
88+
LL | let z = x.as_ref().map(|z| String::clone(z));
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()`
8790

88-
error: aborting due to 13 previous errors
91+
error: aborting due to 14 previous errors
8992

0 commit comments

Comments
 (0)