mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Fix size_of_val and support min_align_of_val
This commit is contained in:
parent
537f9b311d
commit
171ae2ee5d
7 changed files with 221 additions and 89 deletions
|
@ -2456,20 +2456,6 @@ fn const_trait_assoc() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_messages() {
|
||||
check_fail(
|
||||
r#"
|
||||
//- minicore: panic
|
||||
const GOAL: u8 = {
|
||||
let x: u16 = 2;
|
||||
panic!("hello");
|
||||
};
|
||||
"#,
|
||||
|e| e == ConstEvalError::MirEvalError(MirEvalError::Panic("hello".to_string())),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_limits() {
|
||||
check_fail(
|
||||
|
|
|
@ -43,6 +43,50 @@ fn size_of_val() {
|
|||
"#,
|
||||
12,
|
||||
);
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized, transmute
|
||||
use core::mem::transmute;
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
}
|
||||
|
||||
struct X {
|
||||
x: i64,
|
||||
y: u8,
|
||||
t: [i32],
|
||||
}
|
||||
|
||||
const GOAL: usize = unsafe {
|
||||
let y: &X = transmute([0usize, 3]);
|
||||
size_of_val(y)
|
||||
};
|
||||
"#,
|
||||
24,
|
||||
);
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized, transmute
|
||||
use core::mem::transmute;
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
}
|
||||
|
||||
struct X {
|
||||
x: i32,
|
||||
y: i64,
|
||||
t: [u8],
|
||||
}
|
||||
|
||||
const GOAL: usize = unsafe {
|
||||
let y: &X = transmute([0usize, 15]);
|
||||
size_of_val(y)
|
||||
};
|
||||
"#,
|
||||
32,
|
||||
);
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized, fmt, builtin_impls
|
||||
|
@ -74,6 +118,37 @@ fn size_of_val() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn min_align_of_val() {
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized
|
||||
extern "rust-intrinsic" {
|
||||
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
}
|
||||
|
||||
struct X(i32, u8);
|
||||
|
||||
const GOAL: usize = min_align_of_val(&X(1, 2));
|
||||
"#,
|
||||
4,
|
||||
);
|
||||
check_number(
|
||||
r#"
|
||||
//- minicore: coerce_unsized
|
||||
extern "rust-intrinsic" {
|
||||
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
}
|
||||
|
||||
const GOAL: usize = {
|
||||
let x: &[i32] = &[1, 2, 3];
|
||||
min_align_of_val(x)
|
||||
};
|
||||
"#,
|
||||
4,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transmute() {
|
||||
check_number(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue