Skip to content

Commit 1ed0efc

Browse files
committed
refactor(toml): Move Profile layering to be part of schema API
1 parent 6e187f8 commit 1ed0efc

File tree

2 files changed

+92
-92
lines changed

2 files changed

+92
-92
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,98 +2141,6 @@ fn validate_profile_override(profile: &schema::TomlProfile, which: &str) -> Carg
21412141
Ok(())
21422142
}
21432143

2144-
impl schema::TomlProfile {
2145-
/// Overwrite self's values with the given profile.
2146-
pub fn merge(&mut self, profile: &schema::TomlProfile) {
2147-
if let Some(v) = &profile.opt_level {
2148-
self.opt_level = Some(v.clone());
2149-
}
2150-
2151-
if let Some(v) = &profile.lto {
2152-
self.lto = Some(v.clone());
2153-
}
2154-
2155-
if let Some(v) = &profile.codegen_backend {
2156-
self.codegen_backend = Some(v.clone());
2157-
}
2158-
2159-
if let Some(v) = profile.codegen_units {
2160-
self.codegen_units = Some(v);
2161-
}
2162-
2163-
if let Some(v) = profile.debug {
2164-
self.debug = Some(v);
2165-
}
2166-
2167-
if let Some(v) = profile.debug_assertions {
2168-
self.debug_assertions = Some(v);
2169-
}
2170-
2171-
if let Some(v) = &profile.split_debuginfo {
2172-
self.split_debuginfo = Some(v.clone());
2173-
}
2174-
2175-
if let Some(v) = profile.rpath {
2176-
self.rpath = Some(v);
2177-
}
2178-
2179-
if let Some(v) = &profile.panic {
2180-
self.panic = Some(v.clone());
2181-
}
2182-
2183-
if let Some(v) = profile.overflow_checks {
2184-
self.overflow_checks = Some(v);
2185-
}
2186-
2187-
if let Some(v) = profile.incremental {
2188-
self.incremental = Some(v);
2189-
}
2190-
2191-
if let Some(v) = &profile.rustflags {
2192-
self.rustflags = Some(v.clone());
2193-
}
2194-
2195-
if let Some(other_package) = &profile.package {
2196-
match &mut self.package {
2197-
Some(self_package) => {
2198-
for (spec, other_pkg_profile) in other_package {
2199-
match self_package.get_mut(spec) {
2200-
Some(p) => p.merge(other_pkg_profile),
2201-
None => {
2202-
self_package.insert(spec.clone(), other_pkg_profile.clone());
2203-
}
2204-
}
2205-
}
2206-
}
2207-
None => self.package = Some(other_package.clone()),
2208-
}
2209-
}
2210-
2211-
if let Some(other_bo) = &profile.build_override {
2212-
match &mut self.build_override {
2213-
Some(self_bo) => self_bo.merge(other_bo),
2214-
None => self.build_override = Some(other_bo.clone()),
2215-
}
2216-
}
2217-
2218-
if let Some(v) = &profile.inherits {
2219-
self.inherits = Some(v.clone());
2220-
}
2221-
2222-
if let Some(v) = &profile.dir_name {
2223-
self.dir_name = Some(v.clone());
2224-
}
2225-
2226-
if let Some(v) = &profile.strip {
2227-
self.strip = Some(v.clone());
2228-
}
2229-
2230-
if let Some(v) = &profile.trim_paths {
2231-
self.trim_paths = Some(v.clone())
2232-
}
2233-
}
2234-
}
2235-
22362144
impl schema::InheritableLints {
22372145
fn inherit_with<'a>(
22382146
self,

src/cargo/util/toml/schema.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,98 @@ pub struct TomlProfile {
670670
pub trim_paths: Option<TomlTrimPaths>,
671671
}
672672

673+
impl TomlProfile {
674+
/// Overwrite self's values with the given profile.
675+
pub fn merge(&mut self, profile: &Self) {
676+
if let Some(v) = &profile.opt_level {
677+
self.opt_level = Some(v.clone());
678+
}
679+
680+
if let Some(v) = &profile.lto {
681+
self.lto = Some(v.clone());
682+
}
683+
684+
if let Some(v) = &profile.codegen_backend {
685+
self.codegen_backend = Some(v.clone());
686+
}
687+
688+
if let Some(v) = profile.codegen_units {
689+
self.codegen_units = Some(v);
690+
}
691+
692+
if let Some(v) = profile.debug {
693+
self.debug = Some(v);
694+
}
695+
696+
if let Some(v) = profile.debug_assertions {
697+
self.debug_assertions = Some(v);
698+
}
699+
700+
if let Some(v) = &profile.split_debuginfo {
701+
self.split_debuginfo = Some(v.clone());
702+
}
703+
704+
if let Some(v) = profile.rpath {
705+
self.rpath = Some(v);
706+
}
707+
708+
if let Some(v) = &profile.panic {
709+
self.panic = Some(v.clone());
710+
}
711+
712+
if let Some(v) = profile.overflow_checks {
713+
self.overflow_checks = Some(v);
714+
}
715+
716+
if let Some(v) = profile.incremental {
717+
self.incremental = Some(v);
718+
}
719+
720+
if let Some(v) = &profile.rustflags {
721+
self.rustflags = Some(v.clone());
722+
}
723+
724+
if let Some(other_package) = &profile.package {
725+
match &mut self.package {
726+
Some(self_package) => {
727+
for (spec, other_pkg_profile) in other_package {
728+
match self_package.get_mut(spec) {
729+
Some(p) => p.merge(other_pkg_profile),
730+
None => {
731+
self_package.insert(spec.clone(), other_pkg_profile.clone());
732+
}
733+
}
734+
}
735+
}
736+
None => self.package = Some(other_package.clone()),
737+
}
738+
}
739+
740+
if let Some(other_bo) = &profile.build_override {
741+
match &mut self.build_override {
742+
Some(self_bo) => self_bo.merge(other_bo),
743+
None => self.build_override = Some(other_bo.clone()),
744+
}
745+
}
746+
747+
if let Some(v) = &profile.inherits {
748+
self.inherits = Some(v.clone());
749+
}
750+
751+
if let Some(v) = &profile.dir_name {
752+
self.dir_name = Some(v.clone());
753+
}
754+
755+
if let Some(v) = &profile.strip {
756+
self.strip = Some(v.clone());
757+
}
758+
759+
if let Some(v) = &profile.trim_paths {
760+
self.trim_paths = Some(v.clone())
761+
}
762+
}
763+
}
764+
673765
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
674766
pub enum ProfilePackageSpec {
675767
Spec(PackageIdSpec),

0 commit comments

Comments
 (0)