Skip to content

Commit

Permalink
cleanup: rename node_id_to_type(_opt)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Feb 9, 2019
1 parent d329d46 commit 3a1a704
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/need_type_info.rs
Expand Up @@ -16,9 +16,9 @@ struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
}

impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> {
fn node_matches_type(&mut self, node_id: HirId) -> bool {
fn node_matches_type(&mut self, hir_id: HirId) -> bool {
let ty_opt = self.infcx.in_progress_tables.and_then(|tables| {
tables.borrow().node_id_to_type_opt(node_id)
tables.borrow().node_type_opt(hir_id)
});
match ty_opt {
Some(ty) => {
Expand Down
Expand Up @@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
// May return None; sometimes the tables are not yet populated.
let ty_hir_id = fn_decl.inputs[index].hir_id;
let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
let ty = tables.node_id_to_type_opt(arg.hir_id)?;
let ty = tables.node_type_opt(arg.hir_id)?;
let mut found_anon_region = false;
let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
if *r == *anon_region {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {

fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def,
pats: &[source_map::Spanned<hir::FieldPat>]) {
let variant = match self.tables.node_id_to_type(lhs.hir_id).sty {
let variant = match self.tables.node_type(lhs.hir_id).sty {
ty::Adt(adt, _) => adt.variant_of_def(def),
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/intrinsicck.rs
Expand Up @@ -165,7 +165,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
};
if let Def::Fn(did) = def {
if self.def_id_is_transmute(did) {
let typ = self.tables.node_id_to_type(expr.hir_id);
let typ = self.tables.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);
let from = sig.inputs().skip_binder()[0];
let to = *sig.output().skip_binder();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -174,7 +174,7 @@ pub enum Note {
// which the value is stored.
//
// *WARNING* The field `cmt.type` is NOT necessarily the same as the
// result of `node_id_to_type(cmt.id)`.
// result of `node_type(cmt.id)`.
//
// (FIXME: rewrite the following comment given that `@x` managed
// pointers have been obsolete for quite some time.)
Expand Down Expand Up @@ -497,7 +497,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
hir_id: hir::HirId)
-> McResult<Ty<'tcx>> {
self.resolve_type_vars_or_error(hir_id,
self.tables.node_id_to_type_opt(hir_id))
self.tables.node_type_opt(hir_id))
}

pub fn expr_ty(&self, expr: &hir::Expr) -> McResult<Ty<'tcx>> {
Expand Down
21 changes: 9 additions & 12 deletions src/librustc/ty/context.rs
Expand Up @@ -525,17 +525,14 @@ impl<'tcx> TypeckTables<'tcx> {
}
}

pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> {
self.node_id_to_type_opt(id).unwrap_or_else(||
bug!("node_id_to_type: no type for node `{}`",
tls::with(|tcx| {
let id = tcx.hir().hir_to_node_id(id);
tcx.hir().node_to_string(id)
}))
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
self.node_type_opt(id).unwrap_or_else(||
bug!("node_type: no type for node `{}`",
tls::with(|tcx| tcx.hir().hir_to_string(id)))
)
}

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

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

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

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

pub fn adjustments(&self) -> LocalTableInContext<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/item_path.rs
@@ -1,4 +1,3 @@
use crate::hir;
use crate::hir::map::DefPathData;
use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/gather_loans/mod.rs
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
fn decl_without_init(&mut self, id: ast::NodeId, _span: Span) {
let ty = self.bccx
.tables
.node_id_to_type(self.bccx.tcx.hir().node_to_hir_id(id));
.node_type(self.bccx.tcx.hir().node_to_hir_id(id));
gather_moves::gather_decl(self.bccx, &self.move_data, id, ty);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Expand Up @@ -155,7 +155,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
}

fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
let ty = cx.tables.node_id_to_type(e.hir_id);
let ty = cx.tables.node_type(e.hir_id);
self.check_heap_type(cx, e.span, ty);
}
}
Expand Down Expand Up @@ -1000,7 +1000,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
if !def_id_is_transmute(cx, did) {
return None;
}
let sig = cx.tables.node_id_to_type(expr.hir_id).fn_sig(cx.tcx);
let sig = cx.tables.node_type(expr.hir_id).fn_sig(cx.tcx);
let from = sig.inputs().skip_binder()[0];
let to = *sig.output().skip_binder();
return Some((&from.sty, &to.sty));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_lint/types.rs
Expand Up @@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
}
}
hir::ExprKind::Lit(ref lit) => {
match cx.tables.node_id_to_type(e.hir_id).sty {
match cx.tables.node_type(e.hir_id).sty {
ty::Int(t) => {
match lit.node {
ast::LitKind::Int(v, ast::LitIntType::Signed(_)) |
Expand Down Expand Up @@ -257,7 +257,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
// Normalize the binop so that the literal is always on the RHS in
// the comparison
let norm_binop = if swap { rev_binop(binop) } else { binop };
match cx.tables.node_id_to_type(expr.hir_id).sty {
match cx.tables.node_type(expr.hir_id).sty {
ty::Int(int_ty) => {
let (min, max) = int_ty_range(int_ty);
let lit_val: i128 = match lit.node {
Expand Down Expand Up @@ -400,7 +400,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
repr_str, val, t, actually, t
));
if let Some(sugg_ty) =
get_type_suggestion(&cx.tables.node_id_to_type(expr.hir_id).sty, val, negative)
get_type_suggestion(&cx.tables.node_type(expr.hir_id).sty, val, negative)
{
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
let (sans_suffix, _) = repr_str.split_at(pos);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Expand Up @@ -1338,7 +1338,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let tables = self.tcx.typeck_tables_of(def_id);
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
let kind = match tables.node_id_to_type(hir_id).sty {
let kind = match tables.node_type(hir_id).sty {
ty::Generator(def_id, ..) => {
let layout = self.tcx.generator_layout(def_id);
let data = GeneratorData {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/error_reporting.rs
Expand Up @@ -1178,7 +1178,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let escapes_from = if tcx.is_closure(self.mir_def_id) {
let tables = tcx.typeck_tables_of(self.mir_def_id);
let mir_hir_id = tcx.hir().def_index_to_hir_id(self.mir_def_id.index);
match tables.node_id_to_type(mir_hir_id).sty {
match tables.node_type(mir_hir_id).sty {
ty::Closure(..) => "closure",
ty::Generator(..) => "generator",
_ => bug!("Closure body doesn't have a closure or generator type"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/universal_regions.rs
Expand Up @@ -482,7 +482,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
tcx.type_of(closure_base_def_id)
} else {
let tables = tcx.typeck_tables_of(self.mir_def_id);
tables.node_id_to_type(self.mir_hir_id)
tables.node_type(self.mir_hir_id)
};

debug!("defining_ty (pre-replacement): {:?}", defining_ty);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -92,7 +92,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
Some(ArgInfo(liberated_closure_env_ty(tcx, id, body_id), None, None, None))
}
ty::Generator(..) => {
let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id);
let gen_ty = tcx.body_tables(body_id).node_type(fn_hir_id);
Some(ArgInfo(gen_ty, None, None, None))
}
_ => None,
Expand Down Expand Up @@ -263,7 +263,7 @@ fn liberated_closure_env_ty<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
body_id: hir::BodyId)
-> Ty<'tcx> {
let closure_expr_hir_id = tcx.hir().node_to_hir_id(closure_expr_id);
let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_hir_id);
let closure_ty = tcx.body_tables(body_id).node_type(closure_expr_hir_id);

let (closure_def_id, closure_substs) = match closure_ty.sty {
ty::Closure(closure_def_id, closure_substs) => (closure_def_id, closure_substs),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/block.rs
Expand Up @@ -115,7 +115,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
pub fn to_expr_ref<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
block: &'tcx hir::Block)
-> ExprRef<'tcx> {
let block_ty = cx.tables().node_id_to_type(block.hir_id);
let block_ty = cx.tables().node_type(block.hir_id);
let temp_lifetime = cx.region_scope_tree.temporary_scope(block.hir_id.local_id);
let expr = Expr {
ty: block_ty,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -304,7 +304,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}
} else {
ExprKind::Call {
ty: cx.tables().node_id_to_type(fun.hir_id),
ty: cx.tables().node_type(fun.hir_id),
fun: fun.to_ref(),
args: args.to_ref(),
from_hir_call: true,
Expand Down Expand Up @@ -677,7 +677,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
let def = cx.tables().qpath_def(qpath, source.hir_id);
cx
.tables()
.node_id_to_type(source.hir_id)
.node_type(source.hir_id)
.ty_adt_def()
.and_then(|adt_def| {
match def {
Expand Down Expand Up @@ -919,7 +919,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
debug!("convert_path_expr: user_ty={:?}", user_ty);
ExprKind::Literal {
literal: cx.tcx.mk_lazy_const(ty::LazyConst::Evaluated(ty::Const::zero_sized(
cx.tables().node_id_to_type(expr.hir_id),
cx.tables().node_type(expr.hir_id),
))),
user_ty,
}
Expand All @@ -940,7 +940,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
let user_provided_types = cx.tables.user_provided_types();
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
match cx.tables().node_id_to_type(expr.hir_id).sty {
match cx.tables().node_type(expr.hir_id).sty {
// A unit struct/variant which is used as a value.
// We return a completely different ExprKind here to account for this special case.
ty::Adt(adt_def, substs) => {
Expand Down Expand Up @@ -980,11 +980,11 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
index,
closure_expr_id);
let var_hir_id = cx.tcx.hir().node_to_hir_id(var_id);
let var_ty = cx.tables().node_id_to_type(var_hir_id);
let var_ty = cx.tables().node_type(var_hir_id);

// FIXME free regions in closures are not right
let closure_ty = cx.tables()
.node_id_to_type(cx.tcx.hir().node_to_hir_id(closure_expr_id));
.node_type(cx.tcx.hir().node_to_hir_id(closure_expr_id));

// FIXME we're just hard-coding the idea that the
// signature will be &self or &mut self and hence will
Expand Down Expand Up @@ -1188,7 +1188,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
};
let upvar_capture = cx.tables().upvar_capture(upvar_id);
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
let var_ty = cx.tables().node_id_to_type(var_hir_id);
let var_ty = cx.tables().node_type(var_hir_id);
let captured_var = Expr {
temp_lifetime,
ty: var_ty,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/pattern/check_match.rs
Expand Up @@ -202,7 +202,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {

// Then, if the match has no arms, check whether the scrutinee
// is uninhabited.
let pat_ty = self.tables.node_id_to_type(scrut.hir_id);
let pat_ty = self.tables.node_type(scrut.hir_id);
let module = self.tcx.hir().get_module_parent(scrut.id);
if inlined_arms.is_empty() {
let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
.flat_map(|arm| &arm.0)
.map(|pat| smallvec![pat.0])
.collect();
let scrut_ty = self.tables.node_id_to_type(scrut.hir_id);
let scrut_ty = self.tables.node_type(scrut.hir_id);
check_exhaustive(cx, scrut_ty, scrut.span, &matrix);
})
}
Expand Down Expand Up @@ -507,7 +507,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor<'_, '_>,
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
match bm {
ty::BindByValue(..) => {
let pat_ty = cx.tables.node_id_to_type(p.hir_id);
let pat_ty = cx.tables.node_type(p.hir_id);
if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) {
check_move(p, sub.as_ref().map(|p| &**p), span_vec);
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/pattern/mod.rs
Expand Up @@ -406,7 +406,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
}

fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat) -> Pattern<'tcx> {
let mut ty = self.tables.node_id_to_type(pat.hir_id);
let mut ty = self.tables.node_type(pat.hir_id);

let kind = match pat.node {
PatKind::Wild => PatternKind::Wild,
Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
}

PatKind::Binding(_, id, _, ident, ref sub) => {
let var_ty = self.tables.node_id_to_type(pat.hir_id);
let var_ty = self.tables.node_type(pat.hir_id);
if let ty::Error = var_ty.sty {
// Avoid ICE
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
Expand Down Expand Up @@ -773,7 +773,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
id: hir::HirId,
span: Span)
-> Pattern<'tcx> {
let ty = self.tables.node_id_to_type(id);
let ty = self.tables.node_type(id);
let def = self.tables.qpath_def(qpath, id);
let is_associated_const = match def {
Def::AssociatedConst(_) => true,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/util.rs
Expand Up @@ -16,7 +16,7 @@ crate trait UserAnnotatedTyHelpers<'gcx: 'tcx, 'tcx> {
let user_provided_types = self.tables().user_provided_types();
let mut user_ty = *user_provided_types.get(hir_id)?;
debug!("user_subts_applied_to_ty_of_hir_id: user_ty={:?}", user_ty);
match &self.tables().node_id_to_type(hir_id).sty {
match &self.tables().node_type(hir_id).sty {
ty::Adt(adt_def, ..) => {
if let UserType::TypeOf(ref mut did, _) = &mut user_ty.value {
*did = adt_def.did;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/rvalue_promotion.rs
Expand Up @@ -244,7 +244,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
}

fn check_expr(&mut self, ex: &'tcx hir::Expr) -> Promotability {
let node_ty = self.tables.node_id_to_type(ex.hir_id);
let node_ty = self.tables.node_type(ex.hir_id);
let mut outer = check_expr_kind(self, ex, node_ty);
outer &= check_adjustments(self, ex);

Expand Down Expand Up @@ -306,7 +306,7 @@ fn check_expr_kind<'a, 'tcx>(
if v.tables.is_method_call(e) {
return NotPromotable;
}
match v.tables.node_id_to_type(lhs.hir_id).sty {
match v.tables.node_type(lhs.hir_id).sty {
ty::RawPtr(_) | ty::FnPtr(..) => {
assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne ||
op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt ||
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -932,7 +932,7 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
// Take node-id of an expression or pattern and check its type for privacy.
fn check_expr_pat_type(&mut self, id: hir::HirId, span: Span) -> bool {
self.span = span;
if self.visit(self.tables.node_id_to_type(id)) || self.visit(self.tables.node_substs(id)) {
if self.visit(self.tables.node_type(id)) || self.visit(self.tables.node_substs(id)) {
return true;
}
if let Some(adjustments) = self.tables.adjustments().get(id) {
Expand Down Expand Up @@ -979,7 +979,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
self.span = hir_ty.span;
if self.in_body {
// Types in bodies.
if self.visit(self.tables.node_id_to_type(hir_ty.hir_id)) {
if self.visit(self.tables.node_type(hir_ty.hir_id)) {
return;
}
} else {
Expand Down

0 comments on commit 3a1a704

Please sign in to comment.