Skip to content

Commit 3b3f447

Browse files
committed
remove hazard by using derivative(procmacro crate) instead of handwritten impls
1 parent 869951c commit 3b3f447

File tree

2 files changed

+9
-38
lines changed

2 files changed

+9
-38
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ unicode-width = "0.1.5"
6666
openssl = { version = '0.10.11', optional = true }
6767
im-rc = "15.0.0"
6868
itertools = "0.10.0"
69+
derivative = "2.2.0"
6970

7071
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
7172
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

src/cargo/core/profiles.rs

+8-38
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::util::{closest_msg, config, CargoResult, Config};
88
use anyhow::{bail, Context as _};
99
use std::collections::{BTreeMap, HashMap, HashSet};
1010
use std::hash::Hash;
11-
use std::{cmp, env, fmt, hash};
11+
use std::{env, fmt};
1212

1313
/// Collection of all profiles.
1414
#[derive(Clone, Debug)]
@@ -539,10 +539,16 @@ pub enum ProfileRoot {
539539

540540
/// Profile settings used to determine which compiler flags to use for a
541541
/// target.
542-
#[derive(Clone, Eq, PartialOrd, Ord, serde::Serialize)]
542+
#[derive(Clone, Eq, PartialOrd, Ord, serde::Serialize, derivative::Derivative)]
543+
/// Don't compare/hash fields which wont affect compilation.
544+
/// This is necessary for `Unit` deduplication for things like "test" and
545+
/// "dev" which are essentially the same.
546+
#[derivative(Hash, PartialEq)]
543547
pub struct Profile {
548+
#[derivative(Hash = "ignore", PartialEq = "ignore")]
544549
pub name: InternedString,
545550
pub opt_level: InternedString,
551+
#[derivative(Hash = "ignore", PartialEq = "ignore")]
546552
#[serde(skip)] // named profiles are unstable
547553
pub root: ProfileRoot,
548554
pub lto: Lto,
@@ -620,21 +626,6 @@ impl fmt::Display for Profile {
620626
}
621627
}
622628

623-
impl hash::Hash for Profile {
624-
fn hash<H>(&self, state: &mut H)
625-
where
626-
H: hash::Hasher,
627-
{
628-
self.comparable().hash(state);
629-
}
630-
}
631-
632-
impl cmp::PartialEq for Profile {
633-
fn eq(&self, other: &Self) -> bool {
634-
self.comparable() == other.comparable()
635-
}
636-
}
637-
638629
impl Profile {
639630
fn default_dev() -> Profile {
640631
Profile {
@@ -656,27 +647,6 @@ impl Profile {
656647
..Profile::default()
657648
}
658649
}
659-
660-
/// Don't compare/hash fields which wont affect compilation.
661-
/// This is necessary for `Unit` deduplication for things like "test" and
662-
/// "dev" which are essentially the same.
663-
fn comparable(&self) -> impl Hash + Eq + '_ {
664-
(
665-
self.opt_level,
666-
self.lto,
667-
self.codegen_backend,
668-
self.codegen_units,
669-
self.debuginfo,
670-
self.split_debuginfo,
671-
self.debug_assertions,
672-
self.overflow_checks,
673-
self.rpath,
674-
self.incremental,
675-
self.panic,
676-
//"This trait is implemented for tuples up to twelve items long." - https://doc.rust-lang.org/std/cmp/trait.Eq.html#impl-Eq-203
677-
(self.strip, &self.rustflags),
678-
)
679-
}
680650
}
681651

682652
/// The link-time-optimization setting.

0 commit comments

Comments
 (0)