Skip to content

Commit f92809b

Browse files
Update ui tests for useless_asref lint extension
1 parent 02b3d3d commit f92809b

File tree

6 files changed

+76
-39
lines changed

6 files changed

+76
-39
lines changed

tests/ui/map_clone.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
clippy::iter_cloned_collect,
55
clippy::many_single_char_names,
66
clippy::redundant_clone,
7+
clippy::useless_asref,
78
clippy::useless_vec
89
)]
910

@@ -60,4 +61,10 @@ fn main() {
6061

6162
let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone());
6263
}
64+
65+
let x = Some(String::new());
66+
let y = x.as_ref().cloned();
67+
//~^ ERROR: you are explicitly cloning with `.map()`
68+
let y = x.as_ref().cloned();
69+
//~^ ERROR: you are explicitly cloning with `.map()`
6370
}

tests/ui/map_clone.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
clippy::iter_cloned_collect,
55
clippy::many_single_char_names,
66
clippy::redundant_clone,
7+
clippy::useless_asref,
78
clippy::useless_vec
89
)]
910

@@ -60,4 +61,10 @@ fn main() {
6061

6162
let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone());
6263
}
64+
65+
let x = Some(String::new());
66+
let y = x.as_ref().map(Clone::clone);
67+
//~^ ERROR: you are explicitly cloning with `.map()`
68+
let y = x.as_ref().map(String::clone);
69+
//~^ ERROR: you are explicitly cloning with `.map()`
6370
}

tests/ui/map_clone.stderr

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you are using an explicit closure for copying elements
2-
--> $DIR/map_clone.rs:11:22
2+
--> $DIR/map_clone.rs:12:22
33
|
44
LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()`
@@ -8,34 +8,46 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
88
= help: to override `-D warnings` add `#[allow(clippy::map_clone)]`
99

1010
error: you are using an explicit closure for cloning elements
11-
--> $DIR/map_clone.rs:12:26
11+
--> $DIR/map_clone.rs:13:26
1212
|
1313
LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect();
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()`
1515

1616
error: you are using an explicit closure for copying elements
17-
--> $DIR/map_clone.rs:13:23
17+
--> $DIR/map_clone.rs:14:23
1818
|
1919
LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect();
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()`
2121

2222
error: you are using an explicit closure for copying elements
23-
--> $DIR/map_clone.rs:15:26
23+
--> $DIR/map_clone.rs:16:26
2424
|
2525
LL | let _: Option<u64> = Some(&16).map(|b| *b);
2626
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()`
2727

2828
error: you are using an explicit closure for copying elements
29-
--> $DIR/map_clone.rs:16:25
29+
--> $DIR/map_clone.rs:17:25
3030
|
3131
LL | let _: Option<u8> = Some(&1).map(|x| x.clone());
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()`
3333

3434
error: you are needlessly cloning iterator elements
35-
--> $DIR/map_clone.rs:27:29
35+
--> $DIR/map_clone.rs:28:29
3636
|
3737
LL | let _ = std::env::args().map(|v| v.clone());
3838
| ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call
3939

40-
error: aborting due to 6 previous errors
40+
error: you are explicitly cloning with `.map()`
41+
--> $DIR/map_clone.rs:66:13
42+
|
43+
LL | let y = x.as_ref().map(Clone::clone);
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
45+
46+
error: you are explicitly cloning with `.map()`
47+
--> $DIR/map_clone.rs:68:13
48+
|
49+
LL | let y = x.as_ref().map(String::clone);
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
51+
52+
error: aborting due to 8 previous errors
4153

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)