X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=tests%2Fui%2Foption_if_let_else.fixed;h=ce3093c542ae0b7bfad86c1c10e665db25761cfa;hb=2938ffd0d94d93893ca32202cb3b6a6b69559bfb;hp=4077f1920a3837758a6f02f6f5b5ea8c6a2b078e;hpb=89a11564cc6f247bfb744f1587bc44e0ce1bb9cf;p=rust.git diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 4077f1920a3..ce3093c542a 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -1,4 +1,3 @@ -// edition:2018 // run-rustfix #![warn(clippy::option_if_let_else)] #![allow(clippy::redundant_closure, clippy::ref_option_ref, clippy::equatable_if_let)] @@ -76,6 +75,17 @@ fn negative_tests(arg: Option) -> u32 { 7 } +// #7973 +fn pattern_to_vec(pattern: &str) -> Vec { + pattern + .trim_matches('/') + .split('/') + .flat_map(|s| { + s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()]) + }) + .collect::>() +} + fn main() { let optional = Some(5); let _ = optional.map_or(5, |x| x + 2); @@ -111,7 +121,7 @@ fn main() { let s = String::new(); // Lint, both branches immutably borrow `s`. - let _ = Some(0).map_or_else(|| s.len(), |x| s.len() + x); + let _ = Some(0).map_or(s.len(), |x| s.len() + x); let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. @@ -147,4 +157,6 @@ fn main() { // Don't lint. `await` can't be moved into a closure. let _ = if let Some(x) = Some(0) { _f1(x).await } else { 0 }; } + + let _ = pattern_to_vec("hello world"); }