mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge commit 'cd3bf9fe51
' into sync-from-ra
This commit is contained in:
parent
bbd695589e
commit
9326cf7f0c
114 changed files with 3893 additions and 1252 deletions
|
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use base_db::fixture::WithFixture;
|
||||
use chalk_ir::{AdtId, TyKind};
|
||||
use either::Either;
|
||||
use hir_def::db::DefDatabase;
|
||||
use triomphe::Arc;
|
||||
|
||||
|
@ -25,27 +26,38 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutErro
|
|||
);
|
||||
|
||||
let (db, file_ids) = TestDB::with_many_files(&ra_fixture);
|
||||
let (adt_id, module_id) = file_ids
|
||||
let (adt_or_type_alias_id, module_id) = file_ids
|
||||
.into_iter()
|
||||
.find_map(|file_id| {
|
||||
let module_id = db.module_for_file(file_id);
|
||||
let def_map = module_id.def_map(&db);
|
||||
let scope = &def_map[module_id.local_id].scope;
|
||||
let adt_id = scope.declarations().find_map(|x| match x {
|
||||
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.to_smol_str(),
|
||||
hir_def::AdtId::UnionId(x) => db.union_data(x).name.to_smol_str(),
|
||||
hir_def::AdtId::EnumId(x) => db.enum_data(x).name.to_smol_str(),
|
||||
};
|
||||
(name == "Goal").then_some(x)
|
||||
(name == "Goal").then_some(Either::Left(x))
|
||||
}
|
||||
hir_def::ModuleDefId::TypeAliasId(x) => {
|
||||
let name = db.type_alias_data(x).name.to_smol_str();
|
||||
(name == "Goal").then_some(Either::Right(x))
|
||||
}
|
||||
_ => None,
|
||||
})?;
|
||||
Some((adt_id, module_id))
|
||||
Some((adt_or_type_alias_id, module_id))
|
||||
})
|
||||
.unwrap();
|
||||
let goal_ty = TyKind::Adt(AdtId(adt_id), Substitution::empty(Interner)).intern(Interner);
|
||||
let goal_ty = match adt_or_type_alias_id {
|
||||
Either::Left(adt_id) => {
|
||||
TyKind::Adt(AdtId(adt_id), Substitution::empty(Interner)).intern(Interner)
|
||||
}
|
||||
Either::Right(ty_id) => {
|
||||
db.ty(ty_id.into()).substitute(Interner, &Substitution::empty(Interner))
|
||||
}
|
||||
};
|
||||
db.layout_of_ty(goal_ty, module_id.krate())
|
||||
}
|
||||
|
||||
|
@ -379,10 +391,23 @@ fn niche_optimization() {
|
|||
|
||||
#[test]
|
||||
fn const_eval() {
|
||||
size_and_align! {
|
||||
struct Goal([i32; 2 + 2]);
|
||||
}
|
||||
size_and_align! {
|
||||
const X: usize = 5;
|
||||
struct Goal([i32; X]);
|
||||
}
|
||||
size_and_align! {
|
||||
mod foo {
|
||||
pub(super) const BAR: usize = 5;
|
||||
}
|
||||
struct Ar<T>([T; foo::BAR]);
|
||||
struct Goal(Ar<Ar<i32>>);
|
||||
}
|
||||
size_and_align! {
|
||||
type Goal = [u8; 2 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue