From 86a11baa06aeeb45798c6d5431d67c23f0157289 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 10 Nov 2023 16:13:56 -0600 Subject: [PATCH] refactor(toml): Be consistent in duplicate field access --- src/cargo/util/toml/mod.rs | 7 +------ src/cargo/util/toml/schema.rs | 5 +++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7ce22437576..b634ff654ad 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -194,12 +194,7 @@ impl schema::TomlManifest { package_root: &Path, ) -> CargoResult { let config = ws.config(); - let mut package = self - .package - .as_ref() - .or_else(|| self.project.as_ref()) - .unwrap() - .clone(); + let mut package = self.package().unwrap().clone(); package.workspace = None; let current_resolver = package .resolver diff --git a/src/cargo/util/toml/schema.rs b/src/cargo/util/toml/schema.rs index 7c86b59df14..7a85b3edf3f 100644 --- a/src/cargo/util/toml/schema.rs +++ b/src/cargo/util/toml/schema.rs @@ -2,6 +2,7 @@ //! //! ## Style //! +//! - Fields duplicated for an alias will have an accessor with the primary field's name //! - Keys that exist for bookkeeping but don't correspond to the schema have a `_` prefix use std::collections::BTreeMap; @@ -51,6 +52,10 @@ impl TomlManifest { self.profile.is_some() } + pub fn package(&self) -> Option<&Box> { + self.package.as_ref().or(self.project.as_ref()) + } + pub fn dev_dependencies(&self) -> Option<&BTreeMap> { self.dev_dependencies .as_ref()