@@ -66,8 +66,8 @@ LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_cons
66
66
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
67
67
--> $DIR/reference_casting.rs:35:16
68
68
|
69
- LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32 );
70
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69
+ LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i8 );
70
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
71
|
72
72
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
73
73
@@ -373,5 +373,103 @@ LL | *(this as *const _ as *mut _) = a;
373
373
|
374
374
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
375
375
376
- error: aborting due to 42 previous errors
376
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
377
+ --> $DIR/reference_casting.rs:163:20
378
+ |
379
+ LL | let _num = &*(num as *const i32 as *const i64);
380
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
381
+ |
382
+ = note: casting from `i32` (size: 4 bytes, align: 4 bytes) to `i64` (size: 8 bytes, align: 8 bytes)
383
+
384
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
385
+ --> $DIR/reference_casting.rs:165:20
386
+ |
387
+ LL | let _num = &mut *(num as *mut i32 as *mut i64);
388
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
389
+ |
390
+ = note: casting from `i32` (size: 4 bytes, align: 4 bytes) to `i64` (size: 8 bytes, align: 8 bytes)
391
+
392
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
393
+ --> $DIR/reference_casting.rs:167:20
394
+ |
395
+ LL | let _num = &mut *(num as *mut i32 as *mut I64);
396
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
397
+ |
398
+ = note: casting from `i32` (size: 4 bytes, align: 4 bytes) to `I64` (size: 16 bytes, align: 16 bytes)
399
+
400
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
401
+ --> $DIR/reference_casting.rs:169:9
402
+ |
403
+ LL | std::ptr::write(num as *mut i32 as *mut i64, 2);
404
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
405
+ |
406
+ = note: casting from `i32` (size: 4 bytes, align: 4 bytes) to `i64` (size: 8 bytes, align: 8 bytes)
407
+
408
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
409
+ --> $DIR/reference_casting.rs:178:20
410
+ |
411
+ LL | let _num = &mut *(num as *mut _ as *mut [i64; 2]);
412
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
413
+ |
414
+ = note: casting from `[i32; 3]` (size: 12 bytes, align: 4 bytes) to `[i64; 2]` (size: 16 bytes, align: 8 bytes)
415
+
416
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
417
+ --> $DIR/reference_casting.rs:180:9
418
+ |
419
+ LL | std::ptr::write_unaligned(num as *mut _ as *mut [i32; 4], [0, 0, 1, 1]);
420
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
421
+ |
422
+ = note: casting from `[i32; 3]` (size: 12 bytes, align: 4 bytes) to `[i32; 4]` (size: 16 bytes, align: 4 bytes)
423
+
424
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
425
+ --> $DIR/reference_casting.rs:190:20
426
+ |
427
+ LL | let _num = &mut *(num as *mut _ as *mut [i64]);
428
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429
+ |
430
+ = note: casting from `[i32; 3]` (size: 12 bytes, align: 4 bytes) to `[i64]` (size: 0 bytes, align: 8 bytes)
431
+
432
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
433
+ --> $DIR/reference_casting.rs:192:20
434
+ |
435
+ LL | let _num = &mut *(num as *mut _ as *mut [i64; 4]);
436
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
437
+ |
438
+ = note: casting from `[i32; 3]` (size: 12 bytes, align: 4 bytes) to `[i64; 4]` (size: 32 bytes, align: 8 bytes)
439
+
440
+ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
441
+ --> $DIR/reference_casting.rs:202:20
442
+ |
443
+ LL | let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
444
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
445
+ |
446
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
447
+
448
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
449
+ --> $DIR/reference_casting.rs:202:20
450
+ |
451
+ LL | let _num = &mut *(&mat3 as *const _ as *mut [[i64; 3]; 3]);
452
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
453
+ |
454
+ = note: casting from `Mat3<i32>` (size: 36 bytes, align: 4 bytes) to `[[i64; 3]; 3]` (size: 72 bytes, align: 8 bytes)
455
+
456
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
457
+ --> $DIR/reference_casting.rs:205:20
458
+ |
459
+ LL | let _num = &*(&mat3 as *const _ as *mut [[i64; 3]; 3]);
460
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
461
+ |
462
+ = note: casting from `Mat3<i32>` (size: 36 bytes, align: 4 bytes) to `[[i64; 3]; 3]` (size: 72 bytes, align: 8 bytes)
463
+
464
+ error: casting references to a bigger memory layout is undefined behavior, even if the reference is unused
465
+ --> $DIR/reference_casting.rs:214:37
466
+ |
467
+ LL | let w: *mut [u16; 2] = &mut l as *mut [u8; 2] as *mut _;
468
+ | -------------------------------- casting happend here
469
+ LL | let w: *mut [u16] = unsafe {&mut *w};
470
+ | ^^^^^^^
471
+ |
472
+ = note: casting from `[u8; 2]` (size: 2 bytes, align: 1 bytes) to `[u16; 2]` (size: 4 bytes, align: 2 bytes)
473
+
474
+ error: aborting due to 54 previous errors
377
475
0 commit comments