Skip to content

Commit c2cabee

Browse files
committed
MIR pre-codegen test for .try_into().ok()
1 parent 8e8116c commit c2cabee

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// MIR for `checked_as_u32` after PreCodegen
2+
3+
fn checked_as_u32(_1: u64) -> Option<u32> {
4+
debug t => _1; // in scope 0 at $DIR/transient_enums.rs:+0:23: +0:24
5+
let mut _0: std::option::Option<u32>; // return place in scope 0 at $DIR/transient_enums.rs:+0:34: +0:45
6+
let mut _2: std::result::Result<u32, std::num::TryFromIntError>; // in scope 0 at $DIR/transient_enums.rs:+1:5: +1:17
7+
scope 1 (inlined <u64 as TryInto<u32>>::try_into) { // at $DIR/transient_enums.rs:9:7: 9:17
8+
debug self => _1; // in scope 1 at $SRC_DIR/core/src/convert/mod.rs:LL:COL
9+
scope 2 (inlined convert::num::<impl TryFrom<u64> for u32>::try_from) { // at $SRC_DIR/core/src/convert/mod.rs:LL:COL
10+
debug u => _1; // in scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
11+
let mut _3: bool; // in scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
12+
let mut _4: u64; // in scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
13+
let mut _5: u32; // in scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
14+
}
15+
}
16+
scope 3 (inlined Result::<u32, TryFromIntError>::ok) { // at $DIR/transient_enums.rs:9:18: 9:22
17+
debug self => _2; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
18+
let mut _6: isize; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
19+
let _7: u32; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
20+
scope 4 {
21+
debug x => _7; // in scope 4 at $SRC_DIR/core/src/result.rs:LL:COL
22+
}
23+
}
24+
25+
bb0: {
26+
StorageLive(_2); // scope 0 at $DIR/transient_enums.rs:+1:5: +1:17
27+
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
28+
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
29+
_4 = const 4294967295_u64; // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
30+
_3 = Gt(_1, move _4); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
31+
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
32+
switchInt(move _3) -> [0: bb2, otherwise: bb1]; // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
33+
}
34+
35+
bb1: {
36+
_2 = Result::<u32, TryFromIntError>::Err(const TryFromIntError(())); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
37+
// mir::Constant
38+
// + span: no-location
39+
// + literal: Const { ty: TryFromIntError, val: Value(<ZST>) }
40+
goto -> bb3; // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
41+
}
42+
43+
bb2: {
44+
StorageLive(_5); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
45+
_5 = _1 as u32 (IntToInt); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
46+
_2 = Result::<u32, TryFromIntError>::Ok(move _5); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
47+
StorageDead(_5); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
48+
goto -> bb3; // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
49+
}
50+
51+
bb3: {
52+
StorageDead(_3); // scope 2 at $SRC_DIR/core/src/convert/num.rs:LL:COL
53+
StorageLive(_7); // scope 0 at $DIR/transient_enums.rs:+1:18: +1:22
54+
_6 = discriminant(_2); // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
55+
switchInt(move _6) -> [0: bb6, 1: bb4, otherwise: bb5]; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
56+
}
57+
58+
bb4: {
59+
_0 = Option::<u32>::None; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
60+
goto -> bb7; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
61+
}
62+
63+
bb5: {
64+
unreachable; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
65+
}
66+
67+
bb6: {
68+
_7 = move ((_2 as Ok).0: u32); // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
69+
_0 = Option::<u32>::Some(move _7); // scope 4 at $SRC_DIR/core/src/result.rs:LL:COL
70+
goto -> bb7; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL
71+
}
72+
73+
bb7: {
74+
StorageDead(_7); // scope 0 at $DIR/transient_enums.rs:+1:18: +1:22
75+
StorageDead(_2); // scope 0 at $DIR/transient_enums.rs:+1:21: +1:22
76+
return; // scope 0 at $DIR/transient_enums.rs:+2:2: +2:2
77+
}
78+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=0
2+
// ignore-debug
3+
// edition: 2021
4+
5+
#![crate_type = "lib"]
6+
7+
// EMIT_MIR transient_enums.checked_as_u32.PreCodegen.after.mir
8+
pub fn checked_as_u32(t: u64) -> Option<u32> {
9+
t.try_into().ok()
10+
}

0 commit comments

Comments
 (0)