Skip to content

Commit ea0a7cd

Browse files
Simplify canonical impls too
1 parent 4e9b151 commit ea0a7cd

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

compiler/rustc_type_ir/src/canonical.rs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fmt;
2-
use std::hash;
2+
use std::hash::Hash;
33
use std::ops::ControlFlow;
44

55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -13,6 +13,13 @@ use crate::{HashStableContext, Interner, TyEncoder, UniverseIndex};
1313
/// A "canonicalized" type `V` is one where all free inference
1414
/// variables have been rewritten to "canonical vars". These are
1515
/// numbered starting from 0 in order of first appearance.
16+
#[derive(derivative::Derivative)]
17+
#[derivative(
18+
Clone(bound = "V: Clone"),
19+
PartialEq(bound = "V: PartialEq"),
20+
Eq(bound = "V: Eq"),
21+
Hash(bound = "V: Hash")
22+
)]
1623
pub struct Canonical<I: Interner, V> {
1724
pub value: V,
1825
pub max_universe: UniverseIndex,
@@ -59,14 +66,6 @@ impl<I: Interner, V> Canonical<I, V> {
5966
}
6067
}
6168

62-
impl<I: Interner, V: hash::Hash> hash::Hash for Canonical<I, V> {
63-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
64-
self.value.hash(state);
65-
self.max_universe.hash(state);
66-
self.variables.hash(state);
67-
}
68-
}
69-
7069
impl<CTX: HashStableContext, I: Interner, V: HashStable<CTX>> HashStable<CTX> for Canonical<I, V>
7170
where
7271
I::CanonicalVars: HashStable<CTX>,
@@ -78,16 +77,6 @@ where
7877
}
7978
}
8079

81-
impl<I: Interner, V: Eq> Eq for Canonical<I, V> {}
82-
83-
impl<I: Interner, V: PartialEq> PartialEq for Canonical<I, V> {
84-
fn eq(&self, other: &Self) -> bool {
85-
self.value == other.value
86-
&& self.max_universe == other.max_universe
87-
&& self.variables == other.variables
88-
}
89-
}
90-
9180
impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
9281
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9382
write!(
@@ -108,16 +97,6 @@ impl<I: Interner, V: fmt::Debug> fmt::Debug for Canonical<I, V> {
10897
}
10998
}
11099

111-
impl<I: Interner, V: Clone> Clone for Canonical<I, V> {
112-
fn clone(&self) -> Self {
113-
Canonical {
114-
value: self.value.clone(),
115-
max_universe: self.max_universe.clone(),
116-
variables: self.variables.clone(),
117-
}
118-
}
119-
}
120-
121100
impl<I: Interner, V: Copy> Copy for Canonical<I, V> where I::CanonicalVars: Copy {}
122101

123102
impl<I: Interner, V: TypeFoldable<I>> TypeFoldable<I> for Canonical<I, V>

0 commit comments

Comments
 (0)