mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
e9ede27a5d
These were probably added automatically to avoid code churn. I'd like to get rid of them bit by bit, so here's the first bit
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
#![warn(clippy::match_single_binding)]
|
|
#![allow(unused_variables)]
|
|
|
|
fn main() {
|
|
// Lint (additional curly braces needed, see #6572)
|
|
struct AppendIter<I>
|
|
where
|
|
I: Iterator,
|
|
{
|
|
inner: Option<(I, <I as Iterator>::Item)>,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
fn size_hint<I: Iterator>(iter: &AppendIter<I>) -> (usize, Option<usize>) {
|
|
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 {a:?} and b {b:?}")
|
|
},
|
|
None => println!("nothing"),
|
|
}
|
|
|
|
fn side_effects() {}
|
|
|
|
// Lint (scrutinee has side effects)
|
|
// issue #7094
|
|
side_effects();
|
|
println!("Side effects");
|
|
|
|
// Lint (scrutinee has side effects)
|
|
// issue #7094
|
|
let x = 1;
|
|
match x {
|
|
//~^ match_single_binding
|
|
0 => 1,
|
|
_ => 2,
|
|
};
|
|
println!("Single branch")
|
|
}
|