Skip to content

Remove NodeId from Block and Expr #58698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
55 changes: 18 additions & 37 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ impl<'a> LoweringContext<'a> {
);

hir::GenericParam {
id: node_id,
hir_id,
name: hir_name,
attrs: hir_vec![],
Expand Down Expand Up @@ -1300,7 +1299,6 @@ impl<'a> LoweringContext<'a> {
// Set the name to `impl Bound1 + Bound2`.
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
in_band_ty_params.push(hir::GenericParam {
id: def_node_id,
hir_id,
name: ParamName::Plain(ident),
pure_wrt_drop: false,
Expand Down Expand Up @@ -1350,9 +1348,8 @@ 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);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id);
hir::Ty {
id: node_id,
node: kind,
span: t.span,
hir_id,
Expand Down Expand Up @@ -1394,12 +1391,11 @@ impl<'a> LoweringContext<'a> {
);

self.with_hir_id_owner(exist_ty_node_id, |lctx| {
let LoweredNodeId { node_id, hir_id } = lctx.next_id();
let LoweredNodeId { node_id: _, hir_id } = lctx.next_id();
let exist_ty_item_kind = hir::ItemKind::Existential(hir::ExistTy {
generics: hir::Generics {
params: lifetime_defs,
where_clause: hir::WhereClause {
id: node_id,
hir_id,
predicates: Vec::new().into(),
},
Expand Down Expand Up @@ -1533,9 +1529,8 @@ impl<'a> LoweringContext<'a> {
&& !self.already_defined_lifetimes.contains(&name) {
self.already_defined_lifetimes.insert(name);

let LoweredNodeId { node_id, hir_id } = self.context.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.context.next_id();
self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime {
id: node_id,
hir_id,
span: lifetime.span,
name,
Expand Down Expand Up @@ -1569,7 +1564,6 @@ impl<'a> LoweringContext<'a> {
};

self.output_lifetime_params.push(hir::GenericParam {
id: def_node_id,
hir_id,
name,
span: lifetime.span,
Expand Down Expand Up @@ -1980,8 +1974,8 @@ impl<'a> LoweringContext<'a> {
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
.collect();
let mk_tup = |this: &mut Self, tys, span| {
let LoweredNodeId { node_id, hir_id } = this.next_id();
hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span }
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span }
};
let LoweredNodeId { node_id, hir_id } = this.next_id();

Expand Down Expand Up @@ -2318,9 +2312,8 @@ impl<'a> LoweringContext<'a> {
this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id)))
}
FunctionRetTy::Default(span) => {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
P(hir::Ty {
id: node_id,
hir_id,
node: hir::TyKind::Tup(hir_vec![]),
span: *span,
Expand Down Expand Up @@ -2362,17 +2355,16 @@ impl<'a> LoweringContext<'a> {
];

if let Some((name, span)) = bound_lifetime {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
bounds.push(hir::GenericBound::Outlives(
hir::Lifetime { id: node_id, hir_id, name, span }));
hir::Lifetime { hir_id, name, span }));
}

hir::HirVec::from(bounds)
});

let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let impl_trait_ty = P(hir::Ty {
id: node_id,
node: impl_trait_ty,
span,
hir_id,
Expand Down Expand Up @@ -2431,10 +2423,9 @@ impl<'a> LoweringContext<'a> {
span: Span,
name: hir::LifetimeName,
) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::Lifetime {
id: node_id,
hir_id,
span,
name: name,
Expand Down Expand Up @@ -2524,10 +2515,9 @@ impl<'a> LoweringContext<'a> {
}
};

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(param.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(param.id);

hir::GenericParam {
id: node_id,
hir_id,
name,
span: param.ident.span,
Expand Down Expand Up @@ -2608,10 +2598,9 @@ impl<'a> LoweringContext<'a> {
self.with_anonymous_lifetime_mode(
AnonymousLifetimeMode::ReportError,
|this| {
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(wc.id);
let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(wc.id);

hir::WhereClause {
id: node_id,
hir_id,
predicates: wc.predicates
.iter()
Expand Down Expand Up @@ -2672,10 +2661,9 @@ impl<'a> LoweringContext<'a> {
ref rhs_ty,
span,
}) => {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);

hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
id: node_id,
hir_id,
lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()),
rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()),
Expand Down Expand Up @@ -2816,10 +2804,9 @@ impl<'a> LoweringContext<'a> {
}
}

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id);

P(hir::Block {
id: node_id,
hir_id,
stmts: stmts.into(),
expr,
Expand Down Expand Up @@ -3544,7 +3531,6 @@ impl<'a> LoweringContext<'a> {
name: ident.name,
vis,
attrs,
id: i.id,
hir_id,
span: i.span,
body,
Expand Down Expand Up @@ -3900,11 +3886,10 @@ impl<'a> LoweringContext<'a> {
// Wrap the `if let` expr in a block.
let span = els.span;
let els = P(self.lower_expr(els));
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let blk = P(hir::Block {
stmts: hir_vec![],
expr: Some(els),
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down Expand Up @@ -4978,12 +4963,11 @@ impl<'a> LoweringContext<'a> {
stmts: hir::HirVec<hir::Stmt>,
expr: Option<P<hir::Expr>>,
) -> hir::Block {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Block {
stmts,
expr,
id: node_id,
hir_id,
rules: hir::DefaultBlock,
span,
Expand Down Expand Up @@ -5108,7 +5092,6 @@ impl<'a> LoweringContext<'a> {
_ => hir::TyKind::Path(qpath),
};
hir::Ty {
id: id.node_id,
hir_id: id.hir_id,
node,
span,
Expand All @@ -5124,9 +5107,8 @@ impl<'a> LoweringContext<'a> {
// `'f`.
AnonymousLifetimeMode::CreateParameter => {
let fresh_name = self.collect_fresh_in_band_lifetime(span);
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
hir::Lifetime {
id: node_id,
hir_id,
span,
name: hir::LifetimeName::Param(fresh_name),
Expand Down Expand Up @@ -5227,10 +5209,9 @@ impl<'a> LoweringContext<'a> {
}

fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

hir::Lifetime {
id: node_id,
hir_id,
span,
name: hir::LifetimeName::Implicit,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}

fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
let def_index = self.definitions.opt_def_index(macro_def.id).unwrap();
let node_id = self.hir_to_node_id[&macro_def.hir_id];
let def_index = self.definitions.opt_def_index(node_id).unwrap();

self.with_dep_node_owner(def_index, macro_def, |this| {
this.insert(macro_def.span, macro_def.hir_id, Node::MacroDef(macro_def));
Expand Down
13 changes: 9 additions & 4 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,19 @@ impl<'hir> Map<'hir> {
Some(Def::Local(local.id))
}
Node::MacroDef(macro_def) => {
Some(Def::Macro(self.local_def_id(macro_def.id),
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),
MacroKind::Bang))
}
Node::GenericParam(param) => {
Some(match param.kind {
GenericParamKind::Lifetime { .. } => Def::Local(param.id),
GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)),
GenericParamKind::Const { .. } => Def::ConstParam(self.local_def_id(param.id)),
GenericParamKind::Lifetime { .. } => {
let node_id = self.hir_to_node_id(param.hir_id);
Def::Local(node_id)
},
GenericParamKind::Type { .. } => Def::TyParam(
self.local_def_id_from_hir_id(param.hir_id)),
GenericParamKind::Const { .. } => Def::ConstParam(
self.local_def_id_from_hir_id(param.hir_id)),
})
}
}
Expand Down
26 changes: 12 additions & 14 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use errors::FatalError;
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
use syntax::source_map::Spanned;
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
use syntax::ast::{Attribute, Label, Lit, StrStyle, FloatTy, IntTy, UintTy};
use syntax::attr::{InlineAttr, OptimizeAttr};
use syntax::ext::hygiene::SyntaxContext;
Expand Down Expand Up @@ -112,6 +112,12 @@ impl serialize::UseSpecializedDecodable for HirId {
}
}

impl fmt::Display for HirId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

// hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module
mod item_local_id_inner {
use rustc_data_structures::indexed_vec::Idx;
Expand Down Expand Up @@ -145,7 +151,6 @@ pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;

#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
pub struct Lifetime {
pub id: NodeId,
pub hir_id: HirId,
pub span: Span,

Expand Down Expand Up @@ -266,7 +271,7 @@ impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f,
"lifetime({}: {})",
self.id,
self.hir_id,
print::to_string(print::NO_ANN, |s| s.print_lifetime(self)))
}
}
Expand Down Expand Up @@ -411,11 +416,11 @@ impl GenericArg {
}
}

pub fn id(&self) -> NodeId {
pub fn id(&self) -> HirId {
match self {
GenericArg::Lifetime(l) => l.id,
GenericArg::Type(t) => t.id,
GenericArg::Const(c) => c.value.id,
GenericArg::Lifetime(l) => l.hir_id,
GenericArg::Type(t) => t.hir_id,
GenericArg::Const(c) => c.value.hir_id,
}
}
}
Expand Down Expand Up @@ -547,7 +552,6 @@ pub enum GenericParamKind {

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct GenericParam {
pub id: NodeId,
pub hir_id: HirId,
pub name: ParamName,
pub attrs: HirVec<Attribute>,
Expand Down Expand Up @@ -579,7 +583,6 @@ impl Generics {
Generics {
params: HirVec::new(),
where_clause: WhereClause {
id: DUMMY_NODE_ID,
hir_id: DUMMY_HIR_ID,
predicates: HirVec::new(),
},
Expand Down Expand Up @@ -624,7 +627,6 @@ pub enum SyntheticTyParamKind {
/// A where-clause in a definition.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct WhereClause {
pub id: NodeId,
pub hir_id: HirId,
pub predicates: HirVec<WherePredicate>,
}
Expand Down Expand Up @@ -685,7 +687,6 @@ pub struct WhereRegionPredicate {
/// An equality predicate (e.g., `T = int`); currently unsupported.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct WhereEqPredicate {
pub id: NodeId,
pub hir_id: HirId,
pub span: Span,
pub lhs_ty: P<Ty>,
Expand Down Expand Up @@ -808,7 +809,6 @@ pub struct MacroDef {
pub name: Name,
pub vis: Visibility,
pub attrs: HirVec<Attribute>,
pub id: NodeId,
pub hir_id: HirId,
pub span: Span,
pub body: TokenStream,
Expand All @@ -822,7 +822,6 @@ pub struct Block {
/// An expression at the end of the block
/// without a semicolon, if any.
pub expr: Option<P<Expr>>,
pub id: NodeId,
pub hir_id: HirId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
pub rules: BlockCheckMode,
Expand Down Expand Up @@ -1754,7 +1753,6 @@ pub struct TypeBinding {

#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Ty {
pub id: NodeId,
pub node: TyKind,
pub span: Span,
pub hir_id: HirId,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,6 @@ impl<'a> State<'a> {
let generics = hir::Generics {
params: hir::HirVec::new(),
where_clause: hir::WhereClause {
id: ast::DUMMY_NODE_ID,
hir_id: hir::DUMMY_HIR_ID,
predicates: hir::HirVec::new(),
},
Expand Down
Loading