Skip to content

Commit 13e30a8

Browse files
committed
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 rust-lang#10808
1 parent 435a8ad commit 13e30a8

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/ui/single_match.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::single_match)]
2-
#![allow(clippy::uninlined_format_args)]
2+
#![allow(unused, clippy::uninlined_format_args)]
33

44
fn dummy() {}
55

@@ -244,3 +244,13 @@ fn main() {
244244
_ => 0,
245245
};
246246
}
247+
248+
fn issue_10808(bar: Option<i32>) {
249+
match bar {
250+
Some(v) => unsafe {
251+
let r = &v as *const i32;
252+
println!("{}", *r);
253+
},
254+
_ => {},
255+
}
256+
}

tests/ui/single_match_else.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@aux-build: proc_macros.rs
22
#![warn(clippy::single_match_else)]
3-
#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
3+
#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
44

55
extern crate proc_macros;
66
use proc_macros::with_span;
@@ -115,3 +115,40 @@ fn main() {
115115
}
116116
}
117117
}
118+
119+
fn issue_10808(bar: Option<i32>) {
120+
match bar {
121+
Some(v) => unsafe {
122+
let r = &v as *const i32;
123+
println!("{}", *r);
124+
},
125+
None => {
126+
println!("None1");
127+
println!("None2");
128+
},
129+
}
130+
131+
match bar {
132+
Some(v) => {
133+
println!("Some");
134+
println!("{v}");
135+
},
136+
None => unsafe {
137+
let v = 0;
138+
let r = &v as *const i32;
139+
println!("{}", *r);
140+
},
141+
}
142+
143+
match bar {
144+
Some(v) => unsafe {
145+
let r = &v as *const i32;
146+
println!("{}", *r);
147+
},
148+
None => unsafe {
149+
let v = 0;
150+
let r = &v as *const i32;
151+
println!("{}", *r);
152+
},
153+
}
154+
}

0 commit comments

Comments
 (0)