diff options
| author | bors <bors@rust-lang.org> | 2024-04-19 16:00:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-19 16:00:54 +0000 |
| commit | 50bdeaad07f1f052d1c6fc4d504a8b5f01596ec0 (patch) | |
| tree | 876e094e8da39bb5db0a68e89b9c79a26ff198a1 /crates/base-db | |
| parent | 05428c56404a7751f3bd6cb61d739a8249f01ebc (diff) | |
| parent | cdb8c3a3279d0ac6fcc4571fdd79bbe91849f4c9 (diff) | |
Auto merge of #17108 - Veykril:rustc-ws-hacks, r=Veykril
internal: Cleanup cfg and env handling in project-model Fixes https://github.com/rust-lang/rust-analyzer/issues/16122#issuecomment-2065794340 `miri` and `debug_assertions` are now enabled via the `cargo.cfgs` config by default, allowing them to be disabled by overwriting the config.
Diffstat (limited to 'crates/base-db')
| -rw-r--r-- | crates/base-db/src/input.rs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index 6a8ab71624e..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<String, String>, } +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, @@ -331,10 +350,11 @@ impl CrateGraph { version: Option<String>, cfg_options: Arc<CfgOptions>, potential_cfg_options: Option<Arc<CfgOptions>>, - 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,16 +671,24 @@ impl FromIterator<(String, String)> for Env { } 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<String>) { + self.entries.insert(env.to_owned(), value.into()); } pub fn get(&self, env: &str) -> Option<String> { self.entries.get(env).cloned() } - pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> { - 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<Env> for Vec<(String, String)> { + fn from(env: Env) -> Vec<(String, String)> { + let mut entries: Vec<_> = env.entries.into_iter().collect(); + entries.sort(); + entries } } |
