diff options
| author | The Miri Conjob Bot <miri@cron.bot> | 2024-01-13 05:03:10 +0000 |
|---|---|---|
| committer | The Miri Conjob Bot <miri@cron.bot> | 2024-01-13 05:03:10 +0000 |
| commit | 9b46f3bb6499c263c9c81e7cea4815396bbbce14 (patch) | |
| tree | ab6ca2c31a68888b7c34f3b091e899054f3a56aa /src/tools/clippy/tests/ui/map_clone.fixed | |
| parent | 86190488cd05ffd48394d9d1c464d7f50ee19614 (diff) | |
| parent | f1f8687b06a5908dd096f51da32347b3313279db (diff) | |
| download | rust-9b46f3bb6499c263c9c81e7cea4815396bbbce14.tar.gz rust-9b46f3bb6499c263c9c81e7cea4815396bbbce14.zip | |
Merge from rustc
Diffstat (limited to 'src/tools/clippy/tests/ui/map_clone.fixed')
| -rw-r--r-- | src/tools/clippy/tests/ui/map_clone.fixed | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/map_clone.fixed b/src/tools/clippy/tests/ui/map_clone.fixed index dd979013d3c..08b155a1aea 100644 --- a/src/tools/clippy/tests/ui/map_clone.fixed +++ b/src/tools/clippy/tests/ui/map_clone.fixed @@ -4,6 +4,8 @@ clippy::iter_cloned_collect, clippy::many_single_char_names, clippy::redundant_clone, + clippy::redundant_closure, + clippy::useless_asref, clippy::useless_vec )] @@ -60,4 +62,26 @@ fn main() { let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone()); } + + let x = Some(String::new()); + 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()` + + // Testing with `Result` now. + let x: Result<String, ()> = Ok(String::new()); + 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(); + + // We ensure that no warning is emitted here because `useless_asref` is taking over. + let x = Some(String::new()); + let y = x.as_ref().map(|x| String::clone(x)); + let x: Result<String, ()> = Ok(String::new()); + let y = x.as_ref().map(|x| String::clone(x)); } |
