Skip to content

Commit 647eda1

Browse files
authored
Rollup merge of rust-lang#66457 - cjgillot:just_hashstable, r=Zoxc
Just derive Hashstable in librustc Split out of rust-lang#66279 r? @Zoxc
2 parents 00cbc75 + 579625b commit 647eda1

35 files changed

+70
-330
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,7 @@ dependencies = [
37193719
"rustc_errors",
37203720
"rustc_index",
37213721
"rustc_lexer",
3722+
"rustc_macros",
37223723
"rustc_target",
37233724
"serialize",
37243725
"smallvec 1.0.0",

src/librustc/dep_graph/dep_node.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ impl<'tcx> DepNodeParams<'tcx> for HirId {
578578
/// the need to be mapped or unmapped. (This ensures we can serialize
579579
/// them even in the absence of a tcx.)
580580
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
581-
RustcEncodable, RustcDecodable)]
581+
RustcEncodable, RustcDecodable, HashStable)]
582582
pub struct WorkProductId {
583583
hash: Fingerprint
584584
}
@@ -599,7 +599,3 @@ impl WorkProductId {
599599
}
600600
}
601601
}
602-
603-
impl_stable_hash_for!(struct crate::dep_graph::WorkProductId {
604-
hash
605-
});

src/librustc/hir/map/definitions.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ pub enum DefPathData {
313313
}
314314

315315
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
316-
RustcEncodable, RustcDecodable)]
316+
RustcEncodable, RustcDecodable, HashStable)]
317317
pub struct DefPathHash(pub Fingerprint);
318318

319-
impl_stable_hash_for!(tuple_struct DefPathHash { fingerprint });
320-
321319
impl Borrow<Fingerprint> for DefPathHash {
322320
#[inline]
323321
fn borrow(&self) -> &Fingerprint {

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ impl UnOp {
12151215
}
12161216

12171217
/// A statement.
1218-
#[derive(RustcEncodable, RustcDecodable)]
1218+
#[derive(RustcEncodable, RustcDecodable, HashStable)]
12191219
pub struct Stmt {
12201220
pub hir_id: HirId,
12211221
pub kind: StmtKind,

src/librustc/ich/impls_hir.rs

-7
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
140140

141141
impl_stable_hash_for_spanned!(hir::BinOpKind);
142142

143-
impl_stable_hash_for!(struct hir::Stmt {
144-
hir_id,
145-
kind,
146-
span,
147-
});
148-
149-
150143
impl_stable_hash_for_spanned!(ast::Name);
151144

152145
impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {

src/librustc/infer/outlives/free_region_map.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ty::{self, Lift, TyCtxt, Region};
22
use rustc_data_structures::transitive_relation::TransitiveRelation;
33

4-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)]
4+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default, HashStable)]
55
pub struct FreeRegionMap<'tcx> {
66
// Stores the relation `a < b`, where `a` and `b` are regions.
77
//
@@ -89,10 +89,6 @@ fn is_free_or_static(r: Region<'_>) -> bool {
8989
}
9090
}
9191

92-
impl_stable_hash_for!(struct FreeRegionMap<'tcx> {
93-
relation
94-
});
95-
9692
impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> {
9793
type Lifted = FreeRegionMap<'tcx>;
9894
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {

src/librustc/lint/mod.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,11 @@ impl LintId {
543543
}
544544

545545
/// Setting for how to handle a lint.
546-
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
546+
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable)]
547547
pub enum Level {
548548
Allow, Warn, Deny, Forbid,
549549
}
550550

551-
impl_stable_hash_for!(enum self::Level {
552-
Allow,
553-
Warn,
554-
Deny,
555-
Forbid
556-
});
557-
558551
impl Level {
559552
/// Converts a level to a lower-case string.
560553
pub fn as_str(self) -> &'static str {
@@ -590,7 +583,7 @@ impl Level {
590583
}
591584

592585
/// How a lint level was set.
593-
#[derive(Clone, Copy, PartialEq, Eq)]
586+
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
594587
pub enum LintSource {
595588
/// Lint is at the default level as declared
596589
/// in rustc or a plugin.
@@ -603,12 +596,6 @@ pub enum LintSource {
603596
CommandLine(Symbol),
604597
}
605598

606-
impl_stable_hash_for!(enum self::LintSource {
607-
Default,
608-
Node(name, span, reason),
609-
CommandLine(text)
610-
});
611-
612599
pub type LevelSource = (Level, LintSource);
613600

614601
pub mod builtin;

src/librustc/middle/exported_symbols.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ use crate::ty::subst::SubstsRef;
1111
/// kind of crate, including cdylibs which export very few things.
1212
/// `Rust` will only be exported if the crate produced is a Rust
1313
/// dylib.
14-
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
14+
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
1515
pub enum SymbolExportLevel {
1616
C,
1717
Rust,
1818
}
1919

20-
impl_stable_hash_for!(enum self::SymbolExportLevel {
21-
C,
22-
Rust
23-
});
24-
2520
impl SymbolExportLevel {
2621
pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool {
2722
threshold == SymbolExportLevel::Rust // export everything from Rust dylibs

src/librustc/middle/resolve_lifetime.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,14 @@ struct NamedRegionMap {
207207
}
208208

209209
/// See [`NamedRegionMap`].
210-
#[derive(Default)]
210+
#[derive(Default, HashStable)]
211211
pub struct ResolveLifetimes {
212212
defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
213213
late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
214214
object_lifetime_defaults:
215215
FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
216216
}
217217

218-
impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
219-
defs,
220-
late_bound,
221-
object_lifetime_defaults
222-
});
223-
224218
struct LifetimeContext<'a, 'tcx> {
225219
tcx: TyCtxt<'tcx>,
226220
map: &'a mut NamedRegionMap,

src/librustc/middle/stability.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ enum AnnotationKind {
5252
}
5353

5454
/// An entry in the `depr_map`.
55-
#[derive(Clone)]
55+
#[derive(Clone, HashStable)]
5656
pub struct DeprecationEntry {
5757
/// The metadata of the attribute associated with this entry.
5858
pub attr: Deprecation,
@@ -61,11 +61,6 @@ pub struct DeprecationEntry {
6161
origin: Option<HirId>,
6262
}
6363

64-
impl_stable_hash_for!(struct self::DeprecationEntry {
65-
attr,
66-
origin
67-
});
68-
6964
impl DeprecationEntry {
7065
fn local(attr: Deprecation, id: HirId) -> DeprecationEntry {
7166
DeprecationEntry {
@@ -90,6 +85,7 @@ impl DeprecationEntry {
9085
}
9186

9287
/// A stability index, giving the stability level for items and methods.
88+
#[derive(HashStable)]
9389
pub struct Index<'tcx> {
9490
/// This is mostly a cache, except the stabilities of local items
9591
/// are filled by the annotator.
@@ -103,13 +99,6 @@ pub struct Index<'tcx> {
10399
active_features: FxHashSet<Symbol>,
104100
}
105101

106-
impl_stable_hash_for!(struct self::Index<'tcx> {
107-
stab_map,
108-
depr_map,
109-
staged_api,
110-
active_features
111-
});
112-
113102
// A private tree-walker for producing an Index.
114103
struct Annotator<'a, 'tcx> {
115104
tcx: TyCtxt<'tcx>,

src/librustc/mir/interpret/allocation.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::{
44
Pointer, InterpResult, AllocId, ScalarMaybeUndef, write_target_uint, read_target_uint, Scalar,
55
};
66

7-
use crate::mir;
87
use crate::ty::layout::{Size, Align};
98

109
use rustc_data_structures::sorted_map::SortedMap;
@@ -787,14 +786,13 @@ type Block = u64;
787786

788787
/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
789788
/// is defined. If it is `false` the byte is undefined.
790-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
789+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash,
790+
RustcEncodable, RustcDecodable, HashStable)]
791791
pub struct UndefMask {
792792
blocks: Vec<Block>,
793793
len: Size,
794794
}
795795

796-
impl_stable_hash_for!(struct mir::interpret::UndefMask{blocks, len});
797-
798796
impl UndefMask {
799797
pub const BLOCK_SIZE: u64 = 64;
800798

src/librustc/mir/interpret/value.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
458458
}
459459
}
460460

461-
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable)]
461+
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable)]
462462
pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> {
463463
Scalar(Scalar<Tag, Id>),
464464
Undef,
@@ -583,11 +583,6 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
583583
}
584584
}
585585

586-
impl_stable_hash_for!(enum crate::mir::interpret::ScalarMaybeUndef {
587-
Scalar(v),
588-
Undef
589-
});
590-
591586
/// Gets the bytes of a constant slice value.
592587
pub fn get_slice_bytes<'tcx>(cx: &impl HasDataLayout, val: ConstValue<'tcx>) -> &'tcx [u8] {
593588
if let ConstValue::Slice { data, start, end } = val {

src/librustc/mir/mod.rs

+8-54
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
7070
/// The various "big phases" that MIR goes through.
7171
///
7272
/// Warning: ordering of variants is significant.
73-
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
73+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable,
74+
Debug, PartialEq, Eq, PartialOrd, Ord)]
7475
pub enum MirPhase {
7576
Build = 0,
7677
Const = 1,
@@ -86,7 +87,7 @@ impl MirPhase {
8687
}
8788

8889
/// The lowered representation of a single function.
89-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, TypeFoldable)]
90+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable, TypeFoldable)]
9091
pub struct Body<'tcx> {
9192
/// A list of basic blocks. References to basic block use a newtyped index type `BasicBlock`
9293
/// that indexes into this vector.
@@ -412,24 +413,6 @@ pub enum Safety {
412413
ExplicitUnsafe(hir::HirId),
413414
}
414415

415-
impl_stable_hash_for!(struct Body<'tcx> {
416-
phase,
417-
basic_blocks,
418-
source_scopes,
419-
source_scope_local_data,
420-
yield_ty,
421-
generator_drop,
422-
generator_layout,
423-
local_decls,
424-
user_type_annotations,
425-
arg_count,
426-
__upvar_debuginfo_codegen_only_do_not_use,
427-
spread_arg,
428-
control_flow_destroyed,
429-
span,
430-
cache
431-
});
432-
433416
impl<'tcx> Index<BasicBlock> for Body<'tcx> {
434417
type Output = BasicBlockData<'tcx>;
435418

@@ -609,7 +592,7 @@ pub enum LocalKind {
609592
ReturnPointer,
610593
}
611594

612-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
595+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
613596
pub struct VarBindingForm<'tcx> {
614597
/// Is variable bound via `x`, `mut x`, `ref x`, or `ref mut x`?
615598
pub binding_mode: ty::BindingMode,
@@ -642,7 +625,7 @@ pub enum BindingForm<'tcx> {
642625
}
643626

644627
/// Represents what type of implicit self a function has, if any.
645-
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
628+
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
646629
pub enum ImplicitSelfKind {
647630
/// Represents a `fn x(self);`.
648631
Imm,
@@ -659,28 +642,6 @@ pub enum ImplicitSelfKind {
659642

660643
CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
661644

662-
impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
663-
binding_mode,
664-
opt_ty_info,
665-
opt_match_place,
666-
pat_span
667-
});
668-
669-
impl_stable_hash_for!(enum self::ImplicitSelfKind {
670-
Imm,
671-
Mut,
672-
ImmRef,
673-
MutRef,
674-
None
675-
});
676-
677-
impl_stable_hash_for!(enum self::MirPhase {
678-
Build,
679-
Const,
680-
Validated,
681-
Optimized,
682-
});
683-
684645
mod binding_form_impl {
685646
use crate::ich::StableHashingContext;
686647
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -707,7 +668,7 @@ mod binding_form_impl {
707668
/// involved in borrow_check errors, e.g., explanations of where the
708669
/// temporaries come from, when their destructors are run, and/or how
709670
/// one might revise the code to satisfy the borrow checker's rules.
710-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
671+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
711672
pub struct BlockTailInfo {
712673
/// If `true`, then the value resulting from evaluating this tail
713674
/// expression is ignored by the block's expression context.
@@ -717,8 +678,6 @@ pub struct BlockTailInfo {
717678
pub tail_result_is_ignored: bool,
718679
}
719680

720-
impl_stable_hash_for!(struct BlockTailInfo { tail_result_is_ignored });
721-
722681
/// A MIR local.
723682
///
724683
/// This can be a binding declared by the user, a temporary inserted by the compiler, a function
@@ -1746,7 +1705,8 @@ pub enum PlaceBase<'tcx> {
17461705
}
17471706

17481707
/// We store the normalized type to avoid requiring normalization when reading MIR
1749-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
1708+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
1709+
RustcEncodable, RustcDecodable, HashStable)]
17501710
pub struct Static<'tcx> {
17511711
pub ty: Ty<'tcx>,
17521712
pub kind: StaticKind<'tcx>,
@@ -1768,12 +1728,6 @@ pub enum StaticKind<'tcx> {
17681728
Static,
17691729
}
17701730

1771-
impl_stable_hash_for!(struct Static<'tcx> {
1772-
ty,
1773-
kind,
1774-
def_id
1775-
});
1776-
17771731
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17781732
#[derive(RustcEncodable, RustcDecodable, HashStable)]
17791733
pub enum ProjectionElem<V, T> {

0 commit comments

Comments
 (0)