From 5b9b50e712e583423e7204747271ff56a3975f78 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 13 Sep 2017 18:29:59 +0300 Subject: [PATCH] Give HirId to hir::Ty --- src/librustc/hir/lowering.rs | 21 ++++++++++++--------- src/librustc/hir/mod.rs | 1 + src/librustc/ich/impls_hir.rs | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 465520ea034..f0cb59c08d2 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -685,7 +685,7 @@ impl<'a> LoweringContext<'a> { return self.lower_ty(ty); } TyKind::Path(ref qself, ref path) => { - let id = self.lower_node_id(t.id).node_id; + let id = self.lower_node_id(t.id); let qpath = self.lower_qpath(t.id, qself, path, ParamMode::Explicit); return self.ty_path(id, t.span, qpath); } @@ -734,10 +734,12 @@ impl<'a> LoweringContext<'a> { TyKind::Mac(_) => panic!("TyMac should have been expanded by now."), }; + let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id); P(hir::Ty { - id: self.lower_node_id(t.id).node_id, + id: node_id, node: kind, span: t.span, + hir_id, }) } @@ -863,7 +865,7 @@ impl<'a> LoweringContext<'a> { // Otherwise, the base path is an implicit `Self` type path, // e.g. `Vec` in `Vec::new` or `::Item` in // `::Item::default`. - let new_id = self.next_id().node_id; + let new_id = self.next_id(); self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)) }; @@ -888,7 +890,7 @@ impl<'a> LoweringContext<'a> { } // Wrap the associated extension in another type node. - let new_id = self.next_id().node_id; + let new_id = self.next_id(); ty = self.ty_path(new_id, p.span, qpath); } @@ -996,7 +998,8 @@ impl<'a> LoweringContext<'a> { let &ParenthesizedParameterData { ref inputs, ref output, span } = data; let inputs = inputs.iter().map(|ty| self.lower_ty(ty)).collect(); let mk_tup = |this: &mut Self, tys, span| { - P(hir::Ty { node: hir::TyTup(tys), id: this.next_id().node_id, span }) + let LoweredNodeId { node_id, hir_id } = this.next_id(); + P(hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span }) }; hir::PathParameters { @@ -2976,7 +2979,7 @@ impl<'a> LoweringContext<'a> { self.expr_block(block, attrs) } - fn ty_path(&mut self, id: NodeId, span: Span, qpath: hir::QPath) -> P { + fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> P { let mut id = id; let node = match qpath { hir::QPath::Resolved(None, path) => { @@ -2986,14 +2989,14 @@ impl<'a> LoweringContext<'a> { bound_lifetimes: hir_vec![], trait_ref: hir::TraitRef { path: path.and_then(|path| path), - ref_id: id, + ref_id: id.node_id, }, span, }; // The original ID is taken by the `PolyTraitRef`, // so the `Ty` itself needs a different one. - id = self.next_id().node_id; + id = self.next_id(); hir::TyTraitObject(hir_vec![principal], self.elided_lifetime(span)) } else { @@ -3002,7 +3005,7 @@ impl<'a> LoweringContext<'a> { } _ => hir::TyPath(qpath) }; - P(hir::Ty { id, node, span }) + P(hir::Ty { id: id.node_id, hir_id: id.hir_id, node, span }) } fn elided_lifetime(&mut self, span: Span) -> hir::Lifetime { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 1bef17b28ac..e96edaa86d2 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1354,6 +1354,7 @@ pub struct Ty { pub id: NodeId, pub node: Ty_, pub span: Span, + pub hir_id: HirId, } impl fmt::Debug for Ty { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index b62b9e5ab46..bc0c52575ae 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -245,6 +245,7 @@ impl<'gcx> HashStable> for hir::Ty { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Ty { id: _, + hir_id: _, ref node, ref span, } = *self;