offset_of: Don't require type to be sized
This commit is contained in:
parent
99ff5afeb8
commit
6c18d1ecef
2 changed files with 23 additions and 3 deletions
|
@ -668,11 +668,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
|
|
||||||
mir::Rvalue::NullaryOp(ref null_op, ty) => {
|
mir::Rvalue::NullaryOp(ref null_op, ty) => {
|
||||||
let ty = self.monomorphize(ty);
|
let ty = self.monomorphize(ty);
|
||||||
assert!(bx.cx().type_is_sized(ty));
|
|
||||||
let layout = bx.cx().layout_of(ty);
|
let layout = bx.cx().layout_of(ty);
|
||||||
let val = match null_op {
|
let val = match null_op {
|
||||||
mir::NullOp::SizeOf => layout.size.bytes(),
|
mir::NullOp::SizeOf => {
|
||||||
mir::NullOp::AlignOf => layout.align.abi.bytes(),
|
assert!(bx.cx().type_is_sized(ty));
|
||||||
|
layout.size.bytes()
|
||||||
|
}
|
||||||
|
mir::NullOp::AlignOf => {
|
||||||
|
assert!(bx.cx().type_is_sized(ty));
|
||||||
|
layout.align.abi.bytes()
|
||||||
|
}
|
||||||
mir::NullOp::OffsetOf(fields) => {
|
mir::NullOp::OffsetOf(fields) => {
|
||||||
layout.offset_of_subfield(bx.cx(), fields.iter().map(|f| f.index())).bytes()
|
layout.offset_of_subfield(bx.cx(), fields.iter().map(|f| f.index())).bytes()
|
||||||
}
|
}
|
||||||
|
|
15
tests/ui/offset-of/offset-of-unsized.rs
Normal file
15
tests/ui/offset-of/offset-of-unsized.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// build-pass
|
||||||
|
// regression test for #112051
|
||||||
|
|
||||||
|
#![feature(offset_of)]
|
||||||
|
|
||||||
|
struct S<T: ?Sized> {
|
||||||
|
a: u64,
|
||||||
|
b: T,
|
||||||
|
}
|
||||||
|
trait Tr {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _a = core::mem::offset_of!(S<dyn Tr>, a);
|
||||||
|
let _b = core::mem::offset_of!((u64, dyn Tr), 0);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue