2023-10-06 10:35:45 -05:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2023-08-11 07:05:13 -05:00
|
|
|
#![warn(clippy::ignored_unit_patterns)]
|
2024-02-08 13:24:42 -06:00
|
|
|
#![allow(
|
|
|
|
clippy::let_unit_value,
|
|
|
|
clippy::redundant_pattern_matching,
|
|
|
|
clippy::single_match,
|
|
|
|
clippy::needless_borrow
|
|
|
|
)]
|
2023-08-11 07:05:13 -05:00
|
|
|
|
|
|
|
fn foo() -> Result<(), ()> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
match foo() {
|
2023-09-12 11:13:53 -05:00
|
|
|
Ok(_) => {}, //~ ERROR: matching over `()` is more explicit
|
|
|
|
Err(_) => {}, //~ ERROR: matching over `()` is more explicit
|
2023-08-11 07:05:13 -05:00
|
|
|
}
|
|
|
|
if let Ok(_) = foo() {}
|
2023-09-12 11:13:53 -05:00
|
|
|
//~^ ERROR: matching over `()` is more explicit
|
2023-08-11 07:05:13 -05:00
|
|
|
let _ = foo().map_err(|_| todo!());
|
2023-09-12 11:13:53 -05:00
|
|
|
//~^ ERROR: matching over `()` is more explicit
|
2023-10-06 10:35:45 -05:00
|
|
|
|
2024-09-24 04:58:04 -05:00
|
|
|
println!("{:?}", match foo() {
|
|
|
|
Ok(_) => {},
|
|
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
|
|
Err(_) => {},
|
|
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
|
|
});
|
2023-09-12 11:13:53 -05:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:35:45 -05:00
|
|
|
// ignored_unit_patterns in derive macro should be ok
|
|
|
|
#[derive(proc_macro_derive::StructIgnoredUnitPattern)]
|
|
|
|
pub struct B;
|
|
|
|
|
2023-09-12 11:13:53 -05:00
|
|
|
#[allow(unused)]
|
|
|
|
pub fn moo(_: ()) {
|
|
|
|
let _ = foo().unwrap();
|
|
|
|
//~^ ERROR: matching over `()` is more explicit
|
|
|
|
let _: () = foo().unwrap();
|
|
|
|
let _: () = ();
|
2023-08-11 07:05:13 -05:00
|
|
|
}
|
2023-11-02 11:35:56 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|