forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#97738 - Kixiron:zst-panic, r=eddyb
Fix ICEs from zsts within unsized types with non-zero offsets - Fixes rust-lang#97732 - Fixes ICEs while compiling `alloc` with `-Z randomize-layout` r? `@eddyb`
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// check-pass | ||
|
||
#![feature(coerce_unsized)] | ||
|
||
// Ensure that unsizing structs that contain ZSTs at non-zero offsets don't ICE | ||
|
||
use std::ops::CoerceUnsized; | ||
|
||
#[repr(C)] | ||
pub struct BoxWithZstTail<T: ?Sized>(Box<T>, ()); | ||
|
||
impl<S: ?Sized, T: ?Sized> CoerceUnsized<BoxWithZstTail<T>> for BoxWithZstTail<S> where | ||
Box<S>: CoerceUnsized<Box<T>> | ||
{ | ||
} | ||
|
||
pub fn noop_dyn_upcast_with_zst_tail( | ||
b: BoxWithZstTail<dyn ToString + Send>, | ||
) -> BoxWithZstTail<dyn ToString> { | ||
b | ||
} | ||
|
||
fn main() { | ||
let original = "foo"; | ||
let boxed = BoxWithZstTail(Box::new(original) as Box<dyn ToString + Send>, ()); | ||
let noop_upcasted = noop_dyn_upcast_with_zst_tail(boxed); | ||
assert_eq!(original, noop_upcasted.0.to_string()); | ||
} |