mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge commit '37f84c101b
' into sync-from-ra
This commit is contained in:
parent
6502421771
commit
4704881b64
311 changed files with 13700 additions and 9110 deletions
|
@ -31,7 +31,9 @@ pub fn layout_of_adt_query(
|
|||
subst: Substitution,
|
||||
krate: CrateId,
|
||||
) -> Result<Arc<Layout>, LayoutError> {
|
||||
let Some(target) = db.target_data_layout(krate) else { return Err(LayoutError::TargetLayoutNotAvailable) };
|
||||
let Some(target) = db.target_data_layout(krate) else {
|
||||
return Err(LayoutError::TargetLayoutNotAvailable);
|
||||
};
|
||||
let cx = LayoutCx { krate, target: &target };
|
||||
let dl = cx.current_data_layout();
|
||||
let handle_variant = |def: VariantId, var: &VariantData| {
|
||||
|
@ -70,9 +72,9 @@ pub fn layout_of_adt_query(
|
|||
};
|
||||
let variants = variants
|
||||
.iter()
|
||||
.map(|x| x.iter().map(|x| &**x).collect::<Vec<_>>())
|
||||
.map(|it| it.iter().map(|it| &**it).collect::<Vec<_>>())
|
||||
.collect::<SmallVec<[_; 1]>>();
|
||||
let variants = variants.iter().map(|x| x.iter().collect()).collect();
|
||||
let variants = variants.iter().map(|it| it.iter().collect()).collect();
|
||||
let result = if matches!(def, AdtId::UnionId(..)) {
|
||||
cx.layout_of_union(&repr, &variants).ok_or(LayoutError::Unknown)?
|
||||
} else {
|
||||
|
@ -103,7 +105,7 @@ pub fn layout_of_adt_query(
|
|||
&& variants
|
||||
.iter()
|
||||
.next()
|
||||
.and_then(|x| x.last().map(|x| x.is_unsized()))
|
||||
.and_then(|it| it.last().map(|it| !it.is_unsized()))
|
||||
.unwrap_or(true),
|
||||
)
|
||||
.ok_or(LayoutError::SizeOverflow)?
|
||||
|
@ -116,9 +118,9 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
|
|||
let get = |name| {
|
||||
let attr = attrs.by_key(name).tt_values();
|
||||
for tree in attr {
|
||||
if let Some(x) = tree.token_trees.first() {
|
||||
if let Ok(x) = x.to_string().parse() {
|
||||
return Bound::Included(x);
|
||||
if let Some(it) = tree.token_trees.first() {
|
||||
if let Ok(it) = it.to_string().parse() {
|
||||
return Bound::Included(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,6 +270,20 @@ struct Goal(Foo<S>);
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simd_types() {
|
||||
check_size_and_align(
|
||||
r#"
|
||||
#[repr(simd)]
|
||||
struct SimdType(i64, i64);
|
||||
struct Goal(SimdType);
|
||||
"#,
|
||||
"",
|
||||
16,
|
||||
16,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_position_impl_trait() {
|
||||
size_and_align_expr! {
|
||||
|
@ -343,6 +357,24 @@ fn return_position_impl_trait() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsized_ref() {
|
||||
size_and_align! {
|
||||
struct S1([u8]);
|
||||
struct S2(S1);
|
||||
struct S3(i32, str);
|
||||
struct S4(u64, S3);
|
||||
#[allow(dead_code)]
|
||||
struct S5 {
|
||||
field1: u8,
|
||||
field2: i16,
|
||||
field_last: S4,
|
||||
}
|
||||
|
||||
struct Goal(&'static S1, &'static S2, &'static S3, &'static S4, &'static S5);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enums() {
|
||||
size_and_align! {
|
||||
|
@ -369,11 +401,11 @@ fn tuple() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn non_zero() {
|
||||
fn non_zero_and_non_null() {
|
||||
size_and_align! {
|
||||
minicore: non_zero, option;
|
||||
use core::num::NonZeroU8;
|
||||
struct Goal(Option<NonZeroU8>);
|
||||
minicore: non_zero, non_null, option;
|
||||
use core::{num::NonZeroU8, ptr::NonNull};
|
||||
struct Goal(Option<NonZeroU8>, Option<NonNull<i32>>);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,3 +464,41 @@ fn enums_with_discriminants() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn core_mem_discriminant() {
|
||||
size_and_align! {
|
||||
minicore: discriminant;
|
||||
struct S(i32, u64);
|
||||
struct Goal(core::mem::Discriminant<S>);
|
||||
}
|
||||
size_and_align! {
|
||||
minicore: discriminant;
|
||||
#[repr(u32)]
|
||||
enum S {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
struct Goal(core::mem::Discriminant<S>);
|
||||
}
|
||||
size_and_align! {
|
||||
minicore: discriminant;
|
||||
enum S {
|
||||
A(i32),
|
||||
B(i64),
|
||||
C(u8),
|
||||
}
|
||||
struct Goal(core::mem::Discriminant<S>);
|
||||
}
|
||||
size_and_align! {
|
||||
minicore: discriminant;
|
||||
#[repr(C, u16)]
|
||||
enum S {
|
||||
A(i32),
|
||||
B(i64) = 200,
|
||||
C = 1000,
|
||||
}
|
||||
struct Goal(core::mem::Discriminant<S>);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue