Skip to content

Commit 0b5aa1b

Browse files
committed
manually impl more traits for WithOptParam
1 parent 19d9fd5 commit 0b5aa1b

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/librustc_middle/ty/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ pub type PlaceholderConst = Placeholder<BoundVar>;
15761576
/// Luckily we only need to deal with const arguments once we
15771577
/// know their corresponding parameters. We (ab)use this by
15781578
/// calling `type_of(param_did)` for these arguments.
1579-
#[derive(Copy, Clone, Debug, Hash, HashStable, TypeFoldable, RustcEncodable, RustcDecodable)]
1579+
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
15801580
pub struct WithOptParam<T> {
15811581
pub did: T,
15821582
/// The `DefId` of the corresponding generic paramter in case `did` is
@@ -1586,13 +1586,27 @@ pub struct WithOptParam<T> {
15861586
pub param_did: Option<DefId>,
15871587
}
15881588

1589-
// We manually implement comparisions as the `param_did` can be ignored.
1589+
// We manually implement most traits for `WithOptParam`
1590+
// as the `param_did` is redundant.
1591+
15901592
impl<T: PartialEq> PartialEq for WithOptParam<T> {
15911593
fn eq(&self, other: &Self) -> bool {
15921594
self.did == other.did
15931595
}
15941596
}
15951597

1598+
impl<T: Hash> Hash for WithOptParam<T> {
1599+
fn hash<H: Hasher>(&self, state: &mut H) {
1600+
self.did.hash(state);
1601+
}
1602+
}
1603+
1604+
impl<CTX, T: HashStable<CTX>> HashStable<CTX> for WithOptParam<T> {
1605+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
1606+
self.did.hash_stable(hcx, hasher);
1607+
}
1608+
}
1609+
15961610
impl<T: Eq> Eq for WithOptParam<T> {}
15971611

15981612
impl<T: PartialOrd> PartialOrd for WithOptParam<T> {

src/librustc_middle/ty/structural_impls.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,23 @@ CloneTypeFoldableAndLiftImpls! {
261261
(),
262262
bool,
263263
usize,
264-
::rustc_target::abi::VariantIdx,
264+
rustc_target::abi::VariantIdx,
265265
u64,
266266
String,
267267
crate::middle::region::Scope,
268-
::rustc_ast::ast::FloatTy,
269-
::rustc_ast::ast::InlineAsmOptions,
270-
::rustc_ast::ast::InlineAsmTemplatePiece,
271-
::rustc_ast::ast::NodeId,
272-
::rustc_span::symbol::Symbol,
273-
::rustc_hir::def::Res,
274-
::rustc_hir::def_id::DefId,
275-
::rustc_hir::LlvmInlineAsmInner,
276-
::rustc_hir::MatchSource,
277-
::rustc_hir::Mutability,
278-
::rustc_hir::Unsafety,
279-
::rustc_target::asm::InlineAsmRegOrRegClass,
280-
::rustc_target::spec::abi::Abi,
268+
rustc_ast::ast::FloatTy,
269+
rustc_ast::ast::InlineAsmOptions,
270+
rustc_ast::ast::InlineAsmTemplatePiece,
271+
rustc_ast::ast::NodeId,
272+
rustc_span::symbol::Symbol,
273+
rustc_hir::def::Res,
274+
rustc_hir::def_id::DefId,
275+
rustc_hir::LlvmInlineAsmInner,
276+
rustc_hir::MatchSource,
277+
rustc_hir::Mutability,
278+
rustc_hir::Unsafety,
279+
rustc_target::asm::InlineAsmRegOrRegClass,
280+
rustc_target::spec::abi::Abi,
281281
crate::mir::Local,
282282
crate::mir::Promoted,
283283
crate::traits::Reveal,
@@ -299,6 +299,8 @@ CloneTypeFoldableAndLiftImpls! {
299299
crate::ty::RegionVid,
300300
crate::ty::UniverseIndex,
301301
crate::ty::Variance,
302+
crate::ty::WithOptParam<rustc_hir::def_id::LocalDefId>,
303+
crate::ty::WithOptParam<rustc_hir::def_id::DefId>,
302304
::rustc_span::Span,
303305
}
304306

0 commit comments

Comments
 (0)