rustc: remove BindingMode from DefLocal.

This commit is contained in:
Eduard Burtescu 2014-09-17 18:17:09 +03:00
parent 1813b8cf55
commit 6543c5b9a4
11 changed files with 46 additions and 57 deletions

@ -954,7 +954,7 @@ impl LintPass for NonSnakeCase {
match &p.node {
&ast::PatIdent(_, ref path1, _) => {
match cx.tcx.def_map.borrow().find(&p.id) {
Some(&def::DefLocal(_, _)) => {
Some(&def::DefLocal(_)) => {
self.check_snake_case(cx, "variable", path1.node, p.span);
}
_ => {}

@ -462,7 +462,7 @@ impl tr for def::Def {
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) }
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
def::DefLocal(nid, b) => { def::DefLocal(dcx.tr_id(nid), b) }
def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) }
def::DefVariant(e_did, v_did, is_s) => {
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
},

@ -22,7 +22,7 @@ pub enum Def {
DefMod(ast::DefId),
DefForeignMod(ast::DefId),
DefStatic(ast::DefId, bool /* is_mutbl */),
DefLocal(ast::NodeId, ast::BindingMode),
DefLocal(ast::NodeId),
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
DefTy(ast::DefId, bool /* is_enum */),
DefAssociatedTy(ast::DefId),
@ -66,7 +66,7 @@ impl Def {
DefMethod(id, _) => {
id
}
DefLocal(id, _) |
DefLocal(id) |
DefSelfTy(id) |
DefUpvar(id, _, _, _) |
DefRegion(id) |

@ -462,7 +462,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
freevars::with_freevars(ir.tcx, expr.id, |freevars| {
for fv in freevars.iter() {
match fv.def {
DefLocal(rv, _) => {
DefLocal(rv) => {
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
call_caps.push(CaptureInfo {ln: fv_ln,
var_nid: rv});
@ -1288,7 +1288,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode {
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
DefLocal(nid, _) => {
DefLocal(nid) => {
let ln = self.live_node(expr.id, expr.span);
if acc != 0u {
self.init_from_succ(ln, succ);
@ -1527,7 +1527,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match expr.node {
ExprPath(_) => {
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
DefLocal(nid, _) => {
DefLocal(nid) => {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually
// mutable, then check for a reassignment to flag the mutability

@ -312,26 +312,19 @@ impl MutabilityCategory {
}
}
fn from_def(def: &def::Def) -> MutabilityCategory {
match *def {
def::DefFn(..) | def::DefStaticMethod(..) | def::DefSelfTy(..) |
def::DefMod(..) | def::DefForeignMod(..) | def::DefVariant(..) |
def::DefTy(..) | def::DefTrait(..) | def::DefPrimTy(..) |
def::DefTyParam(..) | def::DefUse(..) | def::DefStruct(..) |
def::DefTyParamBinder(..) | def::DefRegion(..) | def::DefLabel(..) |
def::DefMethod(..) | def::DefAssociatedTy(..) => {
fail!("no MutabilityCategory for def: {}", *def)
}
def::DefStatic(_, false) => McImmutable,
def::DefStatic(_, true) => McDeclared,
def::DefLocal(_, binding_mode) => match binding_mode {
ast::BindByValue(ast::MutMutable) => McDeclared,
_ => McImmutable
fn from_local(tcx: &ty::ctxt, id: ast::NodeId) -> MutabilityCategory {
match tcx.map.get(id) {
ast_map::NodeLocal(p) | ast_map::NodeArg(p) => match p.node {
ast::PatIdent(bind_mode, _, _) => {
if bind_mode == ast::BindByValue(ast::MutMutable) {
McDeclared
} else {
McImmutable
}
}
_ => tcx.sess.span_bug(p.span, "expected identifier pattern")
},
def::DefUpvar(_, def, _, _) => MutabilityCategory::from_def(&*def)
_ => tcx.sess.span_bug(tcx.map.span(id), "expected identifier pattern")
}
}
@ -544,12 +537,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}))
}
def::DefStatic(_, _) => {
def::DefStatic(_, mutbl) => {
Ok(Rc::new(cmt_ {
id:id,
span:span,
cat:cat_static_item,
mutbl: MutabilityCategory::from_def(&def),
mutbl: if mutbl { McDeclared } else { McImmutable},
ty:expr_ty
}))
}
@ -582,7 +575,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
onceness: closure_ty.onceness,
capturing_proc: fn_node_id,
}),
mutbl: MutabilityCategory::from_def(&def),
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
ty:expr_ty
}))
}
@ -605,7 +598,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
onceness: onceness,
capturing_proc: fn_node_id,
}),
mutbl: MutabilityCategory::from_def(&def),
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
ty: expr_ty
}))
}
@ -619,12 +612,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}
}
def::DefLocal(vid, _) => {
def::DefLocal(vid) => {
Ok(Rc::new(cmt_ {
id: id,
span: span,
cat: cat_local(vid),
mutbl: MutabilityCategory::from_def(&def),
mutbl: MutabilityCategory::from_local(self.tcx(), vid),
ty: expr_ty
}))
}

@ -4940,7 +4940,7 @@ impl<'a> Resolver<'a> {
debug!("(resolving pattern) binding `{}`",
token::get_name(renamed));
let def = DefLocal(pattern.id, binding_mode);
let def = DefLocal(pattern.id);
// Record the definition so that later passes
// will be able to distinguish variants from

@ -230,7 +230,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
def::DefAssociatedTy(..) |
def::DefTrait(_) => Some(recorder::TypeRef),
def::DefStatic(_, _) |
def::DefLocal(_, _) |
def::DefLocal(_) |
def::DefVariant(_, _, _) |
def::DefUpvar(_, _, _, _) => Some(recorder::VarRef),
@ -737,18 +737,14 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
let def = def_map.get(&ex.id);
let sub_span = self.span.span_for_last_ident(ex.span);
match *def {
def::DefUpvar(id, _, _, _) |
def::DefLocal(id, _) => self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
ast_util::local_def(id),
self.cur_scope),
def::DefStatic(def_id,_) |
def::DefVariant(_, def_id, _) => self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
def_id,
self.cur_scope),
def::DefUpvar(..) |
def::DefLocal(..) |
def::DefStatic(..) |
def::DefVariant(..) => self.fmt.ref_str(recorder::VarRef,
ex.span,
sub_span,
def.def_id(),
self.cur_scope),
def::DefStruct(def_id) => self.fmt.ref_str(recorder::StructRef,
ex.span,
sub_span,
@ -809,7 +805,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
def::DefStaticMethod(_, _, _) => {
self.write_sub_path_trait_truncated(path);
},
def::DefLocal(_, _) |
def::DefLocal(_) |
def::DefStatic(_,_) |
def::DefStruct(_) |
def::DefFn(_, _) => self.write_sub_paths_truncated(path),
@ -1377,12 +1373,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
}
let def = def_map.get(&id);
match *def {
def::DefLocal(id, _) => self.fmt.variable_str(p.span,
sub_span,
id,
path_to_string(p).as_slice(),
value.as_slice(),
""),
def::DefLocal(id) => self.fmt.variable_str(p.span,
sub_span,
id,
path_to_string(p).as_slice(),
value.as_slice(),
""),
def::DefVariant(_,id,_) => self.fmt.ref_str(ref_kind,
p.span,
sub_span,

@ -1226,7 +1226,7 @@ pub fn trans_match<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool {
match discr.node {
ast::ExprPath(..) => match bcx.def(discr.id) {
def::DefLocal(vid, _) | def::DefUpvar(vid, _, _, _) => {
def::DefLocal(vid) | def::DefUpvar(vid, _, _, _) => {
let mut rc = ReassignmentChecker {
node: vid,
reassigned: false

@ -1188,7 +1188,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
}
}
def::DefLocal(nid, _) => {
def::DefLocal(nid) => {
let datum = match bcx.fcx.lllocals.borrow().find(&nid) {
Some(&v) => v,
None => {

@ -5027,7 +5027,7 @@ pub fn polytype_for_def(fcx: &FnCtxt,
defn: def::Def)
-> Polytype {
match defn {
def::DefLocal(nid, _) => {
def::DefLocal(nid) => {
let typ = fcx.local_ty(sp, nid);
return no_params(typ);
}

@ -242,7 +242,7 @@ fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region {
let tcx = fcx.tcx();
match def {
def::DefLocal(node_id, _) => {
def::DefLocal(node_id) => {
tcx.region_maps.var_region(node_id)
}
def::DefUpvar(_, subdef, closure_id, body_id) => {