Skip to content

Commit

Permalink
Update map_clone lint ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 6, 2024
1 parent 355be85 commit 5ea0e80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/ui/useless_asref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
foo_rt(mru.as_ref());
}

fn foo() {
let x = Some(String::new());
let y = x.as_ref().cloned();
//~^ ERROR: you are using an explicit closure for cloning elements
let y = x.as_ref().cloned();
//~^ ERROR: you are using an explicit closure for cloning elements
}

fn main() {
not_ok();
ok();
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/useless_asref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
foo_rt(mru.as_ref());
}

fn foo() {
let x = Some(String::new());
let y = x.as_ref().map(Clone::clone);
//~^ ERROR: you are using an explicit closure for cloning elements
let y = x.as_ref().map(String::clone);
//~^ ERROR: you are using an explicit closure for cloning elements
}

fn main() {
not_ok();
ok();
Expand Down
17 changes: 16 additions & 1 deletion tests/ui/useless_asref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,20 @@ error: this call to `as_ref` does nothing
LL | foo_rt(mrt.as_ref());
| ^^^^^^^^^^^^ help: try: `mrt`

error: aborting due to 11 previous errors
error: you are using an explicit closure for cloning elements
--> $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 using an explicit closure for cloning elements
--> $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()`

error: aborting due to 13 previous errors

0 comments on commit 5ea0e80

Please sign in to comment.