Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/layout/tests.rs')
-rw-r--r--crates/hir-ty/src/layout/tests.rs80
1 files changed, 59 insertions, 21 deletions
diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs
index 8b74b7328b..cc7d74f4fb 100644
--- a/crates/hir-ty/src/layout/tests.rs
+++ b/crates/hir-ty/src/layout/tests.rs
@@ -1,17 +1,17 @@
use chalk_ir::{AdtId, TyKind};
use either::Either;
use hir_def::db::DefDatabase;
-use project_model::{toolchain_info::QueryConfig, Sysroot};
+use project_model::{Sysroot, toolchain_info::QueryConfig};
use rustc_hash::FxHashMap;
use syntax::ToSmolStr;
use test_fixture::WithFixture;
use triomphe::Arc;
use crate::{
+ Interner, Substitution,
db::HirDatabase,
layout::{Layout, LayoutError},
test_db::TestDB,
- Interner, Substitution,
};
mod closure;
@@ -38,27 +38,36 @@ fn eval_goal(
let adt_or_type_alias_id = file_ids
.into_iter()
.find_map(|file_id| {
- let module_id = db.module_for_file(file_id.file_id());
+ let module_id = db.module_for_file(file_id.file_id(&db));
let def_map = module_id.def_map(&db);
let scope = &def_map[module_id.local_id].scope;
let adt_or_type_alias_id = scope.declarations().find_map(|x| match x {
hir_def::ModuleDefId::AdtId(x) => {
let name = match x {
- hir_def::AdtId::StructId(x) => {
- db.struct_data(x).name.display_no_db(file_id.edition()).to_smolstr()
- }
- hir_def::AdtId::UnionId(x) => {
- db.union_data(x).name.display_no_db(file_id.edition()).to_smolstr()
- }
- hir_def::AdtId::EnumId(x) => {
- db.enum_data(x).name.display_no_db(file_id.edition()).to_smolstr()
- }
+ hir_def::AdtId::StructId(x) => db
+ .struct_signature(x)
+ .name
+ .display_no_db(file_id.edition(&db))
+ .to_smolstr(),
+ hir_def::AdtId::UnionId(x) => db
+ .union_signature(x)
+ .name
+ .display_no_db(file_id.edition(&db))
+ .to_smolstr(),
+ hir_def::AdtId::EnumId(x) => db
+ .enum_signature(x)
+ .name
+ .display_no_db(file_id.edition(&db))
+ .to_smolstr(),
};
(name == "Goal").then_some(Either::Left(x))
}
hir_def::ModuleDefId::TypeAliasId(x) => {
- let name =
- db.type_alias_data(x).name.display_no_db(file_id.edition()).to_smolstr();
+ let name = db
+ .type_alias_signature(x)
+ .name
+ .display_no_db(file_id.edition(&db))
+ .to_smolstr();
(name == "Goal").then_some(Either::Right(x))
}
_ => None,
@@ -94,14 +103,15 @@ fn eval_expr(
);
let (db, file_id) = TestDB::with_single_file(&ra_fixture);
- let module_id = db.module_for_file(file_id.file_id());
+ let module_id = db.module_for_file(file_id.file_id(&db));
let def_map = module_id.def_map(&db);
let scope = &def_map[module_id.local_id].scope;
let function_id = scope
.declarations()
.find_map(|x| match x {
hir_def::ModuleDefId::FunctionId(x) => {
- let name = db.function_data(x).name.display_no_db(file_id.edition()).to_smolstr();
+ let name =
+ db.function_signature(x).name.display_no_db(file_id.edition(&db)).to_smolstr();
(name == "main").then_some(x)
}
_ => None,
@@ -111,7 +121,7 @@ fn eval_expr(
let b = hir_body
.bindings
.iter()
- .find(|x| x.1.name.display_no_db(file_id.edition()).to_smolstr() == "goal")
+ .find(|x| x.1.name.display_no_db(file_id.edition(&db)).to_smolstr() == "goal")
.unwrap()
.0;
let infer = db.infer(function_id.into());
@@ -285,6 +295,18 @@ fn repr_packed() {
}
#[test]
+fn multiple_repr_attrs() {
+ size_and_align!(
+ #[repr(C)]
+ #[repr(packed)]
+ struct Goal {
+ id: i32,
+ u: u8,
+ }
+ )
+}
+
+#[test]
fn generic() {
size_and_align! {
struct Pair<A, B>(A, B);
@@ -469,6 +491,16 @@ fn tuple() {
}
#[test]
+fn tuple_ptr_with_dst_tail() {
+ size_and_align!(
+ struct Goal(*const ([u8],));
+ );
+ size_and_align!(
+ struct Goal(*const (u128, [u8]));
+ );
+}
+
+#[test]
fn non_zero_and_non_null() {
size_and_align! {
minicore: non_zero, non_null, option;
@@ -490,10 +522,7 @@ fn niche_optimization() {
}
#[test]
-fn const_eval() {
- size_and_align! {
- struct Goal([i32; 2 + 2]);
- }
+fn const_eval_simple() {
size_and_align! {
const X: usize = 5;
struct Goal([i32; X]);
@@ -505,6 +534,15 @@ fn const_eval() {
struct Ar<T>([T; foo::BAR]);
struct Goal(Ar<Ar<i32>>);
}
+}
+
+#[test]
+// FIXME
+#[should_panic]
+fn const_eval_complex() {
+ size_and_align! {
+ struct Goal([i32; 2 + 2]);
+ }
size_and_align! {
type Goal = [u8; 2 + 2];
}