mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Fix data layout of reference to nested unsized structs
This commit is contained in:
parent
f53f9230f0
commit
302bb3c871
3 changed files with 53 additions and 1 deletions
|
@ -2490,6 +2490,37 @@ fn type_error() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsized_field() {
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized, index, slice, transmute
|
||||
use core::mem::transmute;
|
||||
|
||||
struct Slice([u8]);
|
||||
struct Slice2(Slice);
|
||||
|
||||
impl Slice2 {
|
||||
fn as_inner(&self) -> &Slice {
|
||||
&self.0
|
||||
}
|
||||
|
||||
fn as_bytes(&self) -> &[u8] {
|
||||
&self.as_inner().0
|
||||
}
|
||||
}
|
||||
|
||||
const GOAL: u8 = unsafe {
|
||||
let x: &[u8] = &[1, 2, 3];
|
||||
let x: &Slice2 = transmute(x);
|
||||
let x = x.as_bytes();
|
||||
x[0] + x[1] + x[2]
|
||||
};
|
||||
"#,
|
||||
6,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsized_local() {
|
||||
check_fail(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue