about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-22 19:53:26 +0000
committerbors <bors@rust-lang.org>2024-03-22 19:53:26 +0000
commitc7bb20005464b69eeb0b56202b2ede49802c2c60 (patch)
tree1012ca3b35606ca9cea3c08fdba6004ac35878dd /tests
parent44a5edaaabe9e9191fea86c9443911ba2cf3cf1c (diff)
parent2ffd1336c720190fe26cf27324c111c41bfa9a8a (diff)
downloadrust-c7bb20005464b69eeb0b56202b2ede49802c2c60.tar.gz
rust-c7bb20005464b69eeb0b56202b2ede49802c2c60.zip
Auto merge of #12532 - samueltardieu:issue-12531, r=llogiq
Add necessary parentheses to `manual_unwrap_or_default` lint output

Fix #12531

----

changelog: [`manual_unwrap_or_default`]: add parentheses to suggestion when appropriate
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/manual_unwrap_or_default.fixed9
-rw-r--r--tests/ui/manual_unwrap_or_default.rs12
-rw-r--r--tests/ui/manual_unwrap_or_default.stderr12
3 files changed, 32 insertions, 1 deletions
diff --git a/tests/ui/manual_unwrap_or_default.fixed b/tests/ui/manual_unwrap_or_default.fixed
index c8456805ee6..b24967242eb 100644
--- a/tests/ui/manual_unwrap_or_default.fixed
+++ b/tests/ui/manual_unwrap_or_default.fixed
@@ -17,3 +17,12 @@ fn main() {
     let x: Option<Vec<String>> = None;
     x.unwrap_or_default();
 }
+
+// Issue #12531
+unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
+    match a {
+        // `*b` being correct depends on `a == Some(_)`
+        Some(_) => (*b).unwrap_or_default(),
+        _ => 0,
+    }
+}
diff --git a/tests/ui/manual_unwrap_or_default.rs b/tests/ui/manual_unwrap_or_default.rs
index 820717be53a..ed5e54b4e14 100644
--- a/tests/ui/manual_unwrap_or_default.rs
+++ b/tests/ui/manual_unwrap_or_default.rs
@@ -38,3 +38,15 @@ fn main() {
         Vec::default()
     };
 }
+
+// Issue #12531
+unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
+    match a {
+        // `*b` being correct depends on `a == Some(_)`
+        Some(_) => match *b {
+            Some(v) => v,
+            _ => 0,
+        },
+        _ => 0,
+    }
+}
diff --git a/tests/ui/manual_unwrap_or_default.stderr b/tests/ui/manual_unwrap_or_default.stderr
index f4eb6583588..d89212e6045 100644
--- a/tests/ui/manual_unwrap_or_default.stderr
+++ b/tests/ui/manual_unwrap_or_default.stderr
@@ -52,5 +52,15 @@ LL | |         Vec::default()
 LL | |     };
    | |_____^ help: replace it with: `x.unwrap_or_default()`
 
-error: aborting due to 5 previous errors
+error: match can be simplified with `.unwrap_or_default()`
+  --> tests/ui/manual_unwrap_or_default.rs:46:20
+   |
+LL |           Some(_) => match *b {
+   |  ____________________^
+LL | |             Some(v) => v,
+LL | |             _ => 0,
+LL | |         },
+   | |_________^ help: replace it with: `(*b).unwrap_or_default()`
+
+error: aborting due to 6 previous errors