2023-04-23 06:03:09 -05:00
|
|
|
//@aux-build: proc_macros.rs
|
2018-12-04 00:17:53 -06:00
|
|
|
#![warn(clippy::single_match_else)]
|
2022-10-06 02:44:38 -05:00
|
|
|
#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
|
2018-12-04 00:17:53 -06:00
|
|
|
|
2023-03-24 08:04:35 -05:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::with_span;
|
2022-05-05 09:12:52 -05:00
|
|
|
|
2018-12-04 00:17:53 -06:00
|
|
|
enum ExprNode {
|
|
|
|
ExprAddrOf,
|
|
|
|
Butterflies,
|
|
|
|
Unicorns,
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE: ExprNode = ExprNode::Unicorns;
|
|
|
|
|
|
|
|
fn unwrap_addr() -> Option<&'static ExprNode> {
|
2022-05-05 09:12:52 -05:00
|
|
|
let _ = match ExprNode::Butterflies {
|
|
|
|
ExprNode::ExprAddrOf => Some(&NODE),
|
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't lint
|
|
|
|
with_span!(span match ExprNode::Butterflies {
|
2018-12-04 00:17:53 -06:00
|
|
|
ExprNode::ExprAddrOf => Some(&NODE),
|
2018-12-09 16:26:16 -06:00
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
2022-05-05 09:12:52 -05:00
|
|
|
})
|
2018-12-04 00:17:53 -06:00
|
|
|
}
|
|
|
|
|
2020-03-31 05:19:49 -05:00
|
|
|
macro_rules! unwrap_addr {
|
|
|
|
($expression:expr) => {
|
|
|
|
match $expression {
|
|
|
|
ExprNode::ExprAddrOf => Some(&NODE),
|
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-14 07:59:59 -05:00
|
|
|
#[rustfmt::skip]
|
2020-03-31 05:19:49 -05:00
|
|
|
fn main() {
|
|
|
|
unwrap_addr!(ExprNode::Unicorns);
|
2020-07-14 07:59:59 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// don't lint single exprs/statements
|
|
|
|
//
|
|
|
|
|
|
|
|
// don't lint here
|
|
|
|
match Some(1) {
|
|
|
|
Some(a) => println!("${:?}", a),
|
|
|
|
None => return,
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't lint here
|
|
|
|
match Some(1) {
|
|
|
|
Some(a) => println!("${:?}", a),
|
|
|
|
None => {
|
|
|
|
return
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't lint here
|
|
|
|
match Some(1) {
|
|
|
|
Some(a) => println!("${:?}", a),
|
|
|
|
None => {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// lint multiple exprs/statements "else" blocks
|
|
|
|
//
|
|
|
|
|
|
|
|
// lint here
|
|
|
|
match Some(1) {
|
|
|
|
Some(a) => println!("${:?}", a),
|
|
|
|
None => {
|
|
|
|
println!("else block");
|
|
|
|
return
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// lint here
|
|
|
|
match Some(1) {
|
|
|
|
Some(a) => println!("${:?}", a),
|
|
|
|
None => {
|
|
|
|
println!("else block");
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
}
|
2022-06-30 03:50:09 -05:00
|
|
|
|
|
|
|
// lint here
|
|
|
|
use std::convert::Infallible;
|
|
|
|
match Result::<i32, Infallible>::Ok(1) {
|
|
|
|
Ok(a) => println!("${:?}", a),
|
|
|
|
Err(_) => {
|
|
|
|
println!("else block");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use std::borrow::Cow;
|
|
|
|
match Cow::from("moo") {
|
|
|
|
Cow::Owned(a) => println!("${:?}", a),
|
|
|
|
Cow::Borrowed(_) => {
|
|
|
|
println!("else block");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 05:19:49 -05:00
|
|
|
}
|