File tree 1 file changed +11
-9
lines changed
1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -305,20 +305,22 @@ pub struct Foo {
305
305
306
306
///////////////////////////////////////////////////////////
307
307
// Example usage that will break.
308
+ use updated_crate::Foo;
309
+
308
310
fn main() {
309
311
let foo = Foo {
310
312
f1: 1,
311
313
f2: 1000,
312
314
f3: 5,
313
315
};
314
-
316
+
315
317
let foo_ptr = &foo as *const Foo as *const u8;
316
-
318
+
317
319
// this is now unsound because of the change
318
320
// SAFETY: Foo is repr(C), so we are guaranteed that there will be `3` at this offset (u8, 8 pad, u16)
319
- let f2 = unsafe { foo_ptr.offset(4).read() };
320
-
321
- println!("{}", f2 );
321
+ let f3 = unsafe { foo_ptr.offset(4).read() };
322
+
323
+ assert_eq!(5, f3 );
322
324
}
323
325
```
324
326
@@ -534,12 +536,12 @@ pub enum Number {
534
536
///////////////////////////////////////////////////////////
535
537
// Example usage that will break.
536
538
fn main() {
537
- let num_three = Number::Three;
538
-
539
+ let num_three = updated_crate:: Number::Three;
540
+
539
541
// SAFETY: `Number` is `#[repr(i32)]`
540
542
let three: i32 = unsafe { std::mem::transmute(num_three) }; // Error: cannot transmute between types of different sizes
541
-
542
- println!("{}" , three)
543
+
544
+ assert_eq!(3 , three)
543
545
}
544
546
```
545
547
You can’t perform that action at this time.
0 commit comments