Skip to content

Commit 5ea0e80

Browse files
Update map_clone lint ui test
1 parent 355be85 commit 5ea0e80

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

tests/ui/useless_asref.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
132132
foo_rt(mru.as_ref());
133133
}
134134

135+
fn foo() {
136+
let x = Some(String::new());
137+
let y = x.as_ref().cloned();
138+
//~^ ERROR: you are using an explicit closure for cloning elements
139+
let y = x.as_ref().cloned();
140+
//~^ ERROR: you are using an explicit closure for cloning elements
141+
}
142+
135143
fn main() {
136144
not_ok();
137145
ok();

tests/ui/useless_asref.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
132132
foo_rt(mru.as_ref());
133133
}
134134

135+
fn foo() {
136+
let x = Some(String::new());
137+
let y = x.as_ref().map(Clone::clone);
138+
//~^ ERROR: you are using an explicit closure for cloning elements
139+
let y = x.as_ref().map(String::clone);
140+
//~^ ERROR: you are using an explicit closure for cloning elements
141+
}
142+
135143
fn main() {
136144
not_ok();
137145
ok();

tests/ui/useless_asref.stderr

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,20 @@ error: this call to `as_ref` does nothing
7070
LL | foo_rt(mrt.as_ref());
7171
| ^^^^^^^^^^^^ help: try: `mrt`
7272

73-
error: aborting due to 11 previous errors
73+
error: you are using an explicit closure for cloning elements
74+
--> $DIR/useless_asref.rs:137:13
75+
|
76+
LL | let y = x.as_ref().map(Clone::clone);
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
78+
|
79+
= note: `-D clippy::map-clone` implied by `-D warnings`
80+
= help: to override `-D warnings` add `#[allow(clippy::map_clone)]`
81+
82+
error: you are using an explicit closure for cloning elements
83+
--> $DIR/useless_asref.rs:139:13
84+
|
85+
LL | let y = x.as_ref().map(String::clone);
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.as_ref().cloned()`
87+
88+
error: aborting due to 13 previous errors
7489

0 commit comments

Comments
 (0)