Skip to content

Commit 14a9cf2

Browse files
committed
Generalize some InternedInSet impls
1 parent 907ef22 commit 14a9cf2

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

compiler/rustc_middle/src/ty/context.rs

+6-36
Original file line numberDiff line numberDiff line change
@@ -2163,53 +2163,23 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> {
21632163
}
21642164

21652165
#[allow(rustc::usage_of_ty_tykind)]
2166-
impl<'tcx> Borrow<TyKind<'tcx>> for InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>> {
2167-
fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> {
2166+
impl<'tcx, T> Borrow<T> for InternedInSet<'tcx, WithCachedTypeInfo<T>> {
2167+
fn borrow<'a>(&'a self) -> &'a T {
21682168
&self.0.internee
21692169
}
21702170
}
21712171

2172-
impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>> {
2173-
fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>) -> bool {
2172+
impl<'tcx, T: PartialEq> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<T>> {
2173+
fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<T>>) -> bool {
21742174
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
21752175
// `x == y`.
21762176
self.0.internee == other.0.internee
21772177
}
21782178
}
21792179

2180-
impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>> {}
2180+
impl<'tcx, T: Eq> Eq for InternedInSet<'tcx, WithCachedTypeInfo<T>> {}
21812181

2182-
impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>> {
2183-
fn hash<H: Hasher>(&self, s: &mut H) {
2184-
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2185-
self.0.internee.hash(s)
2186-
}
2187-
}
2188-
2189-
impl<'tcx> Borrow<Binder<'tcx, PredicateKind<'tcx>>>
2190-
for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>
2191-
{
2192-
fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> {
2193-
&self.0.internee
2194-
}
2195-
}
2196-
2197-
impl<'tcx> PartialEq
2198-
for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>
2199-
{
2200-
fn eq(
2201-
&self,
2202-
other: &InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
2203-
) -> bool {
2204-
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
2205-
// `x == y`.
2206-
self.0.internee == other.0.internee
2207-
}
2208-
}
2209-
2210-
impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>> {}
2211-
2212-
impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>> {
2182+
impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, WithCachedTypeInfo<T>> {
22132183
fn hash<H: Hasher>(&self, s: &mut H) {
22142184
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
22152185
self.0.internee.hash(s)

0 commit comments

Comments
 (0)