X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=tests%2Fui%2Foption_if_let_else.rs;h=9eeaea12d3bc91e615cb2fac5f3d3b10c0ffd0c9;hb=c0d928561c3b88b294ddffaf8f8179f672babcda;hp=c228b2f43d10c41420440776d50a9f6c9c47d945;hpb=3fe11e776c223201045ff9938f8eaec6053ceb3a;p=rust.git diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index c228b2f43d1..9eeaea12d3b 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -1,6 +1,12 @@ // run-rustfix #![warn(clippy::option_if_let_else)] -#![allow(clippy::redundant_closure, clippy::ref_option_ref, clippy::equatable_if_let)] +#![allow( + unused_tuple_struct_fields, + clippy::redundant_closure, + clippy::ref_option_ref, + clippy::equatable_if_let, + clippy::let_unit_value +)] fn bad1(string: Option<&str>) -> (bool, &str) { if let Some(x) = string { @@ -109,6 +115,19 @@ fn pattern_to_vec(pattern: &str) -> Vec { .collect::>() } +enum DummyEnum { + One(u8), + Two, +} + +// should not warn since there is a compled complex subpat +// see #7991 +fn complex_subpat() -> DummyEnum { + let x = Some(DummyEnum::One(1)); + let _ = if let Some(_one @ DummyEnum::One(..)) = x { 1 } else { 2 }; + DummyEnum::Two +} + fn main() { let optional = Some(5); let _ = if let Some(x) = optional { x + 2 } else { 5 }; @@ -188,4 +207,26 @@ async fn _f2() { } let _ = pattern_to_vec("hello world"); + let _ = complex_subpat(); + + // issue #8492 + let _ = match s { + Some(string) => string.len(), + None => 1, + }; + let _ = match Some(10) { + Some(a) => a + 1, + None => 5, + }; + + let res: Result = Ok(5); + let _ = match res { + Ok(a) => a + 1, + _ => 1, + }; + let _ = match res { + Err(_) => 1, + Ok(a) => a + 1, + }; + let _ = if let Ok(a) = res { a + 1 } else { 5 }; }