Skip to content

Commit 049881b

Browse files
authored
Rollup merge of rust-lang#87996 - sexxi-goose:fix-87988, r=nikomatsakis
RFC2229 Add missing edge case Closes rust-lang#87988 This PR fixes an ICE where a match discriminant is not being read when expected. This ICE was the result of a missing edge case which assumed that if a pattern is of type `PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::Struct(..) | PatKind::Tuple(..)` then a place could only be a multi variant if the place is of type kind Adt.
2 parents cd0ce33 + 2e61659 commit 049881b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

compiler/rustc_typeck/src/expr_use_visitor.rs

+3
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
269269
if def.variants.len() > 1 {
270270
needs_to_be_read = true;
271271
}
272+
} else {
273+
// If it is not ty::Adt, then it should be read
274+
needs_to_be_read = true;
272275
}
273276
}
274277
PatKind::Lit(_) | PatKind::Range(..) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
// edition:2021
3+
4+
const LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: i32 = 0x01;
5+
const LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: i32 = 0x02;
6+
7+
pub fn hotplug_callback(event: i32) {
8+
let _ = || {
9+
match event {
10+
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED => (),
11+
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT => (),
12+
_ => (),
13+
};
14+
};
15+
}
16+
17+
fn main() {
18+
hotplug_callback(1);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// run-pass
2+
// edition:2021
3+
4+
const PATTERN_REF: &str = "Hello World";
5+
const NUMBER: i32 = 30;
6+
const NUMBER_POINTER: *const i32 = &NUMBER;
7+
8+
pub fn edge_case_ref(event: &str) {
9+
let _ = || {
10+
match event {
11+
PATTERN_REF => (),
12+
_ => (),
13+
};
14+
};
15+
}
16+
17+
pub fn edge_case_str(event: String) {
18+
let _ = || {
19+
match event.as_str() {
20+
"hello" => (),
21+
_ => (),
22+
};
23+
};
24+
}
25+
26+
pub fn edge_case_raw_ptr(event: *const i32) {
27+
let _ = || {
28+
match event {
29+
NUMBER_POINTER => (),
30+
_ => (),
31+
};
32+
};
33+
}
34+
35+
pub fn edge_case_char(event: char) {
36+
let _ = || {
37+
match event {
38+
'a' => (),
39+
_ => (),
40+
};
41+
};
42+
}
43+
44+
fn main() {}

0 commit comments

Comments
 (0)