Skip to content

Commit 2870ce0

Browse files
committed
Impl HashStable/Encodable/Decodable for ObligationCause.
1 parent caefec9 commit 2870ce0

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,8 @@ pub enum LocalSource {
21062106
}
21072107

21082108
/// Hints at the original code for a `match _ { .. }`.
2109-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
2110-
#[derive(HashStable_Generic)]
2109+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2110+
#[derive(HashStable_Generic, Encodable, Decodable)]
21112111
pub enum MatchSource {
21122112
/// A `match _ { .. }`.
21132113
Normal,

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner
3737

3838
/// Depending on the stage of compilation, we want projection to be
3939
/// more or less conservative.
40-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)]
40+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
4141
pub enum Reveal {
4242
/// At type-checking time, we refuse to project any associated
4343
/// type that is marked `default`. Non-`default` ("final") types
@@ -90,7 +90,8 @@ pub enum Reveal {
9090
///
9191
/// We do not want to intern this as there are a lot of obligation causes which
9292
/// only live for a short period of time.
93-
#[derive(Clone, Debug, PartialEq, Eq, Lift)]
93+
#[derive(Clone, Debug, PartialEq, Eq, Lift, HashStable, TyEncodable, TyDecodable)]
94+
#[derive(TypeVisitable, TypeFoldable)]
9495
pub struct ObligationCause<'tcx> {
9596
pub span: Span,
9697

@@ -197,14 +198,16 @@ impl<'tcx> ObligationCause<'tcx> {
197198
}
198199
}
199200

200-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
201+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, HashStable, TyEncodable, TyDecodable)]
202+
#[derive(TypeVisitable, TypeFoldable)]
201203
pub struct UnifyReceiverContext<'tcx> {
202204
pub assoc_item: ty::AssocItem,
203205
pub param_env: ty::ParamEnv<'tcx>,
204206
pub substs: SubstsRef<'tcx>,
205207
}
206208

207-
#[derive(Clone, PartialEq, Eq, Hash, Lift, Default)]
209+
#[derive(Clone, PartialEq, Eq, Hash, Lift, Default, HashStable)]
210+
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
208211
pub struct InternedObligationCauseCode<'tcx> {
209212
/// `None` for `ObligationCauseCode::MiscObligation` (a common case, occurs ~60% of
210213
/// the time). `Some` otherwise.
@@ -239,7 +242,8 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
239242
}
240243
}
241244

242-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
245+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, HashStable, TyEncodable, TyDecodable)]
246+
#[derive(TypeVisitable, TypeFoldable)]
243247
pub enum ObligationCauseCode<'tcx> {
244248
/// Not well classified or should be obvious from the span.
245249
MiscObligation,
@@ -447,7 +451,8 @@ pub enum ObligationCauseCode<'tcx> {
447451
/// This information is used to obtain an `hir::Ty`, which
448452
/// we can walk in order to obtain precise spans for any
449453
/// 'nested' types (e.g. `Foo` in `Option<Foo>`).
450-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
454+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
455+
#[derive(TypeVisitable, TypeFoldable)]
451456
pub enum WellFormedLoc {
452457
/// Use the type of the provided definition.
453458
Ty(LocalDefId),
@@ -464,7 +469,8 @@ pub enum WellFormedLoc {
464469
},
465470
}
466471

467-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
472+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, HashStable, TyEncodable, TyDecodable)]
473+
#[derive(TypeVisitable, TypeFoldable)]
468474
pub struct ImplDerivedObligationCause<'tcx> {
469475
pub derived: DerivedObligationCause<'tcx>,
470476
pub impl_def_id: DefId,
@@ -518,7 +524,8 @@ impl<'tcx> ty::Lift<'tcx> for StatementAsExpression {
518524
}
519525
}
520526

521-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
527+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, HashStable, TyEncodable, TyDecodable)]
528+
#[derive(TypeVisitable, TypeFoldable)]
522529
pub struct MatchExpressionArmCause<'tcx> {
523530
pub arm_block_id: Option<hir::HirId>,
524531
pub arm_ty: Ty<'tcx>,
@@ -534,7 +541,7 @@ pub struct MatchExpressionArmCause<'tcx> {
534541
}
535542

536543
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
537-
#[derive(Lift, TypeFoldable, TypeVisitable)]
544+
#[derive(Lift, TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)]
538545
pub struct IfExpressionCause<'tcx> {
539546
pub then_id: hir::HirId,
540547
pub else_id: hir::HirId,
@@ -544,7 +551,8 @@ pub struct IfExpressionCause<'tcx> {
544551
pub opt_suggest_box_span: Option<Span>,
545552
}
546553

547-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
554+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, HashStable, TyEncodable, TyDecodable)]
555+
#[derive(TypeVisitable, TypeFoldable)]
548556
pub struct DerivedObligationCause<'tcx> {
549557
/// The trait predicate of the parent obligation that led to the
550558
/// current obligation. Note that only trait obligations lead to

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'tcx> AdtDef<'tcx> {
188188
}
189189
}
190190

191-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, TyEncodable, TyDecodable)]
191+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable, TyEncodable, TyDecodable)]
192192
pub enum AdtKind {
193193
Struct,
194194
Union,

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for AllocId {
157157
}
158158
}
159159

160+
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::ParamEnv<'tcx> {
161+
fn encode(&self, e: &mut E) {
162+
self.caller_bounds().encode(e);
163+
self.reveal().encode(e);
164+
self.constness().encode(e);
165+
}
166+
}
167+
160168
#[inline]
161169
fn decode_arena_allocable<
162170
'tcx,
@@ -280,8 +288,17 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::SymbolName<'tcx>
280288
}
281289
}
282290

291+
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> {
292+
fn decode(d: &mut D) -> Self {
293+
let caller_bounds = Decodable::decode(d);
294+
let reveal = Decodable::decode(d);
295+
let constness = Decodable::decode(d);
296+
ty::ParamEnv::new(caller_bounds, reveal, constness)
297+
}
298+
}
299+
283300
macro_rules! impl_decodable_via_ref {
284-
($($t:ty),+) => {
301+
($($t:ty,)+) => {
285302
$(impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for $t {
286303
fn decode(decoder: &mut D) -> Self {
287304
RefDecodable::decode(decoder)
@@ -373,6 +390,15 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty
373390
}
374391
}
375392

393+
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::Predicate<'tcx>> {
394+
fn decode(decoder: &mut D) -> &'tcx Self {
395+
let len = decoder.read_usize();
396+
let predicates: Vec<_> =
397+
(0..len).map::<ty::Predicate<'tcx>, _>(|_| Decodable::decode(decoder)).collect();
398+
decoder.interner().intern_predicates(&predicates)
399+
}
400+
}
401+
376402
impl_decodable_via_ref! {
377403
&'tcx ty::TypeckResults<'tcx>,
378404
&'tcx ty::List<Ty<'tcx>>,
@@ -382,7 +408,8 @@ impl_decodable_via_ref! {
382408
&'tcx mir::UnsafetyCheckResult,
383409
&'tcx mir::BorrowCheckResult<'tcx>,
384410
&'tcx mir::coverage::CodeRegion,
385-
&'tcx ty::List<ty::BoundVariableKind>
411+
&'tcx ty::List<ty::BoundVariableKind>,
412+
&'tcx ty::List<ty::Predicate<'tcx>>,
386413
}
387414

388415
#[macro_export]
@@ -519,6 +546,8 @@ macro_rules! impl_binder_encode_decode {
519546
impl_binder_encode_decode! {
520547
&'tcx ty::List<Ty<'tcx>>,
521548
ty::FnSig<'tcx>,
549+
ty::Predicate<'tcx>,
550+
ty::TraitPredicate<'tcx>,
522551
ty::ExistentialPredicate<'tcx>,
523552
ty::TraitRef<'tcx>,
524553
Vec<ty::GeneratorInteriorTypeCause<'tcx>>,

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ TrivialTypeTraversalAndLiftImpls! {
201201
bool,
202202
usize,
203203
::rustc_target::abi::VariantIdx,
204+
u16,
204205
u32,
205206
u64,
206207
String,

0 commit comments

Comments
 (0)