Skip to content

Commit 6da9129

Browse files
committed
typeck: partially HirIdify
1 parent 8bf7fda commit 6da9129

File tree

12 files changed

+49
-47
lines changed

12 files changed

+49
-47
lines changed

src/librustc/hir/map/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,9 @@ impl<'hir> Map<'hir> {
931931
}
932932
}
933933

934-
pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
934+
pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
935+
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
936+
935937
match self.find(id) {
936938
Some(Node::Item(i)) => {
937939
match i.node {
@@ -946,7 +948,9 @@ impl<'hir> Map<'hir> {
946948
}
947949
}
948950

949-
pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
951+
pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
952+
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
953+
950954
match self.find(id) {
951955
Some(Node::Variant(variant)) => variant,
952956
_ => bug!("expected variant, found {}", self.node_to_string(id)),

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
673673
let def_id = field.did;
674674
debug!("IsolatedEncoder::encode_field({:?})", def_id);
675675

676-
let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap();
676+
let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap();
677677
let variant_data = tcx.hir().expect_variant_data(variant_id);
678678

679679
Entry {

src/librustc_typeck/astconv.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
111111
{
112112
let tcx = self.tcx();
113113
let lifetime_name = |def_id| {
114-
tcx.hir().name(tcx.hir().as_local_node_id(def_id).unwrap()).as_interned_str()
114+
tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str()
115115
};
116116

117117
let r = match tcx.named_region(lifetime.hir_id) {
@@ -1682,12 +1682,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
16821682
assert_eq!(opt_self_ty, None);
16831683
self.prohibit_generics(&path.segments);
16841684

1685-
let node_id = tcx.hir().as_local_node_id(did).unwrap();
1686-
let item_id = tcx.hir().get_parent_node(node_id);
1687-
let item_def_id = tcx.hir().local_def_id(item_id);
1685+
let hir_id = tcx.hir().as_local_hir_id(did).unwrap();
1686+
let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
1687+
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
16881688
let generics = tcx.generics_of(item_def_id);
1689-
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)];
1690-
tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str())
1689+
let index = generics.param_def_id_to_index[
1690+
&tcx.hir().local_def_id_from_hir_id(hir_id)];
1691+
tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str())
16911692
}
16921693
Def::SelfTy(_, Some(def_id)) => {
16931694
// `Self` in impl (we know the concrete type).

src/librustc_typeck/check/compare_method.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
736736
in impl_m_type_params.zip(trait_m_type_params)
737737
{
738738
if impl_synthetic != trait_synthetic {
739-
let impl_node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap();
740-
let impl_span = tcx.hir().span(impl_node_id);
739+
let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap();
740+
let impl_span = tcx.hir().span_by_hir_id(impl_hir_id);
741741
let trait_span = tcx.def_span(trait_def_id);
742742
let mut err = struct_span_err!(tcx.sess,
743743
impl_span,
@@ -840,7 +840,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
840840
match param.kind {
841841
GenericParamKind::Lifetime { .. } => None,
842842
GenericParamKind::Type { .. } => {
843-
if param.id == impl_node_id {
843+
if param.hir_id == impl_hir_id {
844844
Some(&param.bounds)
845845
} else {
846846
None

src/librustc_typeck/check/dropck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
184184
// absent. So we report an error that the Drop impl injected a
185185
// predicate that is not present on the struct definition.
186186

187-
let self_type_node_id = tcx.hir().as_local_node_id(self_type_did).unwrap();
187+
let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap();
188188

189189
let drop_impl_span = tcx.def_span(drop_impl_did);
190190

@@ -216,7 +216,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
216216
// repeated `contains` calls.
217217

218218
if !assumptions_in_impl_context.contains(&predicate) {
219-
let item_span = tcx.hir().span(self_type_node_id);
219+
let item_span = tcx.hir().span_by_hir_id(self_type_hir_id);
220220
struct_span_err!(
221221
tcx.sess,
222222
drop_impl_span,

src/librustc_typeck/check/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1883,14 +1883,14 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
18831883
// Check for duplicate discriminant values
18841884
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
18851885
let variant_did = def.variants[VariantIdx::new(i)].did;
1886-
let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap();
1887-
let variant_i = tcx.hir().expect_variant(variant_i_node_id);
1886+
let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap();
1887+
let variant_i = tcx.hir().expect_variant(variant_i_hir_id);
18881888
let i_span = match variant_i.node.disr_expr {
1889-
Some(ref expr) => tcx.hir().span(expr.id),
1890-
None => tcx.hir().span(variant_i_node_id)
1889+
Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
1890+
None => tcx.hir().span_by_hir_id(variant_i_hir_id)
18911891
};
18921892
let span = match v.node.disr_expr {
1893-
Some(ref expr) => tcx.hir().span(expr.id),
1893+
Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
18941894
None => v.span
18951895
};
18961896
struct_span_err!(tcx.sess, span, E0081,
@@ -5703,8 +5703,8 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
57035703
});
57045704
for (&used, param) in types_used.iter().zip(types) {
57055705
if !used {
5706-
let id = tcx.hir().as_local_node_id(param.def_id).unwrap();
5707-
let span = tcx.hir().span(id);
5706+
let id = tcx.hir().as_local_hir_id(param.def_id).unwrap();
5707+
let span = tcx.hir().span_by_hir_id(id);
57085708
struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name)
57095709
.span_label(span, "unused type parameter")
57105710
.emit();

src/librustc_typeck/check/upvar.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,5 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> {
650650
}
651651

652652
fn var_name(tcx: TyCtxt, var_hir_id: hir::HirId) -> ast::Name {
653-
let var_node_id = tcx.hir().hir_to_node_id(var_hir_id);
654-
tcx.hir().name(var_node_id)
653+
tcx.hir().name_by_hir_id(var_hir_id)
655654
}

src/librustc_typeck/check/wfcheck.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
6262
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
6363
/// the types first.
6464
pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
65-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
66-
let item = tcx.hir().expect_item(node_id);
65+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
66+
let item = tcx.hir().expect_item_by_hir_id(hir_id);
6767

68-
debug!("check_item_well_formed(it.id={}, it.name={})",
69-
item.id,
68+
debug!("check_item_well_formed(it.hir_id={:?}, it.name={})",
69+
item.hir_id,
7070
tcx.item_path_str(def_id));
7171

7272
match item.node {
@@ -88,7 +88,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
8888
// won't be allowed unless there's an *explicit* implementation of `Send`
8989
// for `T`
9090
hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => {
91-
let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id))
91+
let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id))
9292
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
9393
if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) {
9494
tcx.sess.span_err(item.span, "impls of auto traits cannot be default");

src/librustc_typeck/check/writeback.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
407407
if let ty::UserType::TypeOf(_, user_substs) = c_ty.value {
408408
if self.rustc_dump_user_substs {
409409
// This is a unit-testing mechanism.
410-
let node_id = self.tcx().hir().hir_to_node_id(hir_id);
411-
let span = self.tcx().hir().span(node_id);
410+
let span = self.tcx().hir().span_by_hir_id(hir_id);
412411
// We need to buffer the errors in order to guarantee a consistent
413412
// order when emitting them.
414413
let err = self.tcx().sess.struct_span_err(
@@ -739,15 +738,14 @@ impl Locatable for ast::NodeId {
739738

740739
impl Locatable for DefIndex {
741740
fn to_span(&self, tcx: &TyCtxt) -> Span {
742-
let node_id = tcx.hir().def_index_to_node_id(*self);
743-
tcx.hir().span(node_id)
741+
let hir_id = tcx.hir().def_index_to_hir_id(*self);
742+
tcx.hir().span_by_hir_id(hir_id)
744743
}
745744
}
746745

747746
impl Locatable for hir::HirId {
748747
fn to_span(&self, tcx: &TyCtxt) -> Span {
749-
let node_id = tcx.hir().hir_to_node_id(*self);
750-
tcx.hir().span(node_id)
748+
tcx.hir().span_by_hir_id(*self)
751749
}
752750
}
753751

src/librustc_typeck/coherence/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
7676
fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId) {
7777
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
7878

79-
let impl_node_id = if let Some(n) = tcx.hir().as_local_node_id(impl_did) {
79+
let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) {
8080
n
8181
} else {
8282
debug!("visit_implementation_of_copy(): impl not in this crate");
@@ -87,7 +87,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
8787
debug!("visit_implementation_of_copy: self_type={:?} (bound)",
8888
self_type);
8989

90-
let span = tcx.hir().span(impl_node_id);
90+
let span = tcx.hir().span_by_hir_id(impl_hir_id);
9191
let param_env = tcx.param_env(impl_did);
9292
assert!(!self_type.has_escaping_bound_vars());
9393

@@ -97,7 +97,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
9797
match param_env.can_type_implement_copy(tcx, self_type) {
9898
Ok(()) => {}
9999
Err(CopyImplementationError::InfrigingFields(fields)) => {
100-
let item = tcx.hir().expect_item(impl_node_id);
100+
let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
101101
let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node {
102102
tr.path.span
103103
} else {
@@ -114,7 +114,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
114114
err.emit()
115115
}
116116
Err(CopyImplementationError::NotAnAdt) => {
117-
let item = tcx.hir().expect_item(impl_node_id);
117+
let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
118118
let span = if let ItemKind::Impl(.., ref ty, _) = item.node {
119119
ty.span
120120
} else {

src/librustc_typeck/collect.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ fn super_predicates_of<'a, 'tcx>(
737737
}
738738

739739
fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef {
740-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
741-
let item = tcx.hir().expect_item(node_id);
740+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
741+
let item = tcx.hir().expect_item_by_hir_id(hir_id);
742742

743743
let (is_auto, unsafety) = match item.node {
744744
hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety),
@@ -1509,8 +1509,8 @@ fn impl_trait_ref<'a, 'tcx>(
15091509
) -> Option<ty::TraitRef<'tcx>> {
15101510
let icx = ItemCtxt::new(tcx, def_id);
15111511

1512-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
1513-
match tcx.hir().expect_item(node_id).node {
1512+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
1513+
match tcx.hir().expect_item_by_hir_id(hir_id).node {
15141514
hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
15151515
opt_trait_ref.as_ref().map(|ast_trait_ref| {
15161516
let selfty = tcx.type_of(def_id);
@@ -1522,8 +1522,8 @@ fn impl_trait_ref<'a, 'tcx>(
15221522
}
15231523

15241524
fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> hir::ImplPolarity {
1525-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
1526-
match tcx.hir().expect_item(node_id).node {
1525+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
1526+
match tcx.hir().expect_item_by_hir_id(hir_id).node {
15271527
hir::ItemKind::Impl(_, polarity, ..) => polarity,
15281528
ref item => bug!("impl_polarity: {:?} not an impl", item),
15291529
}

src/librustc_typeck/variance/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum)
4646

4747
fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
4848
-> Lrc<Vec<ty::Variance>> {
49-
let id = tcx.hir().as_local_node_id(item_def_id).expect("expected local def-id");
49+
let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id");
5050
let unsupported = || {
5151
// Variance not relevant.
52-
span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item")
52+
span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item")
5353
};
54-
match tcx.hir().get(id) {
54+
match tcx.hir().get_by_hir_id(id) {
5555
Node::Item(item) => match item.node {
5656
hir::ItemKind::Enum(..) |
5757
hir::ItemKind::Struct(..) |

0 commit comments

Comments
 (0)