2023-08-24 19:32:12 +00:00
|
|
|
//@aux-build: proc_macros.rs
|
2024-03-07 16:19:29 +00:00
|
|
|
|
2018-12-04 06:17:53 +00:00
|
|
|
#![warn(clippy::single_match_else)]
|
2023-06-02 09:41:57 +00:00
|
|
|
#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
|
2023-03-24 13:04:35 +00:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::with_span;
|
2022-05-05 14:12:52 +00:00
|
|
|
|
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-05-05 14:12:52 +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-05-05 14:12:52 +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-14 12:59:59 +00:00
|
|
|
#[rustfmt::skip]
|
2020-03-31 10:19:49 +00:00
|
|
|
fn main() {
|
|
|
|
unwrap_addr!(ExprNode::Unicorns);
|
2020-07-14 12:59:59 +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;
|
|
|
|
},
|
|
|
|
}
|
2022-06-30 08:50:09 +00:00
|
|
|
|
|
|
|
// lint here
|
|
|
|
use std::convert::Infallible;
|
2024-03-20 21:51:29 +00:00
|
|
|
match Result::<i32, &Infallible>::Ok(1) {
|
2022-06-30 08:50:09 +00:00
|
|
|
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 10:19:49 +00:00
|
|
|
}
|
2023-06-02 09:41:57 +00:00
|
|
|
|
|
|
|
fn issue_10808(bar: Option<i32>) {
|
|
|
|
match bar {
|
|
|
|
Some(v) => unsafe {
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
println!("None1");
|
|
|
|
println!("None2");
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match bar {
|
|
|
|
Some(v) => {
|
|
|
|
println!("Some");
|
|
|
|
println!("{v}");
|
|
|
|
},
|
|
|
|
None => unsafe {
|
|
|
|
let v = 0;
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match bar {
|
|
|
|
Some(v) => unsafe {
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
},
|
|
|
|
None => unsafe {
|
|
|
|
let v = 0;
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match bar {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
Some(v) => {
|
|
|
|
unsafe {
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
println!("None");
|
|
|
|
println!("None");
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match bar {
|
|
|
|
Some(v) => {
|
|
|
|
println!("Some");
|
|
|
|
println!("{v}");
|
|
|
|
},
|
|
|
|
#[rustfmt::skip]
|
|
|
|
None => {
|
|
|
|
unsafe {
|
|
|
|
let v = 0;
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match bar {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
Some(v) => {
|
|
|
|
unsafe {
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
#[rustfmt::skip]
|
|
|
|
None => {
|
|
|
|
unsafe {
|
|
|
|
let v = 0;
|
|
|
|
let r = &v as *const i32;
|
|
|
|
println!("{}", *r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-08-30 21:02:07 +00:00
|
|
|
|
|
|
|
fn irrefutable_match() -> Option<&'static ExprNode> {
|
|
|
|
match ExprNode::Butterflies {
|
|
|
|
ExprNode::Butterflies => Some(&NODE),
|
|
|
|
_ => {
|
|
|
|
let x = 5;
|
|
|
|
None
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|