Add necessary parentheses to manual_unwrap_or_default lint output
This commit is contained in:
parent
fc053c3296
commit
2ffd1336c7
4 changed files with 35 additions and 3 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue