Skip to content

Commit ec7ecb3

Browse files
committed
Auto merge of #58079 - ljedrz:HirIdification_phase_1, r=Zoxc
hir: add HirId to main Hir nodes This is the 1st PR in a series dedicated to `HirId`-ification, i.e. deprecating `ast::NodeId`s after the AST > HIR lowering process. The bigger proof of concept can be seen in #57578. **Phase 1**: store `HirId` in all remaining (some already have it) main HIR nodes (excluding `*Id` objects). - [x] `Field` - [x] `FieldPat` - [x] `ForeignItem` - [x] `GenericParam` - [x] `Lifetime` - [x] `MacroDef` - [x] `PathSegment` - [x] `PatKind::Binding` - [x] `Stmt` - [x] `StructField` - [x] `TypeBinding` - [x] `VariantData` - [x] `WhereClause` - [x] `WhereEqPredicate` r? @Zoxc Cc @varkor
2 parents 8a57831 + 55ef78e commit ec7ecb3

File tree

24 files changed

+257
-114
lines changed

24 files changed

+257
-114
lines changed

src/librustc/hir/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn is_c_like_enum(item: &hir::Item) -> bool {
362362
if let hir::ItemKind::Enum(ref def, _) = item.node {
363363
for variant in &def.variants {
364364
match variant.node.data {
365-
hir::VariantData::Unit(_) => { /* continue */ }
365+
hir::VariantData::Unit(..) => { /* continue */ }
366366
_ => { return false; }
367367
}
368368
}

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
694694
PatKind::Ref(ref subpattern, _) => {
695695
visitor.visit_pat(subpattern)
696696
}
697-
PatKind::Binding(_, canonical_id, ident, ref optional_subpattern) => {
697+
PatKind::Binding(_, canonical_id, _hir_id, ident, ref optional_subpattern) => {
698698
visitor.visit_def_mention(Def::Local(canonical_id));
699699
visitor.visit_ident(ident);
700700
walk_list!(visitor, visit_pat, optional_subpattern);

src/librustc/hir/lowering.rs

+179-78
Large diffs are not rendered by default.

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl<'hir> Map<'hir> {
875875
Node::Field(f) => f.ident.name,
876876
Node::Lifetime(lt) => lt.name.ident().name,
877877
Node::GenericParam(param) => param.name.ident().name,
878-
Node::Binding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.name,
878+
Node::Binding(&Pat { node: PatKind::Binding(_, _, _, l, _), .. }) => l.name,
879879
Node::StructCtor(_) => self.name(self.get_parent(id)),
880880
_ => bug!("no name for {}", self.node_to_string(id))
881881
}

src/librustc/hir/mod.rs

+31-6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;
146146
#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
147147
pub struct Lifetime {
148148
pub id: NodeId,
149+
pub hir_id: HirId,
149150
pub span: Span,
150151

151152
/// Either "'a", referring to a named lifetime definition,
@@ -321,6 +322,7 @@ pub struct PathSegment {
321322
// affected. (In general, we don't bother to get the defs for synthesized
322323
// segments, only for segments which have come from the AST).
323324
pub id: Option<NodeId>,
325+
pub hir_id: Option<HirId>,
324326
pub def: Option<Def>,
325327

326328
/// Type/lifetime parameters attached to this path. They come in
@@ -343,6 +345,7 @@ impl PathSegment {
343345
PathSegment {
344346
ident,
345347
id: None,
348+
hir_id: None,
346349
def: None,
347350
infer_types: true,
348351
args: None,
@@ -352,13 +355,15 @@ impl PathSegment {
352355
pub fn new(
353356
ident: Ident,
354357
id: Option<NodeId>,
358+
hir_id: Option<HirId>,
355359
def: Option<Def>,
356360
args: GenericArgs,
357361
infer_types: bool,
358362
) -> Self {
359363
PathSegment {
360364
ident,
361365
id,
366+
hir_id,
362367
def,
363368
infer_types,
364369
args: if args.is_empty() {
@@ -528,6 +533,7 @@ pub enum GenericParamKind {
528533
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
529534
pub struct GenericParam {
530535
pub id: NodeId,
536+
pub hir_id: HirId,
531537
pub name: ParamName,
532538
pub attrs: HirVec<Attribute>,
533539
pub bounds: GenericBounds,
@@ -558,6 +564,7 @@ impl Generics {
558564
params: HirVec::new(),
559565
where_clause: WhereClause {
560566
id: DUMMY_NODE_ID,
567+
hir_id: DUMMY_HIR_ID,
561568
predicates: HirVec::new(),
562569
},
563570
span: DUMMY_SP,
@@ -601,6 +608,7 @@ pub enum SyntheticTyParamKind {
601608
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
602609
pub struct WhereClause {
603610
pub id: NodeId,
611+
pub hir_id: HirId,
604612
pub predicates: HirVec<WherePredicate>,
605613
}
606614

@@ -661,6 +669,7 @@ pub struct WhereRegionPredicate {
661669
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
662670
pub struct WhereEqPredicate {
663671
pub id: NodeId,
672+
pub hir_id: HirId,
664673
pub span: Span,
665674
pub lhs_ty: P<Ty>,
666675
pub rhs_ty: P<Ty>,
@@ -789,6 +798,7 @@ pub struct MacroDef {
789798
pub vis: Visibility,
790799
pub attrs: HirVec<Attribute>,
791800
pub id: NodeId,
801+
pub hir_id: HirId,
792802
pub span: Span,
793803
pub body: TokenStream,
794804
pub legacy: bool,
@@ -878,6 +888,7 @@ impl Pat {
878888
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
879889
pub struct FieldPat {
880890
pub id: NodeId,
891+
pub hir_id: HirId,
881892
/// The identifier for the field
882893
pub ident: Ident,
883894
/// The pattern the field is destructured to
@@ -924,7 +935,7 @@ pub enum PatKind {
924935
/// The `NodeId` is the canonical ID for the variable being bound,
925936
/// e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID,
926937
/// which is the pattern ID of the first `x`.
927-
Binding(BindingAnnotation, NodeId, Ident, Option<P<Pat>>),
938+
Binding(BindingAnnotation, NodeId, HirId, Ident, Option<P<Pat>>),
928939

929940
/// A struct or struct variant pattern, e.g., `Variant {x, y, ..}`.
930941
/// The `bool` is `true` in the presence of a `..`.
@@ -1137,6 +1148,7 @@ impl UnOp {
11371148
#[derive(Clone, RustcEncodable, RustcDecodable)]
11381149
pub struct Stmt {
11391150
pub id: NodeId,
1151+
pub hir_id: HirId,
11401152
pub node: StmtKind,
11411153
pub span: Span,
11421154
}
@@ -1204,6 +1216,7 @@ pub enum Guard {
12041216
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
12051217
pub struct Field {
12061218
pub id: NodeId,
1219+
pub hir_id: HirId,
12071220
pub ident: Ident,
12081221
pub expr: P<Expr>,
12091222
pub span: Span,
@@ -1711,6 +1724,7 @@ pub enum ImplItemKind {
17111724
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
17121725
pub struct TypeBinding {
17131726
pub id: NodeId,
1727+
pub hir_id: HirId,
17141728
pub ident: Ident,
17151729
pub ty: P<Ty>,
17161730
pub span: Span,
@@ -2106,6 +2120,7 @@ pub struct StructField {
21062120
pub ident: Ident,
21072121
pub vis: Visibility,
21082122
pub id: NodeId,
2123+
pub hir_id: HirId,
21092124
pub ty: P<Ty>,
21102125
pub attrs: HirVec<Attribute>,
21112126
}
@@ -2131,21 +2146,30 @@ impl StructField {
21312146
/// Id of the whole struct lives in `Item`.
21322147
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
21332148
pub enum VariantData {
2134-
Struct(HirVec<StructField>, NodeId),
2135-
Tuple(HirVec<StructField>, NodeId),
2136-
Unit(NodeId),
2149+
Struct(HirVec<StructField>, NodeId, HirId),
2150+
Tuple(HirVec<StructField>, NodeId, HirId),
2151+
Unit(NodeId, HirId),
21372152
}
21382153

21392154
impl VariantData {
21402155
pub fn fields(&self) -> &[StructField] {
21412156
match *self {
2142-
VariantData::Struct(ref fields, _) | VariantData::Tuple(ref fields, _) => fields,
2157+
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields,
21432158
_ => &[],
21442159
}
21452160
}
21462161
pub fn id(&self) -> NodeId {
21472162
match *self {
2148-
VariantData::Struct(_, id) | VariantData::Tuple(_, id) | VariantData::Unit(id) => id,
2163+
VariantData::Struct(_, id, ..)
2164+
| VariantData::Tuple(_, id, ..)
2165+
| VariantData::Unit(id, ..) => id,
2166+
}
2167+
}
2168+
pub fn hir_id(&self) -> HirId {
2169+
match *self {
2170+
VariantData::Struct(_, _, hir_id)
2171+
| VariantData::Tuple(_, _, hir_id)
2172+
| VariantData::Unit(_, hir_id) => hir_id,
21492173
}
21502174
}
21512175
pub fn is_struct(&self) -> bool {
@@ -2343,6 +2367,7 @@ pub struct ForeignItem {
23432367
pub attrs: HirVec<Attribute>,
23442368
pub node: ForeignItemKind,
23452369
pub id: NodeId,
2370+
pub hir_id: HirId,
23462371
pub span: Span,
23472372
pub vis: Visibility,
23482373
}

src/librustc/hir/pat_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl hir::Pat {
8383
where F: FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident),
8484
{
8585
self.walk(|p| {
86-
if let PatKind::Binding(binding_mode, _, ident, _) = p.node {
86+
if let PatKind::Binding(binding_mode, _, _, ident, _) = p.node {
8787
f(binding_mode, p.hir_id, p.span, ident);
8888
}
8989
true
@@ -123,8 +123,8 @@ impl hir::Pat {
123123

124124
pub fn simple_ident(&self) -> Option<ast::Ident> {
125125
match self.node {
126-
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) |
127-
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, None) => Some(ident),
126+
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, None) |
127+
PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, None) => Some(ident),
128128
_ => None,
129129
}
130130
}

src/librustc/hir/print.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ impl<'a> State<'a> {
17681768
// is that it doesn't matter
17691769
match pat.node {
17701770
PatKind::Wild => self.s.word("_")?,
1771-
PatKind::Binding(binding_mode, _, ident, ref sub) => {
1771+
PatKind::Binding(binding_mode, _, _, ident, ref sub) => {
17721772
match binding_mode {
17731773
hir::BindingAnnotation::Ref => {
17741774
self.word_nbsp("ref")?;
@@ -2246,6 +2246,7 @@ impl<'a> State<'a> {
22462246
params: hir::HirVec::new(),
22472247
where_clause: hir::WhereClause {
22482248
id: ast::DUMMY_NODE_ID,
2249+
hir_id: hir::DUMMY_HIR_ID,
22492250
predicates: hir::HirVec::new(),
22502251
},
22512252
span: syntax_pos::DUMMY_SP,

src/librustc/ich/impls_hir.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl_stable_hash_for!(struct ast::Label {
159159

160160
impl_stable_hash_for!(struct hir::Lifetime {
161161
id,
162+
hir_id,
162163
span,
163164
name
164165
});
@@ -172,6 +173,7 @@ impl_stable_hash_for!(struct hir::Path {
172173
impl_stable_hash_for!(struct hir::PathSegment {
173174
ident -> (ident.name),
174175
id,
176+
hir_id,
175177
def,
176178
infer_types,
177179
args
@@ -200,6 +202,7 @@ impl_stable_hash_for!(enum hir::TraitBoundModifier {
200202

201203
impl_stable_hash_for!(struct hir::GenericParam {
202204
id,
205+
hir_id,
203206
name,
204207
pure_wrt_drop,
205208
attrs,
@@ -244,6 +247,7 @@ impl_stable_hash_for!(enum hir::SyntheticTyParamKind {
244247

245248
impl_stable_hash_for!(struct hir::WhereClause {
246249
id,
250+
hir_id,
247251
predicates
248252
});
249253

@@ -268,6 +272,7 @@ impl_stable_hash_for!(struct hir::WhereRegionPredicate {
268272

269273
impl_stable_hash_for!(struct hir::WhereEqPredicate {
270274
id,
275+
hir_id,
271276
span,
272277
lhs_ty,
273278
rhs_ty
@@ -285,6 +290,7 @@ impl_stable_hash_for!(struct hir::MethodSig {
285290

286291
impl_stable_hash_for!(struct hir::TypeBinding {
287292
id,
293+
hir_id,
288294
ident -> (ident.name),
289295
ty,
290296
span
@@ -397,6 +403,7 @@ impl_stable_hash_for!(struct hir::MacroDef {
397403
vis,
398404
attrs,
399405
id,
406+
hir_id,
400407
span,
401408
legacy,
402409
body
@@ -423,6 +430,7 @@ impl_stable_hash_for_spanned!(hir::FieldPat);
423430

424431
impl_stable_hash_for!(struct hir::FieldPat {
425432
id -> _,
433+
hir_id -> _,
426434
ident -> (ident.name),
427435
pat,
428436
is_shorthand,
@@ -442,7 +450,7 @@ impl_stable_hash_for!(enum hir::RangeEnd {
442450

443451
impl_stable_hash_for!(enum hir::PatKind {
444452
Wild,
445-
Binding(binding_mode, var, name, sub),
453+
Binding(binding_mode, var, hir_id, name, sub),
446454
Struct(path, field_pats, dotdot),
447455
TupleStruct(path, field_pats, dotdot),
448456
Path(path),
@@ -485,6 +493,7 @@ impl_stable_hash_for!(enum hir::UnOp {
485493

486494
impl_stable_hash_for!(struct hir::Stmt {
487495
id,
496+
hir_id,
488497
node,
489498
span,
490499
});
@@ -514,6 +523,7 @@ impl_stable_hash_for!(enum hir::Guard {
514523

515524
impl_stable_hash_for!(struct hir::Field {
516525
id -> _,
526+
hir_id -> _,
517527
ident,
518528
expr,
519529
span,
@@ -836,14 +846,15 @@ impl_stable_hash_for!(struct hir::StructField {
836846
ident -> (ident.name),
837847
vis,
838848
id,
849+
hir_id,
839850
ty,
840851
attrs
841852
});
842853

843854
impl_stable_hash_for!(enum hir::VariantData {
844-
Struct(fields, id),
845-
Tuple(fields, id),
846-
Unit(id)
855+
Struct(fields, id, hir_id),
856+
Tuple(fields, id, hir_id),
857+
Unit(id, hir_id)
847858
});
848859

849860
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
@@ -929,6 +940,7 @@ impl_stable_hash_for!(struct hir::ForeignItem {
929940
attrs,
930941
node,
931942
id,
943+
hir_id,
932944
span,
933945
vis
934946
});

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
408408
while let Some(pat) = pats.pop_front() {
409409
use hir::PatKind::*;
410410
match pat.node {
411-
Binding(_, _, _, ref inner_pat) => {
411+
Binding(_, _, _, _, ref inner_pat) => {
412412
pats.extend(inner_pat.iter());
413413
}
414414
Struct(_, ref fields, _) => {

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10241024
Node::Variant(&hir::Variant {
10251025
span,
10261026
node: hir::VariantKind {
1027-
data: hir::VariantData::Tuple(ref fields, _),
1027+
data: hir::VariantData::Tuple(ref fields, ..),
10281028
..
10291029
},
10301030
..

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>,
9999
cmt: &'c mc::cmt_<'tcx>) {
100100
let source = get_pattern_source(bccx.tcx,move_pat);
101101
let pat_span_path_opt = match move_pat.node {
102-
PatKind::Binding(_, _, ident, _) => {
102+
PatKind::Binding(_, _, _, ident, _) => {
103103
Some(MovePlace {
104104
span: move_pat.span,
105105
name: ident.name,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
191191
// (Issue #49588)
192192
continue;
193193
}
194-
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
194+
if let PatKind::Binding(_, _, _, ident, None) = fieldpat.node.pat.node {
195195
if cx.tcx.find_field_index(ident, &variant) ==
196196
Some(cx.tcx.field_index(fieldpat.node.id, cx.tables)) {
197197
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
340340
}
341341

342342
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
343-
if let &PatKind::Binding(_, _, ident, _) = &p.node {
343+
if let &PatKind::Binding(_, _, _, ident, _) = &p.node {
344344
self.check_snake_case(cx, "variable", &ident);
345345
}
346346
}

0 commit comments

Comments
 (0)