From b4ff7875eae0deef2304338fccc372eaefbd4ffd Mon Sep 17 00:00:00 2001 From: Hezuikn Date: Wed, 21 Sep 2022 17:32:35 +0000 Subject: [PATCH 1/3] the fix --- src/cargo/core/profiles.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 75d93f50736..f7a0e40af7a 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -660,7 +660,7 @@ impl Profile { /// 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 { + fn comparable(&self) -> impl Hash + Eq + '_ { ( self.opt_level, self.lto, @@ -673,7 +673,8 @@ impl Profile { self.rpath, self.incremental, self.panic, - self.strip, + //"This trait is implemented for tuples up to twelve items long." - https://doc.rust-lang.org/std/cmp/trait.Eq.html#impl-Eq-203 + (self.strip, &self.rustflags), ) } } From 1b2ce33e4f62fb4dffab4f3aa0c70161885e06f2 Mon Sep 17 00:00:00 2001 From: Hezuikn Date: Wed, 21 Sep 2022 17:46:35 +0000 Subject: [PATCH 2/3] update comment --- src/cargo/core/profiles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index f7a0e40af7a..5856ba7e000 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -657,7 +657,7 @@ impl Profile { } } - /// Compares all fields except `name`, which doesn't affect compilation. + /// 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. fn comparable(&self) -> impl Hash + Eq + '_ { From d8449e9c23d36a11bbf14c9d271936ef4e9205c3 Mon Sep 17 00:00:00 2001 From: Hezuikn Date: Wed, 21 Sep 2022 18:00:32 +0000 Subject: [PATCH 3/3] remove hazard by using derivative(procmacro crate) instead of handwritten impls --- Cargo.toml | 1 + src/cargo/core/profiles.rs | 46 +++++++------------------------------- 2 files changed, 9 insertions(+), 38 deletions(-) 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 5856ba7e000..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,27 +647,6 @@ impl Profile { ..Profile::default() } } - - /// 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. - 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, - //"This trait is implemented for tuples up to twelve items long." - https://doc.rust-lang.org/std/cmp/trait.Eq.html#impl-Eq-203 - (self.strip, &self.rustflags), - ) - } } /// The link-time-optimization setting.