Skip to content

Commit e4f8a6b

Browse files
committed
hir: remove NodeId from GenericParam
1 parent 1c18ac1 commit e4f8a6b

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ impl<'a> LoweringContext<'a> {
780780
);
781781

782782
hir::GenericParam {
783-
id: node_id,
784783
hir_id,
785784
name: hir_name,
786785
attrs: hir_vec![],
@@ -1300,7 +1299,6 @@ impl<'a> LoweringContext<'a> {
13001299
// Set the name to `impl Bound1 + Bound2`.
13011300
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
13021301
in_band_ty_params.push(hir::GenericParam {
1303-
id: def_node_id,
13041302
hir_id,
13051303
name: ParamName::Plain(ident),
13061304
pure_wrt_drop: false,
@@ -1567,7 +1565,6 @@ impl<'a> LoweringContext<'a> {
15671565
};
15681566

15691567
self.output_lifetime_params.push(hir::GenericParam {
1570-
id: def_node_id,
15711568
hir_id,
15721569
name,
15731570
span: lifetime.span,
@@ -2519,10 +2516,9 @@ impl<'a> LoweringContext<'a> {
25192516
}
25202517
};
25212518

2522-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(param.id);
2519+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(param.id);
25232520

25242521
hir::GenericParam {
2525-
id: node_id,
25262522
hir_id,
25272523
name,
25282524
span: param.ident.span,

src/librustc/hir/map/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,14 @@ impl<'hir> Map<'hir> {
395395
}
396396
Node::GenericParam(param) => {
397397
Some(match param.kind {
398-
GenericParamKind::Lifetime { .. } => Def::Local(param.id),
399-
GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)),
400-
GenericParamKind::Const { .. } => Def::ConstParam(self.local_def_id(param.id)),
398+
GenericParamKind::Lifetime { .. } => {
399+
let node_id = self.hir_to_node_id(param.hir_id);
400+
Def::Local(node_id)
401+
},
402+
GenericParamKind::Type { .. } => Def::TyParam(
403+
self.local_def_id_from_hir_id(param.hir_id)),
404+
GenericParamKind::Const { .. } => Def::ConstParam(
405+
self.local_def_id_from_hir_id(param.hir_id)),
401406
})
402407
}
403408
}

src/librustc/hir/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl GenericArg {
420420
match self {
421421
GenericArg::Lifetime(l) => l.hir_id,
422422
GenericArg::Type(t) => t.hir_id,
423-
GenericArg::Const(c) => c.value.id,
423+
GenericArg::Const(c) => c.value.hir_id,
424424
}
425425
}
426426
}
@@ -552,7 +552,6 @@ pub enum GenericParamKind {
552552

553553
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
554554
pub struct GenericParam {
555-
pub id: NodeId,
556555
pub hir_id: HirId,
557556
pub name: ParamName,
558557
pub attrs: HirVec<Attribute>,

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ impl_stable_hash_for!(enum hir::TraitBoundModifier {
206206
});
207207

208208
impl_stable_hash_for!(struct hir::GenericParam {
209-
id,
210209
hir_id,
211210
name,
212211
pure_wrt_drop,

src/librustc/middle/resolve_lifetime.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
1313

1414
use crate::rustc::lint;
1515
use crate::session::Session;
16-
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, NodeMap, NodeSet};
16+
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet, NodeMap};
1717
use errors::{Applicability, DiagnosticBuilder};
1818
use rustc_data_structures::sync::Lrc;
1919
use std::borrow::Cow;
@@ -83,15 +83,15 @@ impl Region {
8383
fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam) -> (ParamName, Region) {
8484
let i = *index;
8585
*index += 1;
86-
let def_id = hir_map.local_def_id(param.id);
86+
let def_id = hir_map.local_def_id_from_hir_id(param.hir_id);
8787
let origin = LifetimeDefOrigin::from_param(param);
8888
debug!("Region::early: index={} def_id={:?}", i, def_id);
8989
(param.name.modern(), Region::EarlyBound(i, def_id, origin))
9090
}
9191

9292
fn late(hir_map: &Map<'_>, param: &GenericParam) -> (ParamName, Region) {
9393
let depth = ty::INNERMOST;
94-
let def_id = hir_map.local_def_id(param.id);
94+
let def_id = hir_map.local_def_id_from_hir_id(param.hir_id);
9595
let origin = LifetimeDefOrigin::from_param(param);
9696
debug!(
9797
"Region::late: param={:?} depth={:?} def_id={:?} origin={:?}",
@@ -200,7 +200,7 @@ struct NamedRegionMap {
200200
// the set of lifetime def ids that are late-bound; a region can
201201
// be late-bound if (a) it does NOT appear in a where-clause and
202202
// (b) it DOES appear in the arguments.
203-
pub late_bound: NodeSet,
203+
pub late_bound: HirIdSet,
204204

205205
// For each type and trait definition, maps type parameters
206206
// to the trait object lifetime defaults computed from them.
@@ -389,8 +389,7 @@ fn resolve_lifetimes<'tcx>(
389389
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
390390
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
391391
}
392-
for k in named_region_map.late_bound {
393-
let hir_id = tcx.hir().node_to_hir_id(k);
392+
for hir_id in named_region_map.late_bound {
394393
let map = rl.late_bound
395394
.entry(hir_id.owner_local_def_id())
396395
.or_default();
@@ -1338,7 +1337,7 @@ fn object_lifetime_defaults_for_item(
13381337

13391338
add_bounds(&mut set, &param.bounds);
13401339

1341-
let param_def_id = tcx.hir().local_def_id(param.id);
1340+
let param_def_id = tcx.hir().local_def_id_from_hir_id(param.hir_id);
13421341
for predicate in &generics.where_clause.predicates {
13431342
// Look for `type: ...` where clauses.
13441343
let data = match *predicate {
@@ -1373,7 +1372,7 @@ fn object_lifetime_defaults_for_item(
13731372
.iter()
13741373
.filter_map(|param| match param.kind {
13751374
GenericParamKind::Lifetime { .. } => Some((
1376-
param.id,
1375+
param.hir_id,
13771376
hir::LifetimeName::Param(param.name),
13781377
LifetimeDefOrigin::from_param(param),
13791378
)),
@@ -1382,7 +1381,7 @@ fn object_lifetime_defaults_for_item(
13821381
.enumerate()
13831382
.find(|&(_, (_, lt_name, _))| lt_name == name)
13841383
.map_or(Set1::Many, |(i, (id, _, origin))| {
1385-
let def_id = tcx.hir().local_def_id(id);
1384+
let def_id = tcx.hir().local_def_id_from_hir_id(id);
13861385
Set1::One(Region::EarlyBound(i as u32, def_id, origin))
13871386
})
13881387
}
@@ -1707,7 +1706,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17071706
let mut non_lifetime_count = 0;
17081707
let lifetimes = generics.params.iter().filter_map(|param| match param.kind {
17091708
GenericParamKind::Lifetime { .. } => {
1710-
if self.map.late_bound.contains(&param.id) {
1709+
if self.map.late_bound.contains(&param.hir_id) {
17111710
Some(Region::late(&self.tcx.hir(), param))
17121711
} else {
17131712
Some(Region::early(&self.tcx.hir(), &mut index, param))
@@ -2792,11 +2791,11 @@ fn insert_late_bound_lifetimes(
27922791
debug!(
27932792
"insert_late_bound_lifetimes: lifetime {:?} with id {:?} is late-bound",
27942793
param.name.ident(),
2795-
param.id
2794+
param.hir_id
27962795
);
27972796

2798-
let inserted = map.late_bound.insert(param.id);
2799-
assert!(inserted, "visited lifetime {:?} twice", param.id);
2797+
let inserted = map.late_bound.insert(param.hir_id);
2798+
assert!(inserted, "visited lifetime {:?} twice", param.hir_id);
28002799
}
28012800

28022801
return;

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,13 +1702,13 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
17021702
match param.kind {
17031703
hir::GenericParamKind::Lifetime { .. } => {}
17041704
hir::GenericParamKind::Type { ref default, .. } => {
1705-
let def_id = self.tcx.hir().local_def_id(param.id);
1705+
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
17061706
let has_default = Untracked(default.is_some());
17071707
let encode_info = IsolatedEncoder::encode_info_for_ty_param;
17081708
self.record(def_id, encode_info, (def_id, has_default));
17091709
}
17101710
hir::GenericParamKind::Const { .. } => {
1711-
let def_id = self.tcx.hir().local_def_id(param.id);
1711+
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
17121712
let encode_info = IsolatedEncoder::encode_info_for_const_param;
17131713
self.record(def_id, encode_info, def_id);
17141714
}

src/librustc_typeck/collect.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
129129
hir::GenericParamKind::Type {
130130
default: Some(_), ..
131131
} => {
132-
let def_id = self.tcx.hir().local_def_id(param.id);
132+
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
133133
self.tcx.type_of(def_id);
134134
}
135135
hir::GenericParamKind::Type { .. } => {}
136136
hir::GenericParamKind::Const { .. } => {
137-
let def_id = self.tcx.hir().local_def_id(param.id);
137+
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
138138
self.tcx.type_of(def_id);
139139
}
140140
}
@@ -322,9 +322,10 @@ fn type_param_predicates<'a, 'tcx>(
322322
};
323323

324324
let icx = ItemCtxt::new(tcx, item_def_id);
325+
let param_hir_id = tcx.hir().node_to_hir_id(param_id);
325326
Lrc::make_mut(&mut result)
326327
.predicates
327-
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
328+
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_hir_id, ty,
328329
OnlySelfBounds(true)));
329330
result
330331
}
@@ -337,15 +338,15 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
337338
fn type_parameter_bounds_in_generics(
338339
&self,
339340
ast_generics: &hir::Generics,
340-
param_id: ast::NodeId,
341+
param_id: hir::HirId,
341342
ty: Ty<'tcx>,
342343
only_self_bounds: OnlySelfBounds,
343344
) -> Vec<(ty::Predicate<'tcx>, Span)> {
344345
let from_ty_params = ast_generics
345346
.params
346347
.iter()
347348
.filter_map(|param| match param.kind {
348-
GenericParamKind::Type { .. } if param.id == param_id => Some(&param.bounds),
349+
GenericParamKind::Type { .. } if param.hir_id == param_id => Some(&param.bounds),
349350
_ => None,
350351
})
351352
.flat_map(|bounds| bounds.iter())
@@ -382,12 +383,12 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
382383
fn is_param<'a, 'tcx>(
383384
tcx: TyCtxt<'a, 'tcx, 'tcx>,
384385
ast_ty: &hir::Ty,
385-
param_id: ast::NodeId,
386+
param_id: hir::HirId,
386387
) -> bool {
387388
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node {
388389
match path.def {
389390
Def::SelfTy(Some(def_id), None) | Def::TyParam(def_id) => {
390-
def_id == tcx.hir().local_def_id(param_id)
391+
def_id == tcx.hir().local_def_id_from_hir_id(param_id)
391392
}
392393
_ => false,
393394
}
@@ -721,7 +722,7 @@ fn super_predicates_of<'a, 'tcx>(
721722
// as one of its "superpredicates".
722723
let is_trait_alias = tcx.is_trait_alias(trait_def_id);
723724
let superbounds2 = icx.type_parameter_bounds_in_generics(
724-
generics, item.id, self_param_ty, OnlySelfBounds(!is_trait_alias));
725+
generics, item.hir_id, self_param_ty, OnlySelfBounds(!is_trait_alias));
725726

726727
// Combine the two lists to form the complete set of superbounds:
727728
let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect();
@@ -987,7 +988,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
987988
.map(|(i, param)| ty::GenericParamDef {
988989
name: param.name.ident().as_interned_str(),
989990
index: own_start + i as u32,
990-
def_id: tcx.hir().local_def_id(param.id),
991+
def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id),
991992
pure_wrt_drop: param.pure_wrt_drop,
992993
kind: ty::GenericParamDefKind::Lifetime,
993994
}),
@@ -1018,9 +1019,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
10181019

10191020
if !allow_defaults && default.is_some() {
10201021
if !tcx.features().default_type_parameter_fallback {
1021-
tcx.lint_node(
1022+
tcx.lint_hir(
10221023
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
1023-
param.id,
1024+
param.hir_id,
10241025
param.span,
10251026
&format!(
10261027
"defaults for type parameters are only allowed in \
@@ -1033,7 +1034,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
10331034
let ty_param = ty::GenericParamDef {
10341035
index: type_start + i as u32,
10351036
name: param.name.ident().as_interned_str(),
1036-
def_id: tcx.hir().local_def_id(param.id),
1037+
def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id),
10371038
pure_wrt_drop: param.pure_wrt_drop,
10381039
kind: ty::GenericParamDefKind::Type {
10391040
has_default: default.is_some(),
@@ -1704,8 +1705,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
17041705
.iter()
17051706
.filter(move |param| match param.kind {
17061707
GenericParamKind::Lifetime { .. } => {
1707-
let hir_id = tcx.hir().node_to_hir_id(param.id);
1708-
!tcx.is_late_bound(hir_id)
1708+
!tcx.is_late_bound(param.hir_id)
17091709
}
17101710
_ => false,
17111711
})
@@ -1942,7 +1942,7 @@ fn explicit_predicates_of<'a, 'tcx>(
19421942
let mut index = parent_count + has_own_self as u32;
19431943
for param in early_bound_lifetimes_from_generics(tcx, ast_generics) {
19441944
let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
1945-
def_id: tcx.hir().local_def_id(param.id),
1945+
def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id),
19461946
index,
19471947
name: param.name.ident().as_interned_str(),
19481948
}));

src/librustdoc/clean/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,15 +1511,15 @@ impl Clean<GenericParamDef> for hir::GenericParam {
15111511
}
15121512
hir::GenericParamKind::Type { ref default, synthetic } => {
15131513
(self.name.ident().name.clean(cx), GenericParamDefKind::Type {
1514-
did: cx.tcx.hir().local_def_id(self.id),
1514+
did: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id),
15151515
bounds: self.bounds.clean(cx),
15161516
default: default.clean(cx),
15171517
synthetic: synthetic,
15181518
})
15191519
}
15201520
hir::GenericParamKind::Const { ref ty } => {
15211521
(self.name.ident().name.clean(cx), GenericParamDefKind::Const {
1522-
did: cx.tcx.hir().local_def_id(self.id),
1522+
did: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id),
15231523
ty: ty.clean(cx),
15241524
})
15251525
}
@@ -2597,15 +2597,16 @@ impl Clean<Type> for hir::Ty {
25972597
if let Some(lt) = lifetime.cloned() {
25982598
if !lt.is_elided() {
25992599
let lt_def_id =
2600-
cx.tcx.hir().local_def_id(param.id);
2600+
cx.tcx.hir().local_def_id_from_hir_id(param.hir_id);
26012601
lt_substs.insert(lt_def_id, lt.clean(cx));
26022602
}
26032603
}
26042604
indices.lifetimes += 1;
26052605
}
26062606
hir::GenericParamKind::Type { ref default, .. } => {
26072607
let ty_param_def =
2608-
Def::TyParam(cx.tcx.hir().local_def_id(param.id));
2608+
Def::TyParam(
2609+
cx.tcx.hir().local_def_id_from_hir_id(param.hir_id));
26092610
let mut j = 0;
26102611
let type_ = generic_args.args.iter().find_map(|arg| {
26112612
match arg {
@@ -2629,7 +2630,8 @@ impl Clean<Type> for hir::Ty {
26292630
}
26302631
hir::GenericParamKind::Const { .. } => {
26312632
let const_param_def =
2632-
Def::ConstParam(cx.tcx.hir().local_def_id(param.id));
2633+
Def::ConstParam(
2634+
cx.tcx.hir().local_def_id_from_hir_id(param.hir_id));
26332635
let mut j = 0;
26342636
let const_ = generic_args.args.iter().find_map(|arg| {
26352637
match arg {

0 commit comments

Comments
 (0)