mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
//@aux-build:proc_macro_derive.rs
|
|
#![warn(clippy::ignored_unit_patterns)]
|
|
#![allow(
|
|
clippy::let_unit_value,
|
|
clippy::redundant_pattern_matching,
|
|
clippy::single_match,
|
|
clippy::needless_borrow
|
|
)]
|
|
|
|
fn foo() -> Result<(), ()> {
|
|
unimplemented!()
|
|
}
|
|
|
|
fn main() {
|
|
match foo() {
|
|
Ok(()) => {}, //~ ERROR: matching over `()` is more explicit
|
|
Err(()) => {}, //~ ERROR: matching over `()` is more explicit
|
|
}
|
|
if let Ok(()) = foo() {}
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
let _ = foo().map_err(|()| todo!());
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
|
|
println!(
|
|
"{:?}",
|
|
match foo() {
|
|
Ok(()) => {},
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
Err(()) => {},
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
}
|
|
);
|
|
}
|
|
|
|
// ignored_unit_patterns in derive macro should be ok
|
|
#[derive(proc_macro_derive::StructIgnoredUnitPattern)]
|
|
pub struct B;
|
|
|
|
#[allow(unused)]
|
|
pub fn moo(_: ()) {
|
|
let () = foo().unwrap();
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
let _: () = foo().unwrap();
|
|
let _: () = ();
|
|
}
|
|
|
|
fn test_unit_ref_1() {
|
|
let x: (usize, &&&&&()) = (1, &&&&&&());
|
|
match x {
|
|
(1, ()) => unimplemented!(),
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
_ => unimplemented!(),
|
|
};
|
|
}
|
|
|
|
fn test_unit_ref_2(v: &[(usize, ())]) {
|
|
for (x, ()) in v {
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
let _ = x;
|
|
}
|
|
}
|