mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-13 00:17:13 +00:00
Unit tests highlighting unsafe match issue
These unit tests generate non-compilable code. I did NOT `bless` them on purpose because the stderr output is not good. I'm surprised we don't auto-compile the suggestions here - is this something that can be easily enabled? See #10808
This commit is contained in:
parent
435a8ad86c
commit
1c277d1be8
2 changed files with 107 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
#![warn(clippy::single_match)]
|
||||
#![allow(clippy::uninlined_format_args)]
|
||||
#![allow(unused, clippy::uninlined_format_args)]
|
||||
|
||||
fn dummy() {}
|
||||
|
||||
|
@ -244,3 +244,24 @@ fn main() {
|
|||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
||||
fn issue_10808(bar: Option<i32>) {
|
||||
match bar {
|
||||
Some(v) => unsafe {
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match bar {
|
||||
Some(v) => {
|
||||
// this comment prevents rustfmt from collapsing the block
|
||||
unsafe {
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//@aux-build: proc_macros.rs
|
||||
#![warn(clippy::single_match_else)]
|
||||
#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
|
||||
#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
|
||||
|
||||
extern crate proc_macros;
|
||||
use proc_macros::with_span;
|
||||
|
@ -115,3 +115,87 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
Some(v) => {
|
||||
// this comment prevents rustfmt from collapsing the block
|
||||
unsafe {
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
println!("None");
|
||||
println!("None");
|
||||
},
|
||||
}
|
||||
|
||||
match bar {
|
||||
Some(v) => {
|
||||
println!("Some");
|
||||
println!("{v}");
|
||||
},
|
||||
None => {
|
||||
// this comment prevents rustfmt from collapsing the block
|
||||
unsafe {
|
||||
let v = 0;
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
match bar {
|
||||
Some(v) => {
|
||||
// this comment prevents rustfmt from collapsing the block
|
||||
unsafe {
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
// this comment prevents rustfmt from collapsing the block
|
||||
unsafe {
|
||||
let v = 0;
|
||||
let r = &v as *const i32;
|
||||
println!("{}", *r);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue