2022-04-08 20:51:40 +00:00
|
|
|
// aux-build: proc_macro_with_span.rs
|
|
|
|
|
2018-12-04 06:17:53 +00:00
|
|
|
#![warn(clippy::single_match_else)]
|
2020-07-06 22:35:51 +00:00
|
|
|
#![allow(clippy::needless_return)]
|
|
|
|
#![allow(clippy::no_effect)]
|
2018-12-04 06:17:53 +00:00
|
|
|
|
2022-04-08 20:51:40 +00:00
|
|
|
extern crate proc_macro_with_span;
|
|
|
|
use proc_macro_with_span::with_span;
|
|
|
|
|
2018-12-04 06:17:53 +00:00
|
|
|
enum ExprNode {
|
|
|
|
ExprAddrOf,
|
|
|
|
Butterflies,
|
|
|
|
Unicorns,
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE: ExprNode = ExprNode::Unicorns;
|
|
|
|
|
|
|
|
fn unwrap_addr() -> Option<&'static ExprNode> {
|
2022-04-08 20:51:40 +00: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 06:17:53 +00:00
|
|
|
ExprNode::ExprAddrOf => Some(&NODE),
|
2018-12-09 22:26:16 +00:00
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
2022-04-08 20:51:40 +00:00
|
|
|
})
|
2018-12-04 06:17:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 10:19:49 +00:00
|
|
|
macro_rules! unwrap_addr {
|
|
|
|
($expression:expr) => {
|
|
|
|
match $expression {
|
|
|
|
ExprNode::ExprAddrOf => Some(&NODE),
|
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:35:51 +00:00
|
|
|
#[rustfmt::skip]
|
2020-03-31 10:19:49 +00:00
|
|
|
fn main() {
|
|
|
|
unwrap_addr!(ExprNode::Unicorns);
|
2020-07-06 22:35:51 +00: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;
|
|
|
|
},
|
|
|
|
}
|
2020-03-31 10:19:49 +00:00
|
|
|
}
|