diff --git a/Cargo.toml b/Cargo.toml index 5cb74f83e57..2d9926725ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,7 @@ unicode-width = "0.1.5" openssl = { version = '0.10.11', optional = true } im-rc = "15.0.0" itertools = "0.10.0" +derivative = "2.2.0" # A noop dependency that changes in the Rust repository, it's a bit of a hack. # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 75d93f50736..56100aeb825 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -8,7 +8,7 @@ use crate::util::{closest_msg, config, CargoResult, Config}; use anyhow::{bail, Context as _}; use std::collections::{BTreeMap, HashMap, HashSet}; use std::hash::Hash; -use std::{cmp, env, fmt, hash}; +use std::{env, fmt}; /// Collection of all profiles. #[derive(Clone, Debug)] @@ -539,10 +539,16 @@ pub enum ProfileRoot { /// Profile settings used to determine which compiler flags to use for a /// target. -#[derive(Clone, Eq, PartialOrd, Ord, serde::Serialize)] +#[derive(Clone, Eq, PartialOrd, Ord, serde::Serialize, derivative::Derivative)] +/// Don't compare/hash fields which wont affect compilation. +/// This is necessary for `Unit` deduplication for things like "test" and +/// "dev" which are essentially the same. +#[derivative(Hash, PartialEq)] pub struct Profile { + #[derivative(Hash = "ignore", PartialEq = "ignore")] pub name: InternedString, pub opt_level: InternedString, + #[derivative(Hash = "ignore", PartialEq = "ignore")] #[serde(skip)] // named profiles are unstable pub root: ProfileRoot, pub lto: Lto, @@ -620,21 +626,6 @@ impl fmt::Display for Profile { } } -impl hash::Hash for Profile { - fn hash(&self, state: &mut H) - where - H: hash::Hasher, - { - self.comparable().hash(state); - } -} - -impl cmp::PartialEq for Profile { - fn eq(&self, other: &Self) -> bool { - self.comparable() == other.comparable() - } -} - impl Profile { fn default_dev() -> Profile { Profile { @@ -656,26 +647,6 @@ impl Profile { ..Profile::default() } } - - /// Compares all fields except `name`, which doesn't affect compilation. - /// This is necessary for `Unit` deduplication for things like "test" and - /// "dev" which are essentially the same. - fn comparable(&self) -> impl Hash + Eq { - ( - self.opt_level, - self.lto, - self.codegen_backend, - self.codegen_units, - self.debuginfo, - self.split_debuginfo, - self.debug_assertions, - self.overflow_checks, - self.rpath, - self.incremental, - self.panic, - self.strip, - ) - } } /// The link-time-optimization setting.