Skip to content

Commit 71fc538

Browse files
committed
patch enums that require zero discriminant
1 parent 9c0558a commit 71fc538

18 files changed

+75
-55
lines changed

compiler/rustc_codegen_ssa/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum IntPredicate {
2727
}
2828

2929
pub enum RealPredicate {
30-
RealPredicateFalse,
30+
RealPredicateFalse = 0, // FIXME(bonega)
3131
RealOEQ,
3232
RealOGT,
3333
RealOGE,

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2631,7 +2631,7 @@ impl Item<'_> {
26312631
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
26322632
#[derive(Encodable, Decodable, HashStable_Generic)]
26332633
pub enum Unsafety {
2634-
Unsafe,
2634+
Unsafe = 0, //FIXME(bonega)
26352635
Normal,
26362636
}
26372637

compiler/rustc_hir/src/lang_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_span::Span;
2020
use std::lazy::SyncLazy;
2121

2222
pub enum LangItemGroup {
23-
Op,
23+
Op = 0, //FIXME(bonega)
2424
}
2525

2626
const NUM_GROUPS: usize = 1;
@@ -44,6 +44,7 @@ macro_rules! language_item_table {
4444
enum_from_u32! {
4545
/// A representation of all the valid language items in Rust.
4646
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
47+
#[repr(u32)]
4748
pub enum LangItem {
4849
$(
4950
#[doc = concat!("The `", stringify!($name), "` lang item.")]

compiler/rustc_parse_format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub enum Alignment {
125125
#[derive(Copy, Clone, Debug, PartialEq)]
126126
pub enum Flag {
127127
/// A `+` will be used to denote positive numbers.
128-
FlagSignPlus,
128+
FlagSignPlus = 0, //FIXME(bonega)
129129
/// A `-` will be used to denote negative numbers. This is the default.
130130
FlagSignMinus,
131131
/// An alternate form will be used for the value. In the case of numbers,

compiler/rustc_type_ir/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl DebruijnIndex {
240240
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
241241
#[derive(Encodable, Decodable)]
242242
pub enum IntTy {
243-
Isize,
243+
Isize = 0, //FIXME(bonega)
244244
I8,
245245
I16,
246246
I32,
@@ -287,7 +287,7 @@ impl IntTy {
287287
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
288288
#[derive(Encodable, Decodable)]
289289
pub enum UintTy {
290-
Usize,
290+
Usize = 0, //FIXME(bonega)
291291
U8,
292292
U16,
293293
U32,
@@ -334,7 +334,7 @@ impl UintTy {
334334
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
335335
#[derive(Encodable, Decodable)]
336336
pub enum FloatTy {
337-
F32,
337+
F32 = 0, //FIXME(bonega)
338338
F64,
339339
}
340340

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<'a> ArgumentV1<'a> {
343343
// flags available in the v1 format of format_args
344344
#[derive(Copy, Clone)]
345345
enum FlagV1 {
346-
SignPlus,
346+
SignPlus = 0, //FIXME(bonega)
347347
SignMinus,
348348
Alternate,
349349
SignAwareZeroPad,

library/std/src/sync/mpsc/oneshot.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,23 @@ pub struct Packet<T> {
5252
upgrade: UnsafeCell<MyUpgrade<T>>,
5353
}
5454

55+
#[repr(usize)]
5556
pub enum Failure<T> {
56-
Empty,
57+
Empty = 0, //FIXME(bonega) repr
5758
Disconnected,
5859
Upgraded(Receiver<T>),
5960
}
6061

62+
#[repr(usize)]
6163
pub enum UpgradeResult {
62-
UpSuccess,
64+
UpSuccess = 0, //FIXME(bonega) repr
6365
UpDisconnected,
6466
UpWoke(SignalToken),
6567
}
6668

69+
#[repr(usize)]
6770
enum MyUpgrade<T> {
68-
NothingSent,
71+
NothingSent = 0, //FIXME(bonega) repr
6972
SendUsed,
7073
GoUp(Receiver<T>),
7174
}

src/test/codegen/enum-bounds-check.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#![crate_type = "lib"]
44

55
pub enum Foo {
6-
A, B
6+
A = 0,
7+
B,
78
}
89

910
// CHECK-LABEL: @lookup
@@ -15,7 +16,7 @@ pub fn lookup(buf: &[u8; 2], f: Foo) -> u8 {
1516

1617
pub enum Bar {
1718
A = 2,
18-
B = 3
19+
B = 3,
1920
}
2021

2122
// CHECK-LABEL: @lookup_unmodified

src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
bb0: {
1010
_2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:11:11: 11:12
11-
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:11:5: 11:12
11+
switchInt(move _2) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:11:5: 11:12
1212
}
1313

1414
bb1: {

src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
bb0: {
1212
- StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1313
- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20
14-
- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
14+
- switchInt(move _3) -> [2_isize: bb2, 3_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1515
+ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20
16-
+ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
16+
+ switchInt(move _2) -> [2_isize: bb2, 3_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1717
}
1818

1919
bb1: {

src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@
106106
// + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r i32, &'s i32, std::option::Option<std::fmt::Arguments<'t0>>) -> ! {core::panicking::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
107107
// ty::Const
108108
// + ty: core::panicking::AssertKind
109-
// + val: Value(Scalar(0x00))
109+
// + val: Value(Scalar(0x01))
110110
// mir::Constant
111111
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
112-
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x00)) }
112+
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x01)) }
113113
}
114114

115115
bb2: {

src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@
119119
_22 = const core::panicking::AssertKind::Eq; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
120120
// ty::Const
121121
// + ty: core::panicking::AssertKind
122-
// + val: Value(Scalar(0x00))
122+
// + val: Value(Scalar(0x01))
123123
// mir::Constant
124124
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
125-
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x00)) }
125+
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x01)) }
126126
StorageLive(_23); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
127127
StorageLive(_24); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
128128
_24 = _13; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -139,10 +139,10 @@
139139
// + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r i32, &'s i32, std::option::Option<std::fmt::Arguments<'t0>>) -> ! {core::panicking::assert_failed::<i32, i32>}, val: Value(Scalar(<ZST>)) }
140140
// ty::Const
141141
// + ty: core::panicking::AssertKind
142-
// + val: Value(Scalar(0x00))
142+
// + val: Value(Scalar(0x01))
143143
// mir::Constant
144144
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
145-
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x00)) }
145+
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x01)) }
146146
}
147147

148148
bb4: {

src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
bb0: {
1010
_2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:12:11: 12:12
11-
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12
11+
switchInt(move _2) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12
1212
}
1313

1414
bb1: {

src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
bb0: {
1010
_2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:20:11: 20:12
11-
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12
11+
switchInt(move _2) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12
1212
}
1313

1414
bb1: {

src/test/mir-opt/simplify_locals.d2.SimplifyLocals.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
- (_2.1: E) = const E::A; // scope 0 at $DIR/simplify-locals.rs:28:6: 28:16
1818
- // ty::Const
1919
- // + ty: E
20-
- // + val: Value(Scalar(0x00))
20+
- // + val: Value(Scalar(0x01))
2121
- // mir::Constant
2222
- // + span: $DIR/simplify-locals.rs:28:6: 28:16
23-
- // + literal: Const { ty: E, val: Value(Scalar(0x00)) }
23+
- // + literal: Const { ty: E, val: Value(Scalar(0x01)) }
2424
- StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:28:15: 28:16
2525
- (_2.1: E) = const E::B; // scope 0 at $DIR/simplify-locals.rs:28:5: 28:26
2626
- // ty::Const
2727
- // + ty: E
28-
- // + val: Value(Scalar(0x01))
28+
- // + val: Value(Scalar(0x02))
2929
- // mir::Constant
3030
- // + span: $DIR/simplify-locals.rs:28:5: 28:26
31-
- // + literal: Const { ty: E, val: Value(Scalar(0x01)) }
31+
- // + literal: Const { ty: E, val: Value(Scalar(0x02)) }
3232
- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:28:25: 28:26
3333
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:28:26: 28:27
3434
return; // scope 0 at $DIR/simplify-locals.rs:29:2: 29:2

src/test/ui/consts/const-enum-cast.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
// run-pass
22
#![allow(non_upper_case_globals)]
33

4-
enum A { A1, A2 }
5-
enum B { B1=4, B2=2 }
4+
enum A {
5+
A1,
6+
A2,
7+
}
8+
enum B {
9+
B1 = 4,
10+
B2 = 2,
11+
}
612

7-
pub fn main () {
13+
pub fn main() {
814
static c1: isize = A::A2 as isize;
915
static c2: isize = B::B2 as isize;
1016
let a1 = A::A2 as isize;
@@ -15,12 +21,24 @@ pub fn main () {
1521
assert_eq!(a2, 2);
1622

1723
// Turns out that adding a let-binding generates totally different MIR.
18-
static c1_2: isize = { let v = A::A1; v as isize };
19-
static c2_2: isize = { let v = B::B1; v as isize };
20-
let a1_2 = { let v = A::A1; v as isize };
21-
let a2_2 = { let v = B::B1; v as isize };
22-
assert_eq!(c1_2, 0);
24+
static c1_2: isize = {
25+
let v = A::A1;
26+
v as isize
27+
};
28+
static c2_2: isize = {
29+
let v = B::B1;
30+
v as isize
31+
};
32+
let a1_2 = {
33+
let v = A::A1;
34+
v as isize
35+
};
36+
let a2_2 = {
37+
let v = B::B1;
38+
v as isize
39+
};
40+
assert_eq!(c1_2, 1);
2341
assert_eq!(c2_2, 4);
24-
assert_eq!(a1_2, 0);
42+
assert_eq!(a1_2, 1);
2543
assert_eq!(a2_2, 4);
2644
}

src/test/ui/enum-discriminant/discriminant_size.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ enum E4 {
3030
fn main() {
3131
let mut target: [isize; 3] = [0, 0, 0];
3232
target[1] = discriminant_value(&E1::A);
33-
assert_eq!(target, [0, 0, 0]);
34-
target[1] = discriminant_value(&E1::B);
3533
assert_eq!(target, [0, 1, 0]);
34+
target[1] = discriminant_value(&E1::B);
35+
assert_eq!(target, [0, 2, 0]);
3636

3737
let mut target: [i8; 3] = [0, 0, 0];
3838
target[1] = discriminant_value(&E2::A);

src/test/ui/enum-discriminant/discriminant_value.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,49 @@ enum CLike1 {
99
A,
1010
B,
1111
C,
12-
D
12+
D,
1313
}
1414

1515
enum CLike2 {
1616
A = 5,
1717
B = 2,
1818
C = 19,
19-
D
19+
D,
2020
}
2121

2222
#[repr(i8)]
2323
enum CLike3 {
2424
A = 5,
2525
B,
2626
C = -1,
27-
D
27+
D,
2828
}
2929

3030
enum ADT {
3131
First(u32, u32),
32-
Second(u64)
32+
Second(u64),
3333
}
3434

3535
enum NullablePointer {
3636
Something(&'static u32),
37-
Nothing
37+
Nothing,
3838
}
3939

40-
static CONST : u32 = 0xBEEF;
40+
static CONST: u32 = 0xBEEF;
4141

4242
#[allow(dead_code)]
4343
#[repr(isize)]
4444
enum Mixed {
4545
Unit = 3,
4646
Tuple(u16) = 2,
47-
Struct {
48-
a: u8,
49-
b: u16,
50-
} = 1,
47+
Struct { a: u8, b: u16 } = 1,
5148
}
5249

5350
pub fn main() {
54-
assert_eq!(discriminant_value(&CLike1::A), 0isize);
55-
assert_eq!(discriminant_value(&CLike1::B), 1);
56-
assert_eq!(discriminant_value(&CLike1::C), 2);
57-
assert_eq!(discriminant_value(&CLike1::D), 3);
51+
assert_eq!(discriminant_value(&CLike1::A), 1isize);
52+
assert_eq!(discriminant_value(&CLike1::B), 2);
53+
assert_eq!(discriminant_value(&CLike1::C), 3);
54+
assert_eq!(discriminant_value(&CLike1::D), 4);
5855

5956
assert_eq!(discriminant_value(&CLike2::A), 5isize);
6057
assert_eq!(discriminant_value(&CLike2::B), 2);
@@ -66,7 +63,7 @@ pub fn main() {
6663
assert_eq!(discriminant_value(&CLike3::C), -1);
6764
assert_eq!(discriminant_value(&CLike3::D), 0);
6865

69-
assert_eq!(discriminant_value(&ADT::First(0,0)), 0isize);
66+
assert_eq!(discriminant_value(&ADT::First(0, 0)), 0isize);
7067
assert_eq!(discriminant_value(&ADT::Second(5)), 1);
7168

7269
assert_eq!(discriminant_value(&NullablePointer::Nothing), 1isize);
@@ -77,5 +74,5 @@ pub fn main() {
7774

7875
assert_eq!(discriminant_value(&Mixed::Unit), 3isize);
7976
assert_eq!(discriminant_value(&Mixed::Tuple(5)), 2);
80-
assert_eq!(discriminant_value(&Mixed::Struct{a: 7, b: 11}), 1);
77+
assert_eq!(discriminant_value(&Mixed::Struct { a: 7, b: 11 }), 1);
8178
}

0 commit comments

Comments
 (0)