Fix projection of sized field in unsized type

This commit is contained in:
bjorn3 2018-10-06 11:21:18 +02:00
parent aab736a137
commit ab57af4e6a
2 changed files with 16 additions and 0 deletions

View File

@ -196,3 +196,13 @@ fn str_wrapper_get(w: &StrWrapper) -> &str {
fn i16_as_i8(a: i16) -> i8 {
a as i8
}
struct Unsized(u8, str);
fn get_sized_field_ref_from_unsized_type(u: &Unsized) -> &u8 {
&u.0
}
fn get_unsized_field_ref_from_unsized_type(u: &Unsized) -> &str {
&u.1
}

View File

@ -460,6 +460,12 @@ pub fn place_field(
}
CPlace::Addr(base, extra, layout) => {
let (field_ptr, field_layout) = codegen_field(fx, base, layout, field);
let extra = if field_layout.is_unsized() {
assert!(extra.is_some());
extra
} else {
None
};
CPlace::Addr(field_ptr, extra, field_layout)
}
}