From ee10f9f5cdcecd18845e6b516c1f1a5ab5afba41 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 19 Apr 2024 10:41:08 +0200 Subject: [PATCH 1/4] Cleanup cfg and env handling in project-model --- crates/base-db/src/input.rs | 7 +- crates/project-model/src/build_scripts.rs | 4 +- crates/project-model/src/cargo_workspace.rs | 32 ++++ .../project-model/src/{cfg_flag.rs => cfg.rs} | 27 +++- crates/project-model/src/env.rs | 84 ++++++++++ crates/project-model/src/lib.rs | 6 +- crates/project-model/src/project_json.rs | 2 +- crates/project-model/src/rustc_cfg.rs | 2 +- crates/project-model/src/workspace.rs | 143 +++++------------- 9 files changed, 193 insertions(+), 114 deletions(-) rename crates/project-model/src/{cfg_flag.rs => cfg.rs} (72%) create mode 100644 crates/project-model/src/env.rs diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index 6a8ab71624e..e136d8e915f 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -331,10 +331,11 @@ pub fn add_crate_root( version: Option, cfg_options: Arc, potential_cfg_options: Option>, - env: Env, + mut env: Env, is_proc_macro: bool, origin: CrateOrigin, ) -> CrateId { + env.entries.shrink_to_fit(); let data = CrateData { root_file_id, edition, @@ -651,8 +652,8 @@ fn from_iter>(iter: T) -> Self { } impl Env { - pub fn set(&mut self, env: &str, value: String) { - self.entries.insert(env.to_owned(), value); + pub fn set(&mut self, env: &str, value: impl Into) { + self.entries.insert(env.to_owned(), value.into()); } pub fn get(&self, env: &str) -> Option { diff --git a/crates/project-model/src/build_scripts.rs b/crates/project-model/src/build_scripts.rs index 26f8f52bbc7..fbd423c9eac 100644 --- a/crates/project-model/src/build_scripts.rs +++ b/crates/project-model/src/build_scripts.rs @@ -23,16 +23,18 @@ use toolchain::Tool; use crate::{ - cfg_flag::CfgFlag, utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationLocation, + cfg::CfgFlag, utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationLocation, InvocationStrategy, Package, Sysroot, TargetKind, }; +/// Output of the build script and proc-macro building steps for a workspace. #[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct WorkspaceBuildScripts { outputs: ArenaMap, error: Option, } +/// Output of the build script and proc-macro building step for a concrete package. #[derive(Debug, Clone, Default, PartialEq, Eq)] pub(crate) struct BuildScriptOutput { /// List of config flags defined by this package's build script. diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index 82fee7112fb..fd898ffa5c3 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -135,6 +135,20 @@ pub struct PackageData { pub active_features: Vec, /// String representation of package id pub id: String, + /// Authors as given in the `Cargo.toml` + pub authors: Vec, + /// Description as given in the `Cargo.toml` + pub description: Option, + /// Homepage as given in the `Cargo.toml` + pub homepage: Option, + /// License as given in the `Cargo.toml` + pub license: Option, + /// License file as given in the `Cargo.toml` + pub license_file: Option, + /// Readme file as given in the `Cargo.toml` + pub readme: Option, + /// Rust version as given in the `Cargo.toml` + pub rust_version: Option, /// The contents of [package.metadata.rust-analyzer] pub metadata: RustAnalyzerPackageMetaData, } @@ -225,6 +239,10 @@ fn new(kinds: &[String]) -> TargetKind { } TargetKind::Other } + + pub fn is_executable(self) -> bool { + matches!(self, TargetKind::Bin | TargetKind::Example) + } } // Deserialize helper for the cargo metadata @@ -330,6 +348,13 @@ pub fn new(mut meta: cargo_metadata::Metadata) -> CargoWorkspace { repository, edition, metadata, + authors, + description, + homepage, + license, + license_file, + readme, + rust_version, .. } = meta_pkg; let meta = from_value::(metadata).unwrap_or_default(); @@ -358,6 +383,13 @@ pub fn new(mut meta: cargo_metadata::Metadata) -> CargoWorkspace { is_member, edition, repository, + authors, + description, + homepage, + license, + license_file, + readme, + rust_version, dependencies: Vec::new(), features: features.into_iter().collect(), active_features: Vec::new(), diff --git a/crates/project-model/src/cfg_flag.rs b/crates/project-model/src/cfg.rs similarity index 72% rename from crates/project-model/src/cfg_flag.rs rename to crates/project-model/src/cfg.rs index 6192e18da02..b409bc1ce7a 100644 --- a/crates/project-model/src/cfg_flag.rs +++ b/crates/project-model/src/cfg.rs @@ -3,7 +3,8 @@ //! rustc main.rs --cfg foo --cfg 'feature="bar"' use std::{fmt, str::FromStr}; -use cfg::CfgOptions; +use cfg::{CfgDiff, CfgOptions}; +use rustc_hash::FxHashMap; use serde::Serialize; #[derive(Clone, Eq, PartialEq, Debug, Serialize)] @@ -70,3 +71,27 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } } + +/// A set of cfg-overrides per crate. +#[derive(Default, Debug, Clone, Eq, PartialEq)] +pub struct CfgOverrides { + /// A global set of overrides matching all crates. + pub global: CfgDiff, + /// A set of overrides matching specific crates. + pub selective: FxHashMap, +} + +impl CfgOverrides { + pub fn len(&self) -> usize { + self.global.len() + self.selective.values().map(|it| it.len()).sum::() + } + + pub fn apply(&self, cfg_options: &mut CfgOptions, name: &str) { + if !self.global.is_empty() { + cfg_options.apply_diff(self.global.clone()); + }; + if let Some(diff) = self.selective.get(name) { + cfg_options.apply_diff(diff.clone()); + }; + } +} diff --git a/crates/project-model/src/env.rs b/crates/project-model/src/env.rs new file mode 100644 index 00000000000..541298585ad --- /dev/null +++ b/crates/project-model/src/env.rs @@ -0,0 +1,84 @@ +use base_db::Env; +use rustc_hash::FxHashMap; +use toolchain::Tool; + +use crate::{utf8_stdout, ManifestPath, PackageData, Sysroot, TargetKind}; + +/// Recreates the compile-time environment variables that Cargo sets. +/// +/// Should be synced with +/// +/// +/// FIXME: ask Cargo to provide this data instead of re-deriving. +pub(crate) fn inject_cargo_package_env(env: &mut Env, package: &PackageData) { + // FIXME: Missing variables: + // CARGO_BIN_NAME, CARGO_BIN_EXE_ + + let manifest_dir = package.manifest.parent(); + env.set("CARGO_MANIFEST_DIR", manifest_dir.as_str()); + + env.set("CARGO_PKG_VERSION", package.version.to_string()); + env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string()); + env.set("CARGO_PKG_VERSION_MINOR", package.version.minor.to_string()); + env.set("CARGO_PKG_VERSION_PATCH", package.version.patch.to_string()); + env.set("CARGO_PKG_VERSION_PRE", package.version.pre.to_string()); + + env.set("CARGO_PKG_AUTHORS", package.authors.join(":").clone()); + + env.set("CARGO_PKG_NAME", package.name.clone()); + env.set("CARGO_PKG_DESCRIPTION", package.description.as_deref().unwrap_or_default()); + env.set("CARGO_PKG_HOMEPAGE", package.homepage.as_deref().unwrap_or_default()); + env.set("CARGO_PKG_REPOSITORY", package.repository.as_deref().unwrap_or_default()); + env.set("CARGO_PKG_LICENSE", package.license.as_deref().unwrap_or_default()); + env.set( + "CARGO_PKG_LICENSE_FILE", + package.license_file.as_ref().map(ToString::to_string).unwrap_or_default(), + ); + env.set( + "CARGO_PKG_README", + package.readme.as_ref().map(ToString::to_string).unwrap_or_default(), + ); + + env.set( + "CARGO_PKG_RUST_VERSION", + package.rust_version.as_ref().map(ToString::to_string).unwrap_or_default(), + ); +} + +pub(crate) fn inject_cargo_env(env: &mut Env) { + env.set("CARGO", Tool::Cargo.path().to_string()); +} + +pub(crate) fn inject_rustc_tool_env(env: &mut Env, cargo_name: &str, kind: TargetKind) { + _ = kind; + // FIXME + // if kind.is_executable() { + // env.set("CARGO_BIN_NAME", cargo_name); + // } + env.set("CARGO_CRATE_NAME", cargo_name.replace('-', "_")); +} + +pub(crate) fn cargo_config_env( + cargo_toml: &ManifestPath, + extra_env: &FxHashMap, + sysroot: Option<&Sysroot>, +) -> FxHashMap { + let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo); + cargo_config.envs(extra_env); + cargo_config + .current_dir(cargo_toml.parent()) + .args(["-Z", "unstable-options", "config", "get", "env"]) + .env("RUSTC_BOOTSTRAP", "1"); + // if successful we receive `env.key.value = "value" per entry + tracing::debug!("Discovering cargo config env by {:?}", cargo_config); + utf8_stdout(cargo_config).map(parse_output_cargo_config_env).unwrap_or_default() +} + +fn parse_output_cargo_config_env(stdout: String) -> FxHashMap { + stdout + .lines() + .filter_map(|l| l.strip_prefix("env.")) + .filter_map(|l| l.split_once(".value = ")) + .map(|(key, value)| (key.to_owned(), value.trim_matches('"').to_owned())) + .collect() +} diff --git a/crates/project-model/src/lib.rs b/crates/project-model/src/lib.rs index 28696aa3277..7f3e35ca5db 100644 --- a/crates/project-model/src/lib.rs +++ b/crates/project-model/src/lib.rs @@ -19,7 +19,8 @@ mod build_scripts; mod cargo_workspace; -mod cfg_flag; +mod cfg; +mod env; mod manifest_path; mod project_json; mod rustc_cfg; @@ -47,10 +48,11 @@ CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency, RustLibSource, Target, TargetData, TargetKind, }, + cfg::CfgOverrides, manifest_path::ManifestPath, project_json::{ProjectJson, ProjectJsonData}, sysroot::Sysroot, - workspace::{CfgOverrides, PackageRoot, ProjectWorkspace}, + workspace::{FileLoader, PackageRoot, ProjectWorkspace}, }; #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index a8e30d22673..fac6eb8ad3e 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -55,7 +55,7 @@ use serde::{de, Deserialize, Serialize}; use span::Edition; -use crate::cfg_flag::CfgFlag; +use crate::cfg::CfgFlag; /// Roots and crates that compose this Rust project. #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/crates/project-model/src/rustc_cfg.rs b/crates/project-model/src/rustc_cfg.rs index 501b1fdc8c5..194bae55701 100644 --- a/crates/project-model/src/rustc_cfg.rs +++ b/crates/project-model/src/rustc_cfg.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap; use toolchain::Tool; -use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath, Sysroot}; +use crate::{cfg::CfgFlag, utf8_stdout, ManifestPath, Sysroot}; /// Determines how `rustc --print cfg` is discovered and invoked. pub(crate) enum RustcCfgConfig<'a> { diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 6a063905cae..0baf90e54e4 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -2,7 +2,7 @@ //! metadata` or `rust-project.json`) into representation stored in the salsa //! database -- `CrateGraph`. -use std::{collections::VecDeque, fmt, fs, iter, str::FromStr, sync}; +use std::{collections::VecDeque, fmt, fs, iter, sync}; use anyhow::{format_err, Context}; use base_db::{ @@ -21,7 +21,8 @@ use crate::{ build_scripts::BuildScriptOutput, cargo_workspace::{DepKind, PackageData, RustLibSource}, - cfg_flag::CfgFlag, + cfg::{CfgFlag, CfgOverrides}, + env::{cargo_config_env, inject_cargo_env, inject_cargo_package_env, inject_rustc_tool_env}, project_json::{Crate, CrateArrayIdx}, rustc_cfg::{self, RustcCfgConfig}, sysroot::{SysrootCrate, SysrootMode}, @@ -30,29 +31,7 @@ ProjectJson, ProjectManifest, Sysroot, TargetData, TargetKind, WorkspaceBuildScripts, }; -/// A set of cfg-overrides per crate. -#[derive(Default, Debug, Clone, Eq, PartialEq)] -pub struct CfgOverrides { - /// A global set of overrides matching all crates. - pub global: CfgDiff, - /// A set of overrides matching specific crates. - pub selective: FxHashMap, -} - -impl CfgOverrides { - pub fn len(&self) -> usize { - self.global.len() + self.selective.values().map(|it| it.len()).sum::() - } - - fn apply(&self, cfg_options: &mut CfgOptions, name: &str) { - if !self.global.is_empty() { - cfg_options.apply_diff(self.global.clone()); - }; - if let Some(diff) = self.selective.get(name) { - cfg_options.apply_diff(diff.clone()); - }; - } -} +pub type FileLoader<'a> = &'a mut dyn for<'b> FnMut(&'b AbsPath) -> Option; /// `PackageRoot` describes a package root folder. /// Which may be an external dependency, or a member of @@ -69,29 +48,43 @@ pub struct PackageRoot { pub enum ProjectWorkspace { /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. Cargo { + /// The workspace as returned by `cargo metadata`. cargo: CargoWorkspace, + /// The build script results for the workspace. build_scripts: WorkspaceBuildScripts, + /// The sysroot loaded for this workspace. sysroot: Result>, + /// The rustc workspace loaded for this workspace. An `Err(None)` means loading has been + /// disabled or was otherwise not requested. rustc: Result, Option>, /// Holds cfg flags for the current target. We get those by running /// `rustc --print cfg`. - /// - /// FIXME: make this a per-crate map, as, eg, build.rs might have a - /// different target. + // FIXME: make this a per-crate map, as, eg, build.rs might have a + // different target. rustc_cfg: Vec, + /// A set of cfg overrides for this workspace. cfg_overrides: CfgOverrides, + /// The toolchain version used by this workspace. toolchain: Option, + /// The target data layout queried for workspace. target_layout: TargetLayoutLoadResult, + /// Environment variables set in the `.cargo/config` file. cargo_config_extra_env: FxHashMap, }, /// Project workspace was manually specified using a `rust-project.json` file. Json { + /// The loaded project json file. project: ProjectJson, + /// The sysroot loaded for this workspace. sysroot: Result>, /// Holds cfg flags for the current target. We get those by running /// `rustc --print cfg`. + // FIXME: make this a per-crate map, as, eg, build.rs might have a + // different target. rustc_cfg: Vec, + /// The toolchain version used by this workspace. toolchain: Option, + /// The target data layout queried for workspace. target_layout: TargetLayoutLoadResult, }, // FIXME: The primary limitation of this approach is that the set of detached files needs to be fixed at the beginning. @@ -105,12 +98,18 @@ pub enum ProjectWorkspace { /// Project with a set of disjoint files, not belonging to any particular workspace. /// Backed by basic sysroot crates for basic completion and highlighting. DetachedFiles { + /// The set of detached files. files: Vec, + /// The sysroot loaded for this workspace. sysroot: Result>, /// Holds cfg flags for the current target. We get those by running /// `rustc --print cfg`. + // FIXME: make this a per-crate map, as, eg, build.rs might have a + // different target. rustc_cfg: Vec, + /// The toolchain version used by this workspace. toolchain: Option, + /// The target data layout queried for workspace. target_layout: TargetLayoutLoadResult, }, } @@ -723,7 +722,7 @@ pub fn n_packages(&self) -> usize { pub fn to_crate_graph( &self, - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, extra_env: &FxHashMap, ) -> (CrateGraph, ProcMacroPaths) { let _p = tracing::span!(tracing::Level::INFO, "ProjectWorkspace::to_crate_graph").entered(); @@ -874,7 +873,7 @@ pub fn is_json(&self) -> bool { fn project_json_to_crate_graph( rustc_cfg: Vec, - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, project: &ProjectJson, sysroot: Option<&Sysroot>, extra_env: &FxHashMap, @@ -976,7 +975,7 @@ fn project_json_to_crate_graph( } fn cargo_to_crate_graph( - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, rustc: Option<&(CargoWorkspace, WorkspaceBuildScripts)>, cargo: &CargoWorkspace, sysroot: Option<&Sysroot>, @@ -1166,7 +1165,7 @@ fn cargo_to_crate_graph( fn detached_files_to_crate_graph( rustc_cfg: Vec, - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, detached_files: &[AbsPathBuf], sysroot: Option<&Sysroot>, ) -> (CrateGraph, ProcMacroPaths) { @@ -1216,7 +1215,7 @@ fn handle_rustc_crates( crate_graph: &mut CrateGraph, proc_macros: &mut ProcMacroPaths, pkg_to_lib_crate: &mut FxHashMap, - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, rustc_workspace: &CargoWorkspace, cargo: &CargoWorkspace, public_deps: &SysrootPublicDeps, @@ -1350,23 +1349,19 @@ fn add_target_crate_root( }; let mut env = Env::default(); - inject_cargo_env(pkg, &mut env); - if let Ok(cname) = String::from_str(cargo_name) { - // CARGO_CRATE_NAME is the name of the Cargo target with - converted to _, such as the name of the library, binary, example, integration test, or benchmark. - env.set("CARGO_CRATE_NAME", cname.replace('-', "_")); - } + inject_cargo_package_env(&mut env, pkg); + inject_cargo_env(&mut env); + inject_rustc_tool_env(&mut env, cargo_name, kind); if let Some(envs) = build_data.map(|it| &it.envs) { for (k, v) in envs { env.set(k, v.clone()); } } - - let display_name = CrateDisplayName::from_canonical_name(cargo_name.to_owned()); let crate_id = crate_graph.add_crate_root( file_id, edition, - Some(display_name), + Some(CrateDisplayName::from_canonical_name(cargo_name.to_owned())), Some(pkg.version.to_string()), Arc::new(cfg_options), potential_cfg_options.map(Arc::new), @@ -1405,7 +1400,7 @@ fn sysroot_to_crate_graph( crate_graph: &mut CrateGraph, sysroot: &Sysroot, rustc_cfg: Vec, - load: &mut dyn FnMut(&AbsPath) -> Option, + load: FileLoader<'_>, ) -> (SysrootPublicDeps, Option) { let _p = tracing::span!(tracing::Level::INFO, "sysroot_to_crate_graph").entered(); match sysroot.mode() { @@ -1480,7 +1475,6 @@ fn sysroot_to_crate_graph( .filter_map(|krate| { let file_id = load(&stitched[krate].root)?; - let env = Env::default(); let display_name = CrateDisplayName::from_canonical_name(stitched[krate].name.clone()); let crate_id = crate_graph.add_crate_root( @@ -1490,7 +1484,7 @@ fn sysroot_to_crate_graph( None, cfg_options.clone(), None, - env, + Env::default(), false, CrateOrigin::Lang(LangCrateOrigin::from(&*stitched[krate].name)), ); @@ -1549,70 +1543,9 @@ fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) { } } -/// Recreates the compile-time environment variables that Cargo sets. -/// -/// Should be synced with -/// -/// -/// FIXME: ask Cargo to provide this data instead of re-deriving. -fn inject_cargo_env(package: &PackageData, env: &mut Env) { - // FIXME: Missing variables: - // CARGO_BIN_NAME, CARGO_BIN_EXE_ - - let manifest_dir = package.manifest.parent(); - env.set("CARGO_MANIFEST_DIR", manifest_dir.as_str().to_owned()); - - // Not always right, but works for common cases. - env.set("CARGO", "cargo".into()); - - env.set("CARGO_PKG_VERSION", package.version.to_string()); - env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string()); - env.set("CARGO_PKG_VERSION_MINOR", package.version.minor.to_string()); - env.set("CARGO_PKG_VERSION_PATCH", package.version.patch.to_string()); - env.set("CARGO_PKG_VERSION_PRE", package.version.pre.to_string()); - - env.set("CARGO_PKG_AUTHORS", String::new()); - - env.set("CARGO_PKG_NAME", package.name.clone()); - // FIXME: This isn't really correct (a package can have many crates with different names), but - // it's better than leaving the variable unset. - env.set("CARGO_CRATE_NAME", CrateName::normalize_dashes(&package.name).to_string()); - env.set("CARGO_PKG_DESCRIPTION", String::new()); - env.set("CARGO_PKG_HOMEPAGE", String::new()); - env.set("CARGO_PKG_REPOSITORY", String::new()); - env.set("CARGO_PKG_LICENSE", String::new()); - - env.set("CARGO_PKG_LICENSE_FILE", String::new()); -} - fn create_cfg_options(rustc_cfg: Vec) -> CfgOptions { let mut cfg_options = CfgOptions::default(); cfg_options.extend(rustc_cfg); cfg_options.insert_atom("debug_assertions".into()); cfg_options } - -fn cargo_config_env( - cargo_toml: &ManifestPath, - extra_env: &FxHashMap, - sysroot: Option<&Sysroot>, -) -> FxHashMap { - let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo); - cargo_config.envs(extra_env); - cargo_config - .current_dir(cargo_toml.parent()) - .args(["-Z", "unstable-options", "config", "get", "env"]) - .env("RUSTC_BOOTSTRAP", "1"); - // if successful we receive `env.key.value = "value" per entry - tracing::debug!("Discovering cargo config env by {:?}", cargo_config); - utf8_stdout(cargo_config).map(parse_output_cargo_config_env).unwrap_or_default() -} - -fn parse_output_cargo_config_env(stdout: String) -> FxHashMap { - stdout - .lines() - .filter_map(|l| l.strip_prefix("env.")) - .filter_map(|l| l.split_once(".value = ")) - .map(|(key, value)| (key.to_owned(), value.trim_matches('"').to_owned())) - .collect() -} From 8989dcffd6e94d402cf1cbce20c91eb78230118a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 19 Apr 2024 10:59:32 +0200 Subject: [PATCH 2/4] Support cfg overrides in all workspace kind --- crates/project-model/src/tests.rs | 1 + crates/project-model/src/workspace.rs | 88 +++++++++++++++------ crates/rust-analyzer/src/cli/rustc_tests.rs | 1 + crates/rust-analyzer/src/reload.rs | 1 + 4 files changed, 69 insertions(+), 22 deletions(-) diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs index fc0b507b332..a07a3d1a7ca 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -75,6 +75,7 @@ fn load_rust_project(file: &str) -> (CrateGraph, ProcMacroPaths) { rustc_cfg: Vec::new(), toolchain: None, target_layout: Err(Arc::from("test has no data layout")), + cfg_overrides: Default::default(), }; to_crate_graph(project_workspace) } diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 0baf90e54e4..85e000bc0ba 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -86,6 +86,8 @@ pub enum ProjectWorkspace { toolchain: Option, /// The target data layout queried for workspace. target_layout: TargetLayoutLoadResult, + /// A set of cfg overrides for this workspace. + cfg_overrides: CfgOverrides, }, // FIXME: The primary limitation of this approach is that the set of detached files needs to be fixed at the beginning. // That's not the end user experience we should strive for. @@ -111,6 +113,8 @@ pub enum ProjectWorkspace { toolchain: Option, /// The target data layout queried for workspace. target_layout: TargetLayoutLoadResult, + /// A set of cfg overrides for the files. + cfg_overrides: CfgOverrides, }, } @@ -149,6 +153,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { rustc_cfg, toolchain, target_layout: data_layout, + cfg_overrides, } => { let mut debug_struct = f.debug_struct("Json"); debug_struct.field("n_crates", &project.n_crates()); @@ -158,7 +163,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { debug_struct .field("n_rustc_cfg", &rustc_cfg.len()) .field("toolchain", &toolchain) - .field("data_layout", &data_layout); + .field("data_layout", &data_layout) + .field("n_cfg_overrides", &cfg_overrides.len()); debug_struct.finish() } ProjectWorkspace::DetachedFiles { @@ -167,6 +173,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { rustc_cfg, toolchain, target_layout, + cfg_overrides, } => f .debug_struct("DetachedFiles") .field("n_files", &files.len()) @@ -174,6 +181,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { .field("n_rustc_cfg", &rustc_cfg.len()) .field("toolchain", &toolchain) .field("data_layout", &target_layout) + .field("n_cfg_overrides", &cfg_overrides.len()) .finish(), } } @@ -227,6 +235,7 @@ fn load_inner( project_json, config.target.as_deref(), &config.extra_env, + &config.cfg_overrides, ) } ProjectManifest::CargoToml(cargo_toml) => { @@ -368,6 +377,7 @@ pub fn load_inline( project_json: ProjectJson, target: Option<&str>, extra_env: &FxHashMap, + cfg_overrides: &CfgOverrides, ) -> ProjectWorkspace { let sysroot = match (project_json.sysroot.clone(), project_json.sysroot_src.clone()) { (Some(sysroot), Some(sysroot_src)) => { @@ -414,6 +424,7 @@ pub fn load_inline( rustc_cfg, toolchain, target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())), + cfg_overrides: cfg_overrides.clone(), } } @@ -464,6 +475,7 @@ pub fn load_detached_files( rustc_cfg, toolchain, target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())), + cfg_overrides: config.cfg_overrides.clone(), }) } @@ -619,6 +631,7 @@ pub fn to_roots(&self) -> Vec { rustc_cfg: _, toolchain: _, target_layout: _, + cfg_overrides: _, } => project .crates() .map(|(_, krate)| PackageRoot { @@ -734,6 +747,7 @@ pub fn to_crate_graph( rustc_cfg, toolchain: _, target_layout: _, + cfg_overrides, } => ( project_json_to_crate_graph( rustc_cfg.clone(), @@ -741,6 +755,7 @@ pub fn to_crate_graph( project, sysroot.as_ref().ok(), extra_env, + cfg_overrides, ), sysroot, ), @@ -772,12 +787,14 @@ pub fn to_crate_graph( rustc_cfg, toolchain: _, target_layout: _, + cfg_overrides, } => ( detached_files_to_crate_graph( rustc_cfg.clone(), load, files, sysroot.as_ref().ok(), + cfg_overrides, ), sysroot, ), @@ -828,28 +845,45 @@ pub fn eq_ignore_build_data(&self, other: &Self) -> bool { && cargo_config_extra_env == o_cargo_config_extra_env } ( - Self::Json { project, sysroot, rustc_cfg, toolchain, target_layout: _ }, + Self::Json { + project, + sysroot, + rustc_cfg, + toolchain, + target_layout: _, + cfg_overrides, + }, Self::Json { project: o_project, sysroot: o_sysroot, rustc_cfg: o_rustc_cfg, toolchain: o_toolchain, target_layout: _, + cfg_overrides: o_cfg_overrides, }, ) => { project == o_project && rustc_cfg == o_rustc_cfg && sysroot == o_sysroot && toolchain == o_toolchain + && cfg_overrides == o_cfg_overrides } ( - Self::DetachedFiles { files, sysroot, rustc_cfg, toolchain, target_layout }, + Self::DetachedFiles { + files, + sysroot, + rustc_cfg, + toolchain, + target_layout, + cfg_overrides, + }, Self::DetachedFiles { files: o_files, sysroot: o_sysroot, rustc_cfg: o_rustc_cfg, toolchain: o_toolchain, target_layout: o_target_layout, + cfg_overrides: o_cfg_overrides, }, ) => { files == o_files @@ -857,6 +891,7 @@ pub fn eq_ignore_build_data(&self, other: &Self) -> bool { && rustc_cfg == o_rustc_cfg && toolchain == o_toolchain && target_layout == o_target_layout + && cfg_overrides == o_cfg_overrides } _ => false, } @@ -877,6 +912,7 @@ fn project_json_to_crate_graph( project: &ProjectJson, sysroot: Option<&Sysroot>, extra_env: &FxHashMap, + override_cfg: &CfgOverrides, ) -> (CrateGraph, ProcMacroPaths) { let mut res = (CrateGraph::default(), ProcMacroPaths::default()); let (crate_graph, proc_macros) = &mut res; @@ -916,19 +952,22 @@ fn project_json_to_crate_graph( None => &rustc_cfg, }; + let mut cfg_options = target_cfgs + .iter() + .chain(cfg.iter()) + .chain(iter::once(&r_a_cfg_flag)) + .cloned() + .collect(); + override_cfg.apply( + &mut cfg_options, + display_name.as_ref().map(|it| it.canonical_name()).unwrap_or_default(), + ); let crate_graph_crate_id = crate_graph.add_crate_root( file_id, *edition, display_name.clone(), version.clone(), - Arc::new( - target_cfgs - .iter() - .chain(cfg.iter()) - .chain(iter::once(&r_a_cfg_flag)) - .cloned() - .collect(), - ), + Arc::new(cfg_options), None, env, *is_proc_macro, @@ -992,7 +1031,7 @@ fn cargo_to_crate_graph( None => (SysrootPublicDeps::default(), None), }; - let cfg_options = create_cfg_options(rustc_cfg); + let cfg_options = CfgOptions::from_iter(rustc_cfg); // Mapping of a package to its library target let mut pkg_to_lib_crate = FxHashMap::default(); @@ -1168,6 +1207,7 @@ fn detached_files_to_crate_graph( load: FileLoader<'_>, detached_files: &[AbsPathBuf], sysroot: Option<&Sysroot>, + override_cfg: &CfgOverrides, ) -> (CrateGraph, ProcMacroPaths) { let _p = tracing::span!(tracing::Level::INFO, "detached_files_to_crate_graph").entered(); let mut crate_graph = CrateGraph::default(); @@ -1176,8 +1216,10 @@ fn detached_files_to_crate_graph( None => (SysrootPublicDeps::default(), None), }; - let mut cfg_options = create_cfg_options(rustc_cfg); + let mut cfg_options = CfgOptions::from_iter(rustc_cfg); + cfg_options.insert_atom("test".into()); cfg_options.insert_atom("rust_analyzer".into()); + override_cfg.apply(&mut cfg_options, ""); let cfg_options = Arc::new(cfg_options); for detached_file in detached_files { @@ -1411,7 +1453,11 @@ fn sysroot_to_crate_graph( cargo, None, rustc_cfg, - &CfgOverrides::default(), + &CfgOverrides { + global: CfgDiff::new(vec![CfgAtom::Flag("debug_assertions".into())], vec![]) + .unwrap(), + ..Default::default() + }, &WorkspaceBuildScripts::default(), ); @@ -1469,7 +1515,12 @@ fn sysroot_to_crate_graph( (SysrootPublicDeps { deps: pub_deps }, libproc_macro) } SysrootMode::Stitched(stitched) => { - let cfg_options = Arc::new(create_cfg_options(rustc_cfg)); + let cfg_options = Arc::new({ + let mut cfg_options = CfgOptions::default(); + cfg_options.extend(rustc_cfg); + cfg_options.insert_atom("debug_assertions".into()); + cfg_options + }); let sysroot_crates: FxHashMap = stitched .crates() .filter_map(|krate| { @@ -1542,10 +1593,3 @@ fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) { tracing::error!("{}", err) } } - -fn create_cfg_options(rustc_cfg: Vec) -> CfgOptions { - let mut cfg_options = CfgOptions::default(); - cfg_options.extend(rustc_cfg); - cfg_options.insert_atom("debug_assertions".into()); - cfg_options -} diff --git a/crates/rust-analyzer/src/cli/rustc_tests.rs b/crates/rust-analyzer/src/cli/rustc_tests.rs index eeec13a14be..548dd4e70e5 100644 --- a/crates/rust-analyzer/src/cli/rustc_tests.rs +++ b/crates/rust-analyzer/src/cli/rustc_tests.rs @@ -81,6 +81,7 @@ fn new() -> Result { rustc_cfg: vec![], toolchain: None, target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())), + cfg_overrides: Default::default(), }; let load_cargo_config = LoadCargoConfig { load_out_dirs_from_check: false, diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index d2e495dbfcd..00a61758f06 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -234,6 +234,7 @@ pub(crate) fn fetch_workspaces(&mut self, cause: Cause, force_crate_graph_reload it.clone(), cargo_config.target.as_deref(), &cargo_config.extra_env, + &cargo_config.cfg_overrides, )) } }) From 0485a85ee2af65b3c73eda0df80fbacf838b862e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 19 Apr 2024 11:06:55 +0200 Subject: [PATCH 3/4] Set debug_assertions and miri cfgs as config defaults, allowing them to be overwritten --- crates/project-model/src/env.rs | 1 + crates/project-model/src/rustc_cfg.rs | 3 --- crates/project-model/src/workspace.rs | 11 +++++++++-- crates/rust-analyzer/src/config.rs | 19 ++++++++++++------- docs/user/generated_config.adoc | 10 +++++++++- editors/code/package.json | 5 ++++- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/crates/project-model/src/env.rs b/crates/project-model/src/env.rs index 541298585ad..762e01c9177 100644 --- a/crates/project-model/src/env.rs +++ b/crates/project-model/src/env.rs @@ -1,3 +1,4 @@ +//! Cargo-like environment variables injection. use base_db::Env; use rustc_hash::FxHashMap; use toolchain::Tool; diff --git a/crates/project-model/src/rustc_cfg.rs b/crates/project-model/src/rustc_cfg.rs index 194bae55701..4f69b2b96f0 100644 --- a/crates/project-model/src/rustc_cfg.rs +++ b/crates/project-model/src/rustc_cfg.rs @@ -32,9 +32,6 @@ pub(crate) fn get( } } - // Add miri cfg, which is useful for mir eval in stdlib - res.push(CfgFlag::Atom("miri".into())); - let rustc_cfgs = get_rust_cfgs(target, extra_env, config); let rustc_cfgs = match rustc_cfgs { diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 85e000bc0ba..a5e74763d70 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -1454,8 +1454,14 @@ fn sysroot_to_crate_graph( None, rustc_cfg, &CfgOverrides { - global: CfgDiff::new(vec![CfgAtom::Flag("debug_assertions".into())], vec![]) - .unwrap(), + global: CfgDiff::new( + vec![ + CfgAtom::Flag("debug_assertions".into()), + CfgAtom::Flag("miri".into()), + ], + vec![], + ) + .unwrap(), ..Default::default() }, &WorkspaceBuildScripts::default(), @@ -1519,6 +1525,7 @@ fn sysroot_to_crate_graph( let mut cfg_options = CfgOptions::default(); cfg_options.extend(rustc_cfg); cfg_options.insert_atom("debug_assertions".into()); + cfg_options.insert_atom("miri".into()); cfg_options }); let sysroot_crates: FxHashMap = stitched diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 00782036217..0d99a8f113b 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -124,7 +124,12 @@ /// avoid checking unnecessary things. cargo_buildScripts_useRustcWrapper: bool = true, /// List of cfg options to enable with the given values. - cargo_cfgs: FxHashMap = FxHashMap::default(), + cargo_cfgs: FxHashMap> = { + let mut m = FxHashMap::default(); + m.insert("debug_assertions".to_owned(), None); + m.insert("miri".to_owned(), None); + m + }, /// Extra arguments that are passed to every cargo invocation. cargo_extraArgs: Vec = vec![], /// Extra environment variables that will be set when running cargo, rustc @@ -1591,12 +1596,9 @@ pub fn cargo(&self) -> CargoConfig { global: CfgDiff::new( self.cargo_cfgs() .iter() - .map(|(key, val)| { - if val.is_empty() { - CfgAtom::Flag(key.into()) - } else { - CfgAtom::KeyValue { key: key.into(), value: val.into() } - } + .map(|(key, val)| match val { + Some(val) => CfgAtom::KeyValue { key: key.into(), value: val.into() }, + None => CfgAtom::Flag(key.into()), }) .collect(), vec![], @@ -2667,6 +2669,9 @@ macro_rules! set { "FxHashMap, usize>" => set! { "type": "object", }, + "FxHashMap>" => set! { + "type": "object", + }, "Option" => set! { "type": ["null", "integer"], "minimum": 0, diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 14bce2083e2..7bd3012056b 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -88,10 +88,18 @@ or build-script sources change and are saved. Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to avoid checking unnecessary things. -- -[[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs (default: `{}`):: +[[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs:: + -- +Default: +---- +{ + "debug_assertions": null, + "miri": null +} +---- List of cfg options to enable with the given values. + -- [[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`):: + diff --git a/editors/code/package.json b/editors/code/package.json index 9b4875dabe0..0fd17f385e7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -610,7 +610,10 @@ }, "rust-analyzer.cargo.cfgs": { "markdownDescription": "List of cfg options to enable with the given values.", - "default": {}, + "default": { + "debug_assertions": null, + "miri": null + }, "type": "object" }, "rust-analyzer.cargo.extraArgs": { From cdb8c3a3279d0ac6fcc4571fdd79bbe91849f4c9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 19 Apr 2024 11:43:16 +0200 Subject: [PATCH 4/4] Fix tests being non-deterministic --- crates/base-db/src/input.rs | 33 +++++- crates/cfg/src/lib.rs | 7 -- crates/load-cargo/src/lib.rs | 3 +- crates/proc-macro-api/src/lib.rs | 10 +- crates/project-model/src/tests.rs | 7 ++ .../cargo_hello_world_project_model.txt | 108 +++++++++--------- ...project_model_with_selective_overrides.txt | 108 +++++++++--------- ..._project_model_with_wildcard_overrides.txt | 108 +++++++++--------- ...rust_project_hello_world_project_model.txt | 10 ++ crates/test-fixture/src/lib.rs | 2 +- 10 files changed, 221 insertions(+), 175 deletions(-) diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index e136d8e915f..240af7925cc 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -295,11 +295,30 @@ pub struct CrateData { pub is_proc_macro: bool, } -#[derive(Default, Debug, Clone, PartialEq, Eq)] +#[derive(Default, Clone, PartialEq, Eq)] pub struct Env { entries: FxHashMap, } +impl fmt::Debug for Env { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + struct EnvDebug<'s>(Vec<(&'s String, &'s String)>); + + impl fmt::Debug for EnvDebug<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_map().entries(self.0.iter().copied()).finish() + } + } + f.debug_struct("Env") + .field("entries", &{ + let mut entries: Vec<_> = self.entries.iter().collect(); + entries.sort(); + EnvDebug(entries) + }) + .finish() + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Dependency { pub crate_id: CrateId, @@ -660,8 +679,16 @@ pub fn get(&self, env: &str) -> Option { self.entries.get(env).cloned() } - pub fn iter(&self) -> impl Iterator { - self.entries.iter().map(|(k, v)| (k.as_str(), v.as_str())) + pub fn extend_from_other(&mut self, other: &Env) { + self.entries.extend(other.entries.iter().map(|(x, y)| (x.to_owned(), y.to_owned()))); + } +} + +impl From for Vec<(String, String)> { + fn from(env: Env) -> Vec<(String, String)> { + let mut entries: Vec<_> = env.entries.into_iter().collect(); + entries.sort(); + entries } } diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs index 454d6fc5384..9a365889e6a 100644 --- a/crates/cfg/src/lib.rs +++ b/crates/cfg/src/lib.rs @@ -58,13 +58,6 @@ pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) { self.enabled.insert(CfgAtom::KeyValue { key, value }); } - pub fn difference<'a>( - &'a self, - other: &'a CfgOptions, - ) -> impl Iterator + 'a { - self.enabled.difference(&other.enabled) - } - pub fn apply_diff(&mut self, diff: CfgDiff) { for atom in diff.enable { self.enabled.insert(atom); diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index 79d6fe36b56..ec37d88e607 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -407,8 +407,7 @@ fn expand( call_site: Span, mixed_site: Span, ) -> Result, ProcMacroExpansionError> { - let env = env.iter().map(|(k, v)| (k.to_owned(), v.to_owned())).collect(); - match self.0.expand(subtree, attrs, env, def_site, call_site, mixed_site) { + match self.0.expand(subtree, attrs, env.clone(), def_site, call_site, mixed_site) { Ok(Ok(subtree)) => Ok(subtree), Ok(Err(err)) => Err(ProcMacroExpansionError::Panic(err.0)), Err(err) => Err(ProcMacroExpansionError::System(err.to_string())), diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs index 3c0c904babe..0ab16c38c87 100644 --- a/crates/proc-macro-api/src/lib.rs +++ b/crates/proc-macro-api/src/lib.rs @@ -11,6 +11,7 @@ mod process; mod version; +use base_db::Env; use indexmap::IndexSet; use paths::AbsPathBuf; use rustc_hash::FxHashMap; @@ -152,16 +153,13 @@ pub fn expand( &self, subtree: &tt::Subtree, attr: Option<&tt::Subtree>, - env: Vec<(String, String)>, + env: Env, def_site: Span, call_site: Span, mixed_site: Span, ) -> Result, PanicMessage>, ServerError> { let version = self.process.lock().unwrap_or_else(|e| e.into_inner()).version(); - let current_dir = env - .iter() - .find(|(name, _)| name == "CARGO_MANIFEST_DIR") - .map(|(_, value)| value.clone()); + let current_dir = env.get("CARGO_MANIFEST_DIR"); let mut span_data_table = IndexSet::default(); let def_site = span_data_table.insert_full(def_site).0; @@ -172,7 +170,7 @@ pub fn expand( macro_name: self.name.to_string(), attributes: attr.map(|subtree| FlatTree::new(subtree, version, &mut span_data_table)), lib: self.dylib_path.to_path_buf().into(), - env, + env: env.into(), current_dir, has_global_spans: ExpnGlobals { serialize: version >= HAS_GLOBAL_SPANS, diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs index a07a3d1a7ca..fd09dff503f 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -98,6 +98,11 @@ fn fixup_paths(val: &mut serde_json::Value) { } } +fn replace_cargo(s: &mut String) { + let path = toolchain::Tool::Cargo.path().to_string().escape_debug().collect::(); + *s = s.replace(&path, "$CARGO$"); +} + fn replace_root(s: &mut String, direction: bool) { if direction { let root = if cfg!(windows) { r#"C:\\ROOT\"# } else { "/ROOT/" }; @@ -156,7 +161,9 @@ fn to_crate_graph(project_workspace: ProjectWorkspace) -> (CrateGraph, ProcMacro fn check_crate_graph(crate_graph: CrateGraph, expect: ExpectFile) { let mut crate_graph = format!("{crate_graph:#?}"); + replace_root(&mut crate_graph, false); + replace_cargo(&mut crate_graph); replace_fake_sys_root(&mut crate_graph); expect.assert_eq(&crate_graph); } diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt index 0ad19ca9f75..c2a2d6ed911 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt @@ -17,7 +17,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -25,20 +24,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -77,7 +78,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -85,20 +85,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -144,7 +146,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -152,20 +153,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "an_example", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -211,7 +214,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -219,20 +221,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "it", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -278,7 +282,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "feature=default", "feature=std", ], @@ -286,7 +289,6 @@ potential_cfg_options: Some( CfgOptions( [ - "debug_assertions", "feature=align", "feature=const-extern-fn", "feature=default", @@ -299,20 +301,22 @@ ), env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", - "CARGO_PKG_VERSION": "0.2.98", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "libc", + "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + "CARGO_PKG_AUTHORS": "The Rust Project Developers", + "CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n", + "CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc", + "CARGO_PKG_LICENSE": "MIT OR Apache-2.0", "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", - "CARGO_PKG_DESCRIPTION": "", "CARGO_PKG_NAME": "libc", - "CARGO_PKG_VERSION_PATCH": "98", - "CARGO": "cargo", - "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_README": "README.md", + "CARGO_PKG_REPOSITORY": "https://github.com/rust-lang/libc", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.2.98", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "2", + "CARGO_PKG_VERSION_PATCH": "98", "CARGO_PKG_VERSION_PRE": "", }, }, diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt index 0ad19ca9f75..c2a2d6ed911 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt @@ -17,7 +17,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -25,20 +24,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -77,7 +78,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -85,20 +85,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -144,7 +146,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -152,20 +153,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "an_example", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -211,7 +214,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", "test", ], @@ -219,20 +221,22 @@ potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "it", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -278,7 +282,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "feature=default", "feature=std", ], @@ -286,7 +289,6 @@ potential_cfg_options: Some( CfgOptions( [ - "debug_assertions", "feature=align", "feature=const-extern-fn", "feature=default", @@ -299,20 +301,22 @@ ), env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", - "CARGO_PKG_VERSION": "0.2.98", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "libc", + "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + "CARGO_PKG_AUTHORS": "The Rust Project Developers", + "CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n", + "CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc", + "CARGO_PKG_LICENSE": "MIT OR Apache-2.0", "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", - "CARGO_PKG_DESCRIPTION": "", "CARGO_PKG_NAME": "libc", - "CARGO_PKG_VERSION_PATCH": "98", - "CARGO": "cargo", - "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_README": "README.md", + "CARGO_PKG_REPOSITORY": "https://github.com/rust-lang/libc", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.2.98", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "2", + "CARGO_PKG_VERSION_PATCH": "98", "CARGO_PKG_VERSION_PRE": "", }, }, diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt index e2334dca875..c291ffcca7b 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt @@ -17,27 +17,28 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", ], ), potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -76,27 +77,28 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", ], ), potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "hello_world", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -142,27 +144,28 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", ], ), potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "an_example", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -208,27 +211,28 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "rust_analyzer", ], ), potential_cfg_options: None, env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$hello-world", - "CARGO_PKG_VERSION": "0.1.0", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "it", - "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", + "CARGO_MANIFEST_DIR": "$ROOT$hello-world", + "CARGO_PKG_AUTHORS": "", "CARGO_PKG_DESCRIPTION": "", + "CARGO_PKG_HOMEPAGE": "", + "CARGO_PKG_LICENSE": "", + "CARGO_PKG_LICENSE_FILE": "", "CARGO_PKG_NAME": "hello-world", - "CARGO_PKG_VERSION_PATCH": "0", - "CARGO": "cargo", + "CARGO_PKG_README": "", "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.1.0", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "1", + "CARGO_PKG_VERSION_PATCH": "0", "CARGO_PKG_VERSION_PRE": "", }, }, @@ -274,7 +278,6 @@ ), cfg_options: CfgOptions( [ - "debug_assertions", "feature=default", "feature=std", ], @@ -282,7 +285,6 @@ potential_cfg_options: Some( CfgOptions( [ - "debug_assertions", "feature=align", "feature=const-extern-fn", "feature=default", @@ -295,20 +297,22 @@ ), env: Env { entries: { - "CARGO_PKG_LICENSE": "", - "CARGO_PKG_VERSION_MAJOR": "0", - "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", - "CARGO_PKG_VERSION": "0.2.98", - "CARGO_PKG_AUTHORS": "", + "CARGO": "$CARGO$", "CARGO_CRATE_NAME": "libc", + "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + "CARGO_PKG_AUTHORS": "The Rust Project Developers", + "CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n", + "CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc", + "CARGO_PKG_LICENSE": "MIT OR Apache-2.0", "CARGO_PKG_LICENSE_FILE": "", - "CARGO_PKG_HOMEPAGE": "", - "CARGO_PKG_DESCRIPTION": "", "CARGO_PKG_NAME": "libc", - "CARGO_PKG_VERSION_PATCH": "98", - "CARGO": "cargo", - "CARGO_PKG_REPOSITORY": "", + "CARGO_PKG_README": "README.md", + "CARGO_PKG_REPOSITORY": "https://github.com/rust-lang/libc", + "CARGO_PKG_RUST_VERSION": "", + "CARGO_PKG_VERSION": "0.2.98", + "CARGO_PKG_VERSION_MAJOR": "0", "CARGO_PKG_VERSION_MINOR": "2", + "CARGO_PKG_VERSION_PATCH": "98", "CARGO_PKG_VERSION_PRE": "", }, }, diff --git a/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt b/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt index ccaba963ded..80c91365894 100644 --- a/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt +++ b/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt @@ -16,6 +16,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -53,6 +54,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -82,6 +84,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -111,6 +114,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -140,6 +144,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -184,6 +189,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -213,6 +219,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -299,6 +306,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -328,6 +336,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, @@ -357,6 +366,7 @@ cfg_options: CfgOptions( [ "debug_assertions", + "miri", ], ), potential_cfg_options: None, diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs index fdca069dc82..89ed6a61579 100644 --- a/crates/test-fixture/src/lib.rs +++ b/crates/test-fixture/src/lib.rs @@ -209,7 +209,7 @@ pub fn parse_with_proc_macros( assert!(default_crate_root.is_none()); 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_env.extend_from_other(&meta.env); } source_change.change_file(file_id, Some(text));