diff --git a/tests/ui/match_single_binding.fixed b/tests/ui/match_single_binding.fixed index 4709b5b01..526e94b10 100644 --- a/tests/ui/match_single_binding.fixed +++ b/tests/ui/match_single_binding.fixed @@ -115,33 +115,4 @@ fn main() { // => _ => println!("Not an array index start"), } - // Lint (additional curly braces needed, see #6572) - struct AppendIter - where - I: Iterator, - { - inner: Option<(I, ::Item)>, - } - - #[allow(dead_code)] - fn size_hint(iter: &AppendIter) -> (usize, Option) { - match &iter.inner { - Some((iter, _item)) => { - let (min, max) = iter.size_hint(); - (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) - }, - None => (0, Some(0)), - } - } - // Lint (no additional curly braces needed) - let opt = Some((5, 2)); - let get_tup = || -> (i32, i32) { (1, 2) }; - match opt { - #[rustfmt::skip] - Some((first, _second)) => { - let (a, b) = get_tup(); - println!("a {:?} and b {:?}", a, b); - }, - None => println!("nothing"), - } } diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs index 6a6b3e8e8..6a2ca7c5e 100644 --- a/tests/ui/match_single_binding.rs +++ b/tests/ui/match_single_binding.rs @@ -132,33 +132,4 @@ fn main() { // => _ => println!("Not an array index start"), } - // Lint (additional curly braces needed, see #6572) - struct AppendIter - where - I: Iterator, - { - inner: Option<(I, ::Item)>, - } - - #[allow(dead_code)] - fn size_hint(iter: &AppendIter) -> (usize, Option) { - match &iter.inner { - Some((iter, _item)) => match iter.size_hint() { - (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), - }, - None => (0, Some(0)), - } - } - // Lint (no additional curly braces needed) - let opt = Some((5, 2)); - let get_tup = || -> (i32, i32) { (1, 2) }; - match opt { - #[rustfmt::skip] - Some((first, _second)) => { - match get_tup() { - (a, b) => println!("a {:?} and b {:?}", a, b), - } - }, - None => println!("nothing"), - } } diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 73cc867dd..cbbf5d29c 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -178,36 +178,5 @@ LL | | _ => println!("Single branch"), LL | | } | |_____^ help: consider using the match body instead: `println!("Single branch");` -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:146:36 - | -LL | Some((iter, _item)) => match iter.size_hint() { - | ____________________________________^ -LL | | (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), -LL | | }, - | |_____________^ - | -help: consider using `let` statement - | -LL | Some((iter, _item)) => { -LL | let (min, max) = iter.size_hint(); -LL | (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) -LL | }, - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:158:13 - | -LL | / match get_tup() { -LL | | (a, b) => println!("a {:?} and b {:?}", a, b), -LL | | } - | |_____________^ - | -help: consider using `let` statement - | -LL | let (a, b) = get_tup(); -LL | println!("a {:?} and b {:?}", a, b); - | - -error: aborting due to 14 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/match_single_binding2.fixed b/tests/ui/match_single_binding2.fixed new file mode 100644 index 000000000..e73a85b73 --- /dev/null +++ b/tests/ui/match_single_binding2.fixed @@ -0,0 +1,37 @@ +// run-rustfix + +#![warn(clippy::match_single_binding)] +#![allow(unused_variables)] + +fn main() { + // Lint (additional curly braces needed, see #6572) + struct AppendIter + where + I: Iterator, + { + inner: Option<(I, ::Item)>, + } + + #[allow(dead_code)] + fn size_hint(iter: &AppendIter) -> (usize, Option) { + match &iter.inner { + Some((iter, _item)) => { + let (min, max) = iter.size_hint(); + (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) + }, + None => (0, Some(0)), + } + } + + // Lint (no additional curly braces needed) + let opt = Some((5, 2)); + let get_tup = || -> (i32, i32) { (1, 2) }; + match opt { + #[rustfmt::skip] + Some((first, _second)) => { + let (a, b) = get_tup(); + println!("a {:?} and b {:?}", a, b); + }, + None => println!("nothing"), + } +} diff --git a/tests/ui/match_single_binding2.rs b/tests/ui/match_single_binding2.rs new file mode 100644 index 000000000..7362cb390 --- /dev/null +++ b/tests/ui/match_single_binding2.rs @@ -0,0 +1,37 @@ +// run-rustfix + +#![warn(clippy::match_single_binding)] +#![allow(unused_variables)] + +fn main() { + // Lint (additional curly braces needed, see #6572) + struct AppendIter + where + I: Iterator, + { + inner: Option<(I, ::Item)>, + } + + #[allow(dead_code)] + fn size_hint(iter: &AppendIter) -> (usize, Option) { + match &iter.inner { + Some((iter, _item)) => match iter.size_hint() { + (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), + }, + None => (0, Some(0)), + } + } + + // Lint (no additional curly braces needed) + let opt = Some((5, 2)); + let get_tup = || -> (i32, i32) { (1, 2) }; + match opt { + #[rustfmt::skip] + Some((first, _second)) => { + match get_tup() { + (a, b) => println!("a {:?} and b {:?}", a, b), + } + }, + None => println!("nothing"), + } +} diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr new file mode 100644 index 000000000..bc18d191a --- /dev/null +++ b/tests/ui/match_single_binding2.stderr @@ -0,0 +1,34 @@ +error: this match could be written as a `let` statement + --> $DIR/match_single_binding2.rs:18:36 + | +LL | Some((iter, _item)) => match iter.size_hint() { + | ____________________________________^ +LL | | (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), +LL | | }, + | |_____________^ + | + = note: `-D clippy::match-single-binding` implied by `-D warnings` +help: consider using `let` statement + | +LL | Some((iter, _item)) => { +LL | let (min, max) = iter.size_hint(); +LL | (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) +LL | }, + | + +error: this match could be written as a `let` statement + --> $DIR/match_single_binding2.rs:31:13 + | +LL | / match get_tup() { +LL | | (a, b) => println!("a {:?} and b {:?}", a, b), +LL | | } + | |_____________^ + | +help: consider using `let` statement + | +LL | let (a, b) = get_tup(); +LL | println!("a {:?} and b {:?}", a, b); + | + +error: aborting due to 2 previous errors +