diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index e136d8e915..240af7925c 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 @@ impl Env { 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 454d6fc538..9a365889e6 100644 --- a/crates/cfg/src/lib.rs +++ b/crates/cfg/src/lib.rs @@ -58,13 +58,6 @@ impl CfgOptions { 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 79d6fe36b5..ec37d88e60 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -407,8 +407,7 @@ impl ProcMacroExpander for Expander { 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 3c0c904bab..0ab16c38c8 100644 --- a/crates/proc-macro-api/src/lib.rs +++ b/crates/proc-macro-api/src/lib.rs @@ -11,6 +11,7 @@ pub mod msg; mod process; mod version; +use base_db::Env; use indexmap::IndexSet; use paths::AbsPathBuf; use rustc_hash::FxHashMap; @@ -152,16 +153,13 @@ impl ProcMacro { &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 @@ impl ProcMacro { 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 a07a3d1a7c..fd09dff503 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -98,6 +98,11 @@ fn get_test_json_file(file: &str) -> T { } } +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 0ad19ca9f7..c2a2d6ed91 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 0ad19ca9f7..c2a2d6ed91 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 e2334dca87..c291ffcca7 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 ccaba963de..80c9136589 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 fdca069dc8..89ed6a6157 100644 --- a/crates/test-fixture/src/lib.rs +++ b/crates/test-fixture/src/lib.rs @@ -209,7 +209,7 @@ impl ChangeFixture { 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));