mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
fix: Split toolchain and datalayout out of CrateData
This commit is contained in:
parent
a01655552d
commit
b1404d387a
22 changed files with 246 additions and 345 deletions
|
@ -1,5 +1,5 @@
|
|||
//! A set of high-level utility fixture methods to use in tests.
|
||||
use std::{mem, ops::Not, str::FromStr, sync};
|
||||
use std::{iter, mem, ops::Not, str::FromStr, sync};
|
||||
|
||||
use base_db::{
|
||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, DependencyKind,
|
||||
|
@ -118,8 +118,14 @@ impl ChangeFixture {
|
|||
ra_fixture: &str,
|
||||
mut proc_macro_defs: Vec<(String, ProcMacro)>,
|
||||
) -> ChangeFixture {
|
||||
let FixtureWithProjectMeta { fixture, mini_core, proc_macro_names, toolchain } =
|
||||
FixtureWithProjectMeta::parse(ra_fixture);
|
||||
let FixtureWithProjectMeta {
|
||||
fixture,
|
||||
mini_core,
|
||||
proc_macro_names,
|
||||
toolchain,
|
||||
target_data_layout,
|
||||
} = FixtureWithProjectMeta::parse(ra_fixture);
|
||||
let target_data_layout = Ok(target_data_layout.into());
|
||||
let toolchain = Some({
|
||||
let channel = toolchain.as_deref().unwrap_or("stable");
|
||||
Version::parse(&format!("1.76.0-{channel}")).unwrap()
|
||||
|
@ -131,7 +137,6 @@ impl ChangeFixture {
|
|||
let mut crates = FxHashMap::default();
|
||||
let mut crate_deps = Vec::new();
|
||||
let mut default_crate_root: Option<FileId> = None;
|
||||
let mut default_target_data_layout: Option<String> = None;
|
||||
let mut default_cfg = CfgOptions::default();
|
||||
let mut default_env = Env::new_for_test_fixture();
|
||||
|
||||
|
@ -187,11 +192,6 @@ impl ChangeFixture {
|
|||
meta.env,
|
||||
false,
|
||||
origin,
|
||||
meta.target_data_layout
|
||||
.as_deref()
|
||||
.map(From::from)
|
||||
.ok_or_else(|| "target_data_layout unset".into()),
|
||||
toolchain.clone(),
|
||||
);
|
||||
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||
assert!(prev.is_none(), "multiple crates with same name: {}", crate_name);
|
||||
|
@ -205,7 +205,6 @@ impl ChangeFixture {
|
|||
default_crate_root = Some(file_id);
|
||||
default_cfg.extend(meta.cfg.into_iter());
|
||||
default_env.extend(meta.env.iter().map(|(x, y)| (x.to_owned(), y.to_owned())));
|
||||
default_target_data_layout = meta.target_data_layout;
|
||||
}
|
||||
|
||||
source_change.change_file(file_id, Some(text.into()));
|
||||
|
@ -228,10 +227,6 @@ impl ChangeFixture {
|
|||
default_env,
|
||||
false,
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
default_target_data_layout
|
||||
.map(|it| it.into())
|
||||
.ok_or_else(|| "target_data_layout unset".into()),
|
||||
toolchain.clone(),
|
||||
);
|
||||
} else {
|
||||
for (from, to, prelude) in crate_deps {
|
||||
|
@ -250,10 +245,6 @@ impl ChangeFixture {
|
|||
.unwrap();
|
||||
}
|
||||
}
|
||||
let target_layout = crate_graph.iter().next().map_or_else(
|
||||
|| Err("target_data_layout unset".into()),
|
||||
|it| crate_graph[it].target_layout.clone(),
|
||||
);
|
||||
|
||||
if let Some(mini_core) = mini_core {
|
||||
let core_file = file_id;
|
||||
|
@ -277,8 +268,6 @@ impl ChangeFixture {
|
|||
Env::new_for_test_fixture(),
|
||||
false,
|
||||
CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||
target_layout.clone(),
|
||||
toolchain.clone(),
|
||||
);
|
||||
|
||||
for krate in all_crates {
|
||||
|
@ -322,8 +311,6 @@ impl ChangeFixture {
|
|||
Env::new_for_test_fixture(),
|
||||
true,
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
target_layout,
|
||||
toolchain,
|
||||
);
|
||||
proc_macros.insert(proc_macros_crate, Ok(proc_macro));
|
||||
|
||||
|
@ -346,17 +333,20 @@ impl ChangeFixture {
|
|||
SourceRootKind::Library => SourceRoot::new_library(mem::take(&mut file_set)),
|
||||
};
|
||||
roots.push(root);
|
||||
source_change.set_roots(roots);
|
||||
source_change.set_crate_graph(crate_graph);
|
||||
|
||||
ChangeFixture {
|
||||
file_position,
|
||||
files,
|
||||
change: Change {
|
||||
source_change,
|
||||
proc_macros: proc_macros.is_empty().not().then_some(proc_macros),
|
||||
},
|
||||
}
|
||||
let mut change = Change {
|
||||
source_change,
|
||||
proc_macros: proc_macros.is_empty().not().then_some(proc_macros),
|
||||
toolchains: Some(iter::repeat(toolchain).take(crate_graph.len()).collect()),
|
||||
target_data_layouts: Some(
|
||||
iter::repeat(target_data_layout).take(crate_graph.len()).collect(),
|
||||
),
|
||||
};
|
||||
|
||||
change.source_change.set_roots(roots);
|
||||
change.source_change.set_crate_graph(crate_graph);
|
||||
|
||||
ChangeFixture { file_position, files, change }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,7 +465,6 @@ struct FileMeta {
|
|||
edition: Edition,
|
||||
env: Env,
|
||||
introduce_new_source_root: Option<SourceRootKind>,
|
||||
target_data_layout: Option<String>,
|
||||
}
|
||||
|
||||
impl FileMeta {
|
||||
|
@ -507,7 +496,6 @@ impl FileMeta {
|
|||
edition: f.edition.map_or(Edition::CURRENT, |v| Edition::from_str(&v).unwrap()),
|
||||
env: f.env.into_iter().collect(),
|
||||
introduce_new_source_root,
|
||||
target_data_layout: f.target_data_layout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue