Skip to content

Commit d24336b

Browse files
authored
Rollup merge of rust-lang#129672 - saethlin:enum-debuginfo-tests, r=Mark-Simulacrum
Make option-like-enum.rs UB-free and portable Fixes rust-lang#129662 (or, at least the parts of it that aren't rust-lang#128973)
2 parents 62b8fdb + 1a2ec26 commit d24336b

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

Diff for: tests/debuginfo/option-like-enum.rs

+14-25
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
// gdb-command:run
99

1010
// gdb-command:print some
11-
// gdb-check:$1 = core::option::Option<&u32>::Some(0x12345678)
11+
// gdb-check:$1 = core::option::Option<&u32>::Some(0x[...])
1212

1313
// gdb-command:print none
1414
// gdb-check:$2 = core::option::Option<&u32>::None
1515

1616
// gdb-command:print full
17-
// gdb-check:$3 = option_like_enum::MoreFields::Full(454545, 0x87654321, 9988)
17+
// gdb-check:$3 = option_like_enum::MoreFields::Full(454545, 0x[...], 9988)
1818

19-
// gdb-command:print empty_gdb.discr
20-
// gdb-check:$4 = (*mut isize) 0x1
19+
// gdb-command:print empty
20+
// gdb-check:$4 = option_like_enum::MoreFields::Empty
2121

2222
// gdb-command:print droid
23-
// gdb-check:$5 = option_like_enum::NamedFields::Droid{id: 675675, range: 10000001, internals: 0x43218765}
23+
// gdb-check:$5 = option_like_enum::NamedFields::Droid{id: 675675, range: 10000001, internals: 0x[...]}
2424

25-
// gdb-command:print void_droid_gdb.internals
26-
// gdb-check:$6 = (*mut isize) 0x1
25+
// gdb-command:print void_droid
26+
// gdb-check:$6 = option_like_enum::NamedFields::Void
2727

2828
// gdb-command:print nested_non_zero_yep
2929
// gdb-check:$7 = option_like_enum::NestedNonZero::Yep(10.5, option_like_enum::NestedNonZeroField {a: 10, b: 20, c: 0x[...]})
@@ -39,19 +39,19 @@
3939
// lldb-command:run
4040

4141
// lldb-command:v some
42-
// lldb-check:[...] Some(&0x12345678)
42+
// lldb-check:[...] Some(&0x[...])
4343

4444
// lldb-command:v none
4545
// lldb-check:[...] None
4646

4747
// lldb-command:v full
48-
// lldb-check:[...] Full(454545, &0x87654321, 9988)
48+
// lldb-check:[...] Full(454545, &0x[...], 9988)
4949

5050
// lldb-command:v empty
5151
// lldb-check:[...] Empty
5252

5353
// lldb-command:v droid
54-
// lldb-check:[...] Droid { id: 675675, range: 10000001, internals: &0x43218765 }
54+
// lldb-check:[...] Droid { id: 675675, range: 10000001, internals: &0x[...] }
5555

5656
// lldb-command:v void_droid
5757
// lldb-check:[...] Void
@@ -76,11 +76,6 @@
7676
// contains a non-nullable pointer, then this value is used as the discriminator.
7777
// The test cases in this file make sure that something readable is generated for
7878
// this kind of types.
79-
// If the non-empty variant contains a single non-nullable pointer than the whole
80-
// item is represented as just a pointer and not wrapped in a struct.
81-
// Unfortunately (for these test cases) the content of the non-discriminant fields
82-
// in the null-case is not defined. So we just read the discriminator field in
83-
// this case (by casting the value to a memory-equivalent struct).
8479

8580
enum MoreFields<'a> {
8681
Full(u32, &'a isize, i16),
@@ -120,32 +115,26 @@ fn main() {
120115
let some_str: Option<&'static str> = Some("abc");
121116
let none_str: Option<&'static str> = None;
122117

123-
let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678_usize) });
118+
let some: Option<&u32> = Some(&1234);
124119
let none: Option<&u32> = None;
125120

126-
let full = MoreFields::Full(454545, unsafe { std::mem::transmute(0x87654321_usize) }, 9988);
127-
121+
let full = MoreFields::Full(454545, &1234, 9988);
128122
let empty = MoreFields::Empty;
129-
let empty_gdb: &MoreFieldsRepr = unsafe { std::mem::transmute(&MoreFields::Empty) };
130123

131124
let droid = NamedFields::Droid {
132125
id: 675675,
133126
range: 10000001,
134-
internals: unsafe { std::mem::transmute(0x43218765_usize) }
127+
internals: &1234,
135128
};
136-
137129
let void_droid = NamedFields::Void;
138-
let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) };
139130

140-
let x = 'x';
141131
let nested_non_zero_yep = NestedNonZero::Yep(
142132
10.5,
143133
NestedNonZeroField {
144134
a: 10,
145135
b: 20,
146-
c: &x
136+
c: &'x',
147137
});
148-
149138
let nested_non_zero_nope = NestedNonZero::Nope;
150139

151140
zzz(); // #break

0 commit comments

Comments
 (0)