Skip to content

Commit 07c5dfd

Browse files
committed
Split rustc_hir_id out of rustc_hir
Some crates depend on `rustc_hir` but only want `HirId` and similar id types. `rustc_hir` is a heavy dependency, since it pulls in `rustc_target`. Split these types out into their own crate `rustc_hir_id`. This allows `rustc_errors` to drop its direct dependency on `rustc_hir`. (`rustc_errors` still depends on `rustc_hir` indirectly through `rustc_lint_defs`; a subsequent commit will fix that.)
1 parent 237b6b5 commit 07c5dfd

File tree

10 files changed

+61
-35
lines changed

10 files changed

+61
-35
lines changed

Cargo.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3803,7 +3803,7 @@ dependencies = [
38033803
"rustc_error_messages",
38043804
"rustc_fluent_macro",
38053805
"rustc_hashes",
3806-
"rustc_hir",
3806+
"rustc_hir_id",
38073807
"rustc_index",
38083808
"rustc_lexer",
38093809
"rustc_lint_defs",
@@ -3899,6 +3899,7 @@ dependencies = [
38993899
"rustc_data_structures",
39003900
"rustc_error_messages",
39013901
"rustc_hashes",
3902+
"rustc_hir_id",
39023903
"rustc_index",
39033904
"rustc_macros",
39043905
"rustc_serialize",
@@ -3936,6 +3937,17 @@ dependencies = [
39363937
"tracing",
39373938
]
39383939

3940+
[[package]]
3941+
name = "rustc_hir_id"
3942+
version = "0.0.0"
3943+
dependencies = [
3944+
"rustc_data_structures",
3945+
"rustc_index",
3946+
"rustc_macros",
3947+
"rustc_serialize",
3948+
"rustc_span",
3949+
]
3950+
39393951
[[package]]
39403952
name = "rustc_hir_pretty"
39413953
version = "0.0.0"
@@ -4128,6 +4140,7 @@ dependencies = [
41284140
"rustc_data_structures",
41294141
"rustc_error_messages",
41304142
"rustc_hir",
4143+
"rustc_hir_id",
41314144
"rustc_macros",
41324145
"rustc_serialize",
41334146
"rustc_span",

compiler/rustc_errors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rustc_error_codes = { path = "../rustc_error_codes" }
1313
rustc_error_messages = { path = "../rustc_error_messages" }
1414
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1515
rustc_hashes = { path = "../rustc_hashes" }
16-
rustc_hir = { path = "../rustc_hir" }
16+
rustc_hir_id = { path = "../rustc_hir_id" }
1717
rustc_index = { path = "../rustc_index" }
1818
rustc_lexer = { path = "../rustc_lexer" }
1919
rustc_lint_defs = { path = "../rustc_lint_defs" }

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub use rustc_error_messages::{
6060
fallback_fluent_bundle, fluent_bundle, into_diag_arg_using_display,
6161
};
6262
use rustc_hashes::Hash128;
63-
use rustc_hir::HirId;
63+
use rustc_hir_id::HirId;
6464
pub use rustc_lint_defs::{Applicability, listify, pluralize};
6565
use rustc_lint_defs::{Lint, LintExpectationId};
6666
use rustc_macros::{Decodable, Encodable};

compiler/rustc_hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1414
rustc_data_structures = { path = "../rustc_data_structures" }
1515
rustc_error_messages = { path = "../rustc_error_messages" }
1616
rustc_hashes = { path = "../rustc_hashes" }
17+
rustc_hir_id = { path = "../rustc_hir_id" }
1718
rustc_index = { path = "../rustc_index" }
1819
rustc_macros = { path = "../rustc_macros" }
1920
rustc_serialize = { path = "../rustc_serialize" }

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
// tidy-alphabetical-start
6-
#![allow(internal_features)]
76
#![feature(associated_type_defaults)]
87
#![feature(closure_track_caller)]
98
#![feature(debug_closure_helpers)]
109
#![feature(exhaustive_patterns)]
11-
#![feature(negative_impls)]
1210
#![feature(never_type)]
13-
#![feature(rustc_attrs)]
1411
#![feature(variant_count)]
1512
#![recursion_limit = "256"]
1613
// tidy-alphabetical-end
@@ -25,7 +22,7 @@ pub mod definitions;
2522
pub mod diagnostic_items;
2623
pub use rustc_span::def_id;
2724
mod hir;
28-
pub mod hir_id;
25+
pub use rustc_hir_id::{self as hir_id, *};
2926
pub mod intravisit;
3027
pub mod lang_items;
3128
pub mod lints;
@@ -41,7 +38,6 @@ mod tests;
4138

4239
#[doc(no_inline)]
4340
pub use hir::*;
44-
pub use hir_id::*;
4541
pub use lang_items::{LangItem, LanguageItems};
4642
pub use stability::*;
4743
pub use stable_hash_impls::HashStableContext;

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::HashIgnoredAttrId;
55
use crate::hir::{
66
AttributeMap, BodyId, Crate, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
77
};
8-
use crate::hir_id::{HirId, ItemLocalId};
8+
use crate::hir_id::ItemLocalId;
99
use crate::lints::DelayedLints;
1010

1111
/// Requirements for a `StableHashingContext` to be used in this crate.
@@ -15,25 +15,6 @@ pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStabl
1515
fn hash_attr_id(&mut self, id: &HashIgnoredAttrId, hasher: &mut StableHasher);
1616
}
1717

18-
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
19-
type KeyType = (DefPathHash, ItemLocalId);
20-
21-
#[inline]
22-
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
23-
let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
24-
(def_path_hash, self.local_id)
25-
}
26-
}
27-
28-
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemLocalId {
29-
type KeyType = ItemLocalId;
30-
31-
#[inline]
32-
fn to_stable_hash_key(&self, _: &HirCtx) -> ItemLocalId {
33-
*self
34-
}
35-
}
36-
3718
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for BodyId {
3819
type KeyType = (DefPathHash, ItemLocalId);
3920

compiler/rustc_hir_id/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "rustc_hir_id"
3+
version = "0.0.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
# tidy-alphabetical-start
8+
rustc_data_structures = { path = "../rustc_data_structures" }
9+
rustc_index = { path = "../rustc_index" }
10+
rustc_macros = { path = "../rustc_macros" }
11+
rustc_serialize = { path = "../rustc_serialize" }
12+
rustc_span = { path = "../rustc_span" }
13+
# tidy-alphabetical-end

compiler/rustc_hir/src/hir_id.rs renamed to compiler/rustc_hir_id/src/lib.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
#![allow(internal_features)]
2+
#![feature(negative_impls)]
3+
#![feature(rustc_attrs)]
4+
15
use std::fmt::{self, Debug};
26

37
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
48
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
5-
use rustc_span::HashStableContext;
6-
use rustc_span::def_id::DefPathHash;
7-
8-
use crate::def_id::{CRATE_DEF_ID, DefId, DefIndex, LocalDefId};
9+
pub use rustc_span::HashStableContext;
10+
use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId};
911

1012
#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
1113
pub struct OwnerId {
@@ -171,3 +173,22 @@ pub const CRATE_HIR_ID: HirId =
171173
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO };
172174

173175
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
176+
177+
impl<CTX: rustc_span::HashStableContext> ToStableHashKey<CTX> for HirId {
178+
type KeyType = (DefPathHash, ItemLocalId);
179+
180+
#[inline]
181+
fn to_stable_hash_key(&self, hcx: &CTX) -> (DefPathHash, ItemLocalId) {
182+
let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
183+
(def_path_hash, self.local_id)
184+
}
185+
}
186+
187+
impl<CTX: HashStableContext> ToStableHashKey<CTX> for ItemLocalId {
188+
type KeyType = ItemLocalId;
189+
190+
#[inline]
191+
fn to_stable_hash_key(&self, _: &CTX) -> ItemLocalId {
192+
*self
193+
}
194+
}

compiler/rustc_lint_defs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rustc_ast = { path = "../rustc_ast" }
1010
rustc_data_structures = { path = "../rustc_data_structures" }
1111
rustc_error_messages = { path = "../rustc_error_messages" }
1212
rustc_hir = { path = "../rustc_hir" }
13+
rustc_hir_id = { path = "../rustc_hir_id" }
1314
rustc_macros = { path = "../rustc_macros" }
1415
rustc_serialize = { path = "../rustc_serialize" }
1516
rustc_span = { path = "../rustc_span" }

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::stable_hasher::{
1111
use rustc_error_messages::{DiagArgValue, DiagMessage, IntoDiagArg, MultiSpan};
1212
use rustc_hir::def::Namespace;
1313
use rustc_hir::def_id::DefPathHash;
14-
use rustc_hir::{HashStableContext, HirId, ItemLocalId};
14+
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
1515
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1616
pub use rustc_span::edition::Edition;
1717
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol, sym};
@@ -140,7 +140,7 @@ impl LintExpectationId {
140140
}
141141
}
142142

143-
impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
143+
impl<HCX: HashStableContext> HashStable<HCX> for LintExpectationId {
144144
#[inline]
145145
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
146146
match self {
@@ -158,7 +158,7 @@ impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
158158
}
159159
}
160160

161-
impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
161+
impl<HCX: HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
162162
type KeyType = (DefPathHash, ItemLocalId, u16, u16);
163163

164164
#[inline]

0 commit comments

Comments
 (0)