Skip to content

Commit 95c40b8

Browse files
committed
Get rustc_middle compiling
1 parent e3db6dc commit 95c40b8

File tree

23 files changed

+148
-27
lines changed

23 files changed

+148
-27
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,6 @@ bitflags::bitflags! {
20272027
}
20282028

20292029
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
2030-
#[stable_hasher(no_hash_stable_eq)]
20312030
pub enum InlineAsmTemplatePiece {
20322031
String(String),
20332032
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },

compiler/rustc_attr/src/builtin.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ pub enum OptimizeAttr {
9393
/// - `#[unstable]`
9494
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
9595
#[derive(HashStable_Generic)]
96-
#[stable_hasher(no_hash_stable_eq)]
9796
pub struct Stability {
9897
pub level: StabilityLevel,
9998
pub feature: Symbol,
@@ -102,7 +101,6 @@ pub struct Stability {
102101
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
103102
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
104103
#[derive(HashStable_Generic)]
105-
#[stable_hasher(no_hash_stable_eq)]
106104
pub struct ConstStability {
107105
pub level: StabilityLevel,
108106
pub feature: Symbol,
@@ -113,7 +111,6 @@ pub struct ConstStability {
113111
/// The available stability levels.
114112
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
115113
#[derive(HashStable_Generic)]
116-
#[stable_hasher(no_hash_stable_eq)]
117114
pub enum StabilityLevel {
118115
// Reason for the current stability level and the relevant rust-lang issue
119116
Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },

compiler/rustc_data_structures/src/sorted_map.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::stable_hasher::{HashStable, StableHasher};
1+
use crate::stable_hasher::{HashStable, HashStableEq, StableHasher};
22
use std::borrow::Borrow;
33
use std::cmp::Ordering;
44
use std::iter::FromIterator;
@@ -298,5 +298,11 @@ impl<K: HashStable<CTX>, V: HashStable<CTX>, CTX> HashStable<CTX> for SortedMap<
298298
}
299299
}
300300

301+
impl<K: HashStableEq, V: HashStableEq> HashStableEq for SortedMap<K, V> {
302+
fn hash_stable_eq(&self, other: &Self) -> bool {
303+
self.data.hash_stable_eq(&other.data)
304+
}
305+
}
306+
301307
#[cfg(test)]
302308
mod tests;

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ impl HashStableEq for ::std::num::NonZeroUsize {
285285
}
286286
}
287287

288+
impl HashStableEq for ::std::num::NonZeroU32 {
289+
fn hash_stable_eq(&self, other: &Self) -> bool {
290+
self.get().hash_stable_eq(&other.get())
291+
}
292+
}
293+
294+
impl HashStableEq for ::std::num::NonZeroU64 {
295+
fn hash_stable_eq(&self, other: &Self) -> bool {
296+
self.get().hash_stable_eq(&other.get())
297+
}
298+
}
299+
288300
impl<CTX> HashStable<CTX> for f32 {
289301
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
290302
let val: u32 = unsafe { ::std::mem::transmute(*self) };
@@ -424,6 +436,25 @@ impl<T: HashStableEq> HashStableEq for Vec<T> {
424436
}
425437
}
426438

439+
impl<K: HashStableEq + Eq + Hash, V: HashStableEq, R: BuildHasher> HashStableEq for indexmap::IndexMap<K, V, R> {
440+
fn hash_stable_eq(&self, other: &Self) -> bool {
441+
if self.len() != other.len() {
442+
return false;
443+
}
444+
// Equal maps will have equal iteration orders
445+
// FIXME -is that actually right?
446+
self.iter().zip(other.iter()).all(|(first, second)| {
447+
first.hash_stable_eq(&second)
448+
})
449+
}
450+
}
451+
452+
impl<T> HashStableEq for std::marker::PhantomData<T> {
453+
fn hash_stable_eq(&self, other: &Self) -> bool {
454+
true
455+
}
456+
}
457+
427458
impl<K, V, R, CTX> HashStable<CTX> for indexmap::IndexMap<K, V, R>
428459
where
429460
K: HashStable<CTX> + Eq + Hash,
@@ -463,6 +494,12 @@ where
463494
}
464495
}
465496

497+
impl<A: smallvec::Array> HashStableEq for SmallVec<A> where <A as smallvec::Array>::Item: HashStableEq {
498+
fn hash_stable_eq(&self, other: &Self) -> bool {
499+
(&self[..]).hash_stable_eq(other)
500+
}
501+
}
502+
466503
impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Box<T> {
467504
#[inline]
468505
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
@@ -693,6 +730,49 @@ where
693730
}
694731
}
695732

733+
impl<K, V, R> HashStableEq for ::std::collections::HashMap<K, V, R>
734+
where
735+
K: HashStableEq + Eq + Hash,
736+
V: HashStableEq,
737+
R: BuildHasher,
738+
{
739+
fn hash_stable_eq(&self, other: &Self) -> bool {
740+
if self.len() != other.len() {
741+
return false;
742+
}
743+
self.iter().all(|(key, value)| {
744+
match other.get_key_value(key) {
745+
Some((other_key, other_value)) => {
746+
// Compare the key, since the `PartailEq` impl
747+
// used by the map may ignore information
748+
key.hash_stable_eq(other_key) && value.hash_stable_eq(other_value)
749+
}
750+
_ => false,
751+
}
752+
})
753+
}
754+
}
755+
756+
impl<K, R> HashStableEq for ::std::collections::HashSet<K, R>
757+
where
758+
K: HashStableEq + Eq + Hash,
759+
R: BuildHasher,
760+
{
761+
fn hash_stable_eq(&self, other: &Self) -> bool {
762+
if self.len() != other.len() {
763+
return false;
764+
}
765+
self.iter().all(|key| {
766+
match other.get(key) {
767+
// Compare the key, since the `PartailEq` impl
768+
// used by the map may ignore information
769+
Some(other_key) => key.hash_stable_eq(other_key),
770+
None => false,
771+
}
772+
})
773+
}
774+
}
775+
696776
impl<K, R, HCX> HashStable<HCX> for ::std::collections::HashSet<K, R>
697777
where
698778
K: ToStableHashKey<HCX> + Eq,

compiler/rustc_data_structures/src/tagged_ptr/copy.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{Pointer, Tag};
2-
use crate::stable_hasher::{HashStable, StableHasher};
2+
use crate::stable_hasher::{HashStable, HashStableEq, StableHasher};
33
use std::fmt;
44
use std::marker::PhantomData;
55
use std::num::NonZeroUsize;
@@ -161,6 +161,16 @@ where
161161
{
162162
}
163163

164+
impl<P, T> HashStableEq for CopyTaggedPtr<P, T, true>
165+
where
166+
P: Pointer,
167+
T: Tag,
168+
{
169+
fn hash_stable_eq(&self, other: &Self) -> bool {
170+
self == other
171+
}
172+
}
173+
164174
impl<P, T> std::hash::Hash for CopyTaggedPtr<P, T, true>
165175
where
166176
P: Pointer,

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ pub enum TraitItemKind<'hir> {
21352135
// The bodies for items are stored "out of line", in a separate
21362136
// hashmap in the `Crate`. Here we just record the hir-id of the item
21372137
// so it can fetched later.
2138-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
2138+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStableEq)]
21392139
pub struct ImplItemId {
21402140
pub def_id: LocalDefId,
21412141
}

compiler/rustc_index/src/bit_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::mem;
77
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds, Shl};
88
use std::slice;
99

10-
use rustc_macros::{Decodable, Encodable};
10+
use rustc_macros::{Decodable, Encodable, HashStableEq};
1111

1212
#[cfg(test)]
1313
mod tests;

compiler/rustc_middle/src/lint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl LintLevelSource {
5353
pub type LevelAndSource = (Level, LintLevelSource);
5454

5555
#[derive(Debug, HashStable)]
56+
#[stable_hasher(no_hash_stable_eq)]
5657
pub struct LintLevelSets {
5758
pub list: IndexVec<LintStackIndex, LintSet>,
5859
pub lint_cap: Level,
@@ -66,6 +67,8 @@ rustc_index::newtype_index! {
6667
}
6768

6869
#[derive(Debug, HashStable)]
70+
#[stable_hasher(no_hash_stable_eq)]
71+
// FIXME - how is LintId implementing HashStable ?
6972
pub struct LintSet {
7073
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
7174
// flag.

compiler/rustc_middle/src/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_span::Span;
1111
/// Module child can be either a proper item or a reexport (including private imports).
1212
/// In case of reexport all the fields describe the reexport item itself, not what it refers to.
1313
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
14+
#[stable_hasher(no_hash_stable_eq)]
1415
pub struct ModChild {
1516
/// Name of the item.
1617
pub ident: Ident,

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_span::symbol::Symbol;
44
use rustc_target::spec::SanitizerSet;
55

66
#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)]
7+
#[stable_hasher(no_hash_stable_eq)]
78
pub struct CodegenFnAttrs {
89
pub flags: CodegenFnAttrFlags,
910
/// Parsed representation of the `#[inline]` attribute

0 commit comments

Comments
 (0)