mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
reuse fetching target data layout from rustc function
This commit is contained in:
parent
443bc7f193
commit
40cf8b45ac
5 changed files with 12 additions and 20 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -583,6 +583,7 @@ dependencies = [
|
||||||
"limit",
|
"limit",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"profile",
|
"profile",
|
||||||
|
"project-model",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"scoped-tls",
|
"scoped-tls",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
|
|
@ -48,6 +48,7 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
|
||||||
"registry",
|
"registry",
|
||||||
] }
|
] }
|
||||||
tracing-tree = "0.2.1"
|
tracing-tree = "0.2.1"
|
||||||
|
project-model = { path = "../project-model" }
|
||||||
|
|
||||||
# local deps
|
# local deps
|
||||||
test-utils.workspace = true
|
test-utils.workspace = true
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use base_db::fixture::WithFixture;
|
use base_db::fixture::WithFixture;
|
||||||
use chalk_ir::{AdtId, TyKind};
|
use chalk_ir::{AdtId, TyKind};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
@ -9,16 +11,12 @@ use crate::{db::HirDatabase, test_db::TestDB, Interner, Substitution};
|
||||||
|
|
||||||
use super::layout_of_ty;
|
use super::layout_of_ty;
|
||||||
|
|
||||||
fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
|
fn current_machine_data_layout() -> String {
|
||||||
// using unstable cargo features failed, fall back to using plain rustc
|
project_model::target_data_layout::get(None, None, &HashMap::default()).unwrap()
|
||||||
let mut cmd = std::process::Command::new("rustc");
|
}
|
||||||
cmd.args(["-Z", "unstable-options", "--print", "target-spec-json"]).env("RUSTC_BOOTSTRAP", "1");
|
|
||||||
let output = cmd.output().unwrap();
|
|
||||||
assert!(output.status.success(), "{}", output.status);
|
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
||||||
let target_data_layout =
|
|
||||||
stdout.split_once(r#""data-layout": ""#).unwrap().1.split_once('"').unwrap().0.to_owned();
|
|
||||||
|
|
||||||
|
fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
|
||||||
|
let target_data_layout = current_machine_data_layout();
|
||||||
let ra_fixture = format!(
|
let ra_fixture = format!(
|
||||||
"{minicore}//- /main.rs crate:test target_data_layout:{target_data_layout}\n{ra_fixture}",
|
"{minicore}//- /main.rs crate:test target_data_layout:{target_data_layout}\n{ra_fixture}",
|
||||||
);
|
);
|
||||||
|
@ -47,15 +45,7 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
|
||||||
|
|
||||||
/// A version of `eval_goal` for types that can not be expressed in ADTs, like closures and `impl Trait`
|
/// A version of `eval_goal` for types that can not be expressed in ADTs, like closures and `impl Trait`
|
||||||
fn eval_expr(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
|
fn eval_expr(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
|
||||||
// using unstable cargo features failed, fall back to using plain rustc
|
let target_data_layout = current_machine_data_layout();
|
||||||
let mut cmd = std::process::Command::new("rustc");
|
|
||||||
cmd.args(["-Z", "unstable-options", "--print", "target-spec-json"]).env("RUSTC_BOOTSTRAP", "1");
|
|
||||||
let output = cmd.output().unwrap();
|
|
||||||
assert!(output.status.success(), "{}", output.status);
|
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
||||||
let target_data_layout =
|
|
||||||
stdout.split_once(r#""data-layout": ""#).unwrap().1.split_once('"').unwrap().0.to_owned();
|
|
||||||
|
|
||||||
let ra_fixture = format!(
|
let ra_fixture = format!(
|
||||||
"{minicore}//- /main.rs crate:test target_data_layout:{target_data_layout}\nfn main(){{let goal = {{{ra_fixture}}};}}",
|
"{minicore}//- /main.rs crate:test target_data_layout:{target_data_layout}\nfn main(){{let goal = {{{ra_fixture}}};}}",
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,7 +25,7 @@ mod sysroot;
|
||||||
mod workspace;
|
mod workspace;
|
||||||
mod rustc_cfg;
|
mod rustc_cfg;
|
||||||
mod build_scripts;
|
mod build_scripts;
|
||||||
mod target_data_layout;
|
pub mod target_data_layout;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::{utf8_stdout, ManifestPath};
|
use crate::{utf8_stdout, ManifestPath};
|
||||||
|
|
||||||
pub(super) fn get(
|
pub fn get(
|
||||||
cargo_toml: Option<&ManifestPath>,
|
cargo_toml: Option<&ManifestPath>,
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, String>,
|
||||||
|
|
Loading…
Reference in a new issue