Rename node_id to var_id and limit to the cases that are actually used

This commit is contained in:
Niko Matsakis 2015-09-07 14:10:25 -04:00
parent 5600c6282e
commit 1dd5ffa405
7 changed files with 17 additions and 20 deletions

View file

@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
rbml_w.tag(c::tag_table_upvar_capture_map, |rbml_w| {
rbml_w.id(id);
let var_id = freevar.def.node_id();
let var_id = freevar.def.var_id();
let upvar_id = ty::UpvarId {
var_id: var_id,
closure_expr_id: id

View file

@ -114,21 +114,18 @@ pub struct Export {
}
impl Def {
pub fn node_id(&self) -> ast::NodeId {
pub fn var_id(&self) -> ast::NodeId {
match *self {
DefLocal(id) |
DefUpvar(id, _, _) |
DefRegion(id) |
DefLabel(id) |
DefSelfTy(_, Some((_, id))) => {
DefUpvar(id, _, _) => {
id
}
DefFn(_, _) | DefMod(_) | DefForeignMod(_) | DefStatic(_, _) |
DefVariant(_, _, _) | DefTy(_, _) | DefAssociatedTy(_, _) |
DefTyParam(_, _, _, _) | DefUse(_) | DefStruct(_) | DefTrait(_) |
DefMethod(_) | DefConst(_) | DefAssociatedConst(_) |
DefSelfTy(Some(_), None) | DefPrimTy(_) | DefSelfTy(..) => {
DefFn(..) | DefMod(..) | DefForeignMod(..) | DefStatic(..) |
DefVariant(..) | DefTy(..) | DefAssociatedTy(..) |
DefTyParam(..) | DefUse(..) | DefStruct(..) | DefTrait(..) |
DefMethod(..) | DefConst(..) | DefAssociatedConst(..) |
DefPrimTy(..) | DefRegion(..) | DefLabel(..) | DefSelfTy(..) => {
panic!("attempted .def_id() on invalid {:?}", self)
}
}

View file

@ -1160,7 +1160,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
self.tcx().with_freevars(closure_expr.id, |freevars| {
for freevar in freevars {
let id_var = freevar.def.node_id();
let id_var = freevar.def.var_id();
let upvar_id = ty::UpvarId { var_id: id_var,
closure_expr_id: closure_expr.id };
let upvar_capture = self.typer.upvar_capture(upvar_id).unwrap();
@ -1192,7 +1192,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
-> mc::McResult<mc::cmt<'tcx>> {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
let var_id = upvar_def.node_id();
let var_id = upvar_def.var_id();
let var_ty = try!(self.typer.node_ty(var_id));
self.mc.cat_def(closure_id, closure_span, var_ty, upvar_def)
}

View file

@ -896,7 +896,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
let mut sep = " ";
try!(tcx.with_freevars(node_id, |freevars| {
for (freevar, upvar_ty) in freevars.iter().zip(&substs.upvar_tys) {
let node_id = freevar.def.node_id();
let node_id = freevar.def.var_id();
try!(write!(f,
"{}{}:{}",
sep,

View file

@ -817,7 +817,7 @@ fn capture_freevar<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>,
freevar: &ty::Freevar,
freevar_ty: Ty<'tcx>)
-> ExprRef<Cx<'a,'tcx>> {
let id_var = freevar.def.node_id();
let id_var = freevar.def.var_id();
let upvar_id = ty::UpvarId { var_id: id_var, closure_expr_id: closure_expr.id };
let upvar_capture = cx.tcx.upvar_capture(upvar_id).unwrap();
let temp_lifetime = cx.tcx.region_maps.temporary_scope(closure_expr.id);

View file

@ -68,7 +68,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
};
for (i, freevar) in freevars.iter().enumerate() {
let upvar_id = ty::UpvarId { var_id: freevar.def.node_id(),
let upvar_id = ty::UpvarId { var_id: freevar.def.var_id(),
closure_expr_id: bcx.fcx.id };
let upvar_capture = bcx.tcx().upvar_capture(upvar_id).unwrap();
let mut upvar_ptr = StructGEP(bcx, llenv, i);
@ -79,7 +79,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
true
}
};
let node_id = freevar.def.node_id();
let node_id = freevar.def.var_id();
bcx.fcx.llupvars.borrow_mut().insert(node_id, upvar_ptr);
if kind == ty::FnOnceClosureKind && !captured_by_ref {
@ -236,7 +236,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
for (i, freevar) in freevars.iter().enumerate() {
let datum = expr::trans_local_var(bcx, freevar.def);
let upvar_slot_dest = adt::trans_field_ptr(bcx, &*repr, dest_addr, 0, i);
let upvar_id = ty::UpvarId { var_id: freevar.def.node_id(),
let upvar_id = ty::UpvarId { var_id: freevar.def.var_id(),
closure_expr_id: id };
match tcx.upvar_capture(upvar_id).unwrap() {
ty::UpvarCapture::ByValue => {

View file

@ -126,7 +126,7 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
self.tcx().with_freevars(expr.id, |freevars| {
for freevar in freevars {
let var_node_id = freevar.def.node_id();
let var_node_id = freevar.def.var_id();
let upvar_id = ty::UpvarId { var_id: var_node_id,
closure_expr_id: expr.id };
debug!("seed upvar_id {:?}", upvar_id);
@ -235,7 +235,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
tcx.with_freevars(closure_id, |freevars| {
freevars.iter()
.map(|freevar| {
let freevar_node_id = freevar.def.node_id();
let freevar_node_id = freevar.def.var_id();
let freevar_ty = self.fcx.node_ty(freevar_node_id);
let upvar_id = ty::UpvarId {
var_id: freevar_node_id,