summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/drop_ref.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/tools/clippy/tests/ui/drop_ref.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/drop_ref.rs')
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/drop_ref.rs b/src/tools/clippy/tests/ui/drop_ref.rs
index 7de0b0bbd..10044e65f 100644
--- a/src/tools/clippy/tests/ui/drop_ref.rs
+++ b/src/tools/clippy/tests/ui/drop_ref.rs
@@ -72,3 +72,26 @@ fn test_owl_result_2() -> Result<u8, ()> {
produce_half_owl_ok().map(drop)?;
Ok(1)
}
+
+#[allow(unused)]
+#[allow(clippy::unit_cmp)]
+fn issue10122(x: u8) {
+ // This is a function which returns a reference and has a side-effect, which means
+ // that calling drop() on the function is considered an idiomatic way of achieving the side-effect
+ // in a match arm.
+ fn println_and<T>(t: &T) -> &T {
+ println!("foo");
+ t
+ }
+
+ match x {
+ 0 => drop(println_and(&12)), // Don't lint (copy type), we only care about side-effects
+ 1 => drop(println_and(&String::new())), // Don't lint (no copy type), we only care about side-effects
+ 2 => {
+ drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
+ },
+ 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ 4 => drop(&2), // Lint, not a fn/method call
+ _ => (),
+ }
+}