Skip to content

Commit f6da289

Browse files
authored
Rollup merge of rust-lang#58137 - ljedrz:cleanup_node_id_to_type, r=estebank
Cleanup: rename node_id_to_type(_opt) Renames `node_id_to_type(_opt)` to `hir_id_to_type(_opt)`; this makes it clear we are dealing with HIR nodes and their IDs here. In addition, a drive-by commit removing `ty::item_path::hir_path_str` (as requested by @eddyb).
2 parents 76b6bda + eb669b3 commit f6da289

File tree

24 files changed

+52
-61
lines changed

24 files changed

+52
-61
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
1616
}
1717

1818
impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> {
19-
fn node_matches_type(&mut self, node_id: HirId) -> bool {
19+
fn node_matches_type(&mut self, hir_id: HirId) -> bool {
2020
let ty_opt = self.infcx.in_progress_tables.and_then(|tables| {
21-
tables.borrow().node_id_to_type_opt(node_id)
21+
tables.borrow().node_type_opt(hir_id)
2222
});
2323
match ty_opt {
2424
Some(ty) => {

src/librustc/infer/error_reporting/nice_region_error/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
6464
// May return None; sometimes the tables are not yet populated.
6565
let ty_hir_id = fn_decl.inputs[index].hir_id;
6666
let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
67-
let ty = tables.node_id_to_type_opt(arg.hir_id)?;
67+
let ty = tables.node_type_opt(arg.hir_id)?;
6868
let mut found_anon_region = false;
6969
let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
7070
if *r == *anon_region {

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
112112

113113
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def,
114114
pats: &[source_map::Spanned<hir::FieldPat>]) {
115-
let variant = match self.tables.node_id_to_type(lhs.hir_id).sty {
115+
let variant = match self.tables.node_type(lhs.hir_id).sty {
116116
ty::Adt(adt, _) => adt.variant_of_def(def),
117117
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
118118
};

src/librustc/middle/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
165165
};
166166
if let Def::Fn(did) = def {
167167
if self.def_id_is_transmute(did) {
168-
let typ = self.tables.node_id_to_type(expr.hir_id);
168+
let typ = self.tables.node_type(expr.hir_id);
169169
let sig = typ.fn_sig(self.tcx);
170170
let from = sig.inputs().skip_binder()[0];
171171
let to = *sig.output().skip_binder();

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub enum Note {
174174
// which the value is stored.
175175
//
176176
// *WARNING* The field `cmt.type` is NOT necessarily the same as the
177-
// result of `node_id_to_type(cmt.id)`.
177+
// result of `node_type(cmt.id)`.
178178
//
179179
// (FIXME: rewrite the following comment given that `@x` managed
180180
// pointers have been obsolete for quite some time.)
@@ -497,7 +497,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
497497
hir_id: hir::HirId)
498498
-> McResult<Ty<'tcx>> {
499499
self.resolve_type_vars_or_error(hir_id,
500-
self.tables.node_id_to_type_opt(hir_id))
500+
self.tables.node_type_opt(hir_id))
501501
}
502502

503503
pub fn expr_ty(&self, expr: &hir::Expr) -> McResult<Ty<'tcx>> {

src/librustc/ty/context.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,14 @@ impl<'tcx> TypeckTables<'tcx> {
525525
}
526526
}
527527

528-
pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> {
529-
self.node_id_to_type_opt(id).unwrap_or_else(||
530-
bug!("node_id_to_type: no type for node `{}`",
531-
tls::with(|tcx| {
532-
let id = tcx.hir().hir_to_node_id(id);
533-
tcx.hir().node_to_string(id)
534-
}))
528+
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
529+
self.node_type_opt(id).unwrap_or_else(||
530+
bug!("node_type: no type for node `{}`",
531+
tls::with(|tcx| tcx.hir().hir_to_string(id)))
535532
)
536533
}
537534

538-
pub fn node_id_to_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
535+
pub fn node_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
539536
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
540537
self.node_types.get(&id.local_id).cloned()
541538
}
@@ -560,11 +557,11 @@ impl<'tcx> TypeckTables<'tcx> {
560557
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
561558
// doesn't provide type parameter substitutions.
562559
pub fn pat_ty(&self, pat: &hir::Pat) -> Ty<'tcx> {
563-
self.node_id_to_type(pat.hir_id)
560+
self.node_type(pat.hir_id)
564561
}
565562

566563
pub fn pat_ty_opt(&self, pat: &hir::Pat) -> Option<Ty<'tcx>> {
567-
self.node_id_to_type_opt(pat.hir_id)
564+
self.node_type_opt(pat.hir_id)
568565
}
569566

570567
// Returns the type of an expression as a monotype.
@@ -578,11 +575,11 @@ impl<'tcx> TypeckTables<'tcx> {
578575
// ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize"
579576
// instead of "fn(ty) -> T with T = isize".
580577
pub fn expr_ty(&self, expr: &hir::Expr) -> Ty<'tcx> {
581-
self.node_id_to_type(expr.hir_id)
578+
self.node_type(expr.hir_id)
582579
}
583580

584581
pub fn expr_ty_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
585-
self.node_id_to_type_opt(expr.hir_id)
582+
self.node_type_opt(expr.hir_id)
586583
}
587584

588585
pub fn adjustments(&self) -> LocalTableInContext<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {

src/librustc/ty/item_path.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::hir;
21
use crate::hir::map::DefPathData;
32
use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
43
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
@@ -77,11 +76,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
7776
self.item_path_str(self.hir().local_def_id(id))
7877
}
7978

80-
// FIXME(@ljedrz): replace the NodeId variant
81-
pub fn hir_path_str(self, id: hir::HirId) -> String {
82-
self.item_path_str(self.hir().local_def_id_from_hir_id(id))
83-
}
84-
8579
/// Returns a string identifying this def-id. This string is
8680
/// suitable for user output. It always begins with a crate identifier.
8781
pub fn absolute_item_path_str(self, def_id: DefId) -> String {

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
149149
fn decl_without_init(&mut self, id: ast::NodeId, _span: Span) {
150150
let ty = self.bccx
151151
.tables
152-
.node_id_to_type(self.bccx.tcx.hir().node_to_hir_id(id));
152+
.node_type(self.bccx.tcx.hir().node_to_hir_id(id));
153153
gather_moves::gather_decl(self.bccx, &self.move_data, id, ty);
154154
}
155155
}

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
158158
}
159159

160160
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
161-
let ty = cx.tables.node_id_to_type(e.hir_id);
161+
let ty = cx.tables.node_type(e.hir_id);
162162
self.check_heap_type(cx, e.span, ty);
163163
}
164164
}
@@ -1002,7 +1002,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
10021002
if !def_id_is_transmute(cx, did) {
10031003
return None;
10041004
}
1005-
let sig = cx.tables.node_id_to_type(expr.hir_id).fn_sig(cx.tcx);
1005+
let sig = cx.tables.node_type(expr.hir_id).fn_sig(cx.tcx);
10061006
let from = sig.inputs().skip_binder()[0];
10071007
let to = *sig.output().skip_binder();
10081008
return Some((&from.sty, &to.sty));

src/librustc_lint/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
8585
}
8686
}
8787
hir::ExprKind::Lit(ref lit) => {
88-
match cx.tables.node_id_to_type(e.hir_id).sty {
88+
match cx.tables.node_type(e.hir_id).sty {
8989
ty::Int(t) => {
9090
match lit.node {
9191
ast::LitKind::Int(v, ast::LitIntType::Signed(_)) |
@@ -257,7 +257,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
257257
// Normalize the binop so that the literal is always on the RHS in
258258
// the comparison
259259
let norm_binop = if swap { rev_binop(binop) } else { binop };
260-
match cx.tables.node_id_to_type(expr.hir_id).sty {
260+
match cx.tables.node_type(expr.hir_id).sty {
261261
ty::Int(int_ty) => {
262262
let (min, max) = int_ty_range(int_ty);
263263
let lit_val: i128 = match lit.node {
@@ -400,7 +400,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
400400
repr_str, val, t, actually, t
401401
));
402402
if let Some(sugg_ty) =
403-
get_type_suggestion(&cx.tables.node_id_to_type(expr.hir_id).sty, val, negative)
403+
get_type_suggestion(&cx.tables.node_type(expr.hir_id).sty, val, negative)
404404
{
405405
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
406406
let (sans_suffix, _) = repr_str.split_at(pos);

0 commit comments

Comments
 (0)