Skip to content

Commit 6543c5b

Browse files
committed
rustc: remove BindingMode from DefLocal.
1 parent 1813b8c commit 6543c5b

File tree

11 files changed

+46
-57
lines changed

11 files changed

+46
-57
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl LintPass for NonSnakeCase {
954954
match &p.node {
955955
&ast::PatIdent(_, ref path1, _) => {
956956
match cx.tcx.def_map.borrow().find(&p.id) {
957-
Some(&def::DefLocal(_, _)) => {
957+
Some(&def::DefLocal(_)) => {
958958
self.check_snake_case(cx, "variable", path1.node, p.span);
959959
}
960960
_ => {}

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl tr for def::Def {
462462
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }
463463
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) }
464464
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
465-
def::DefLocal(nid, b) => { def::DefLocal(dcx.tr_id(nid), b) }
465+
def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) }
466466
def::DefVariant(e_did, v_did, is_s) => {
467467
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
468468
},

src/librustc/middle/def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum Def {
2222
DefMod(ast::DefId),
2323
DefForeignMod(ast::DefId),
2424
DefStatic(ast::DefId, bool /* is_mutbl */),
25-
DefLocal(ast::NodeId, ast::BindingMode),
25+
DefLocal(ast::NodeId),
2626
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
2727
DefTy(ast::DefId, bool /* is_enum */),
2828
DefAssociatedTy(ast::DefId),
@@ -66,7 +66,7 @@ impl Def {
6666
DefMethod(id, _) => {
6767
id
6868
}
69-
DefLocal(id, _) |
69+
DefLocal(id) |
7070
DefSelfTy(id) |
7171
DefUpvar(id, _, _, _) |
7272
DefRegion(id) |

src/librustc/middle/liveness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
462462
freevars::with_freevars(ir.tcx, expr.id, |freevars| {
463463
for fv in freevars.iter() {
464464
match fv.def {
465-
DefLocal(rv, _) => {
465+
DefLocal(rv) => {
466466
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
467467
call_caps.push(CaptureInfo {ln: fv_ln,
468468
var_nid: rv});
@@ -1288,7 +1288,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12881288
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
12891289
-> LiveNode {
12901290
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
1291-
DefLocal(nid, _) => {
1291+
DefLocal(nid) => {
12921292
let ln = self.live_node(expr.id, expr.span);
12931293
if acc != 0u {
12941294
self.init_from_succ(ln, succ);
@@ -1527,7 +1527,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15271527
match expr.node {
15281528
ExprPath(_) => {
15291529
match self.ir.tcx.def_map.borrow().get_copy(&expr.id) {
1530-
DefLocal(nid, _) => {
1530+
DefLocal(nid) => {
15311531
// Assignment to an immutable variable or argument: only legal
15321532
// if there is no later assignment. If this local is actually
15331533
// mutable, then check for a reassignment to flag the mutability

src/librustc/middle/mem_categorization.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -312,26 +312,19 @@ impl MutabilityCategory {
312312
}
313313
}
314314

315-
fn from_def(def: &def::Def) -> MutabilityCategory {
316-
match *def {
317-
def::DefFn(..) | def::DefStaticMethod(..) | def::DefSelfTy(..) |
318-
def::DefMod(..) | def::DefForeignMod(..) | def::DefVariant(..) |
319-
def::DefTy(..) | def::DefTrait(..) | def::DefPrimTy(..) |
320-
def::DefTyParam(..) | def::DefUse(..) | def::DefStruct(..) |
321-
def::DefTyParamBinder(..) | def::DefRegion(..) | def::DefLabel(..) |
322-
def::DefMethod(..) | def::DefAssociatedTy(..) => {
323-
fail!("no MutabilityCategory for def: {}", *def)
324-
}
325-
326-
def::DefStatic(_, false) => McImmutable,
327-
def::DefStatic(_, true) => McDeclared,
328-
329-
def::DefLocal(_, binding_mode) => match binding_mode {
330-
ast::BindByValue(ast::MutMutable) => McDeclared,
331-
_ => McImmutable
315+
fn from_local(tcx: &ty::ctxt, id: ast::NodeId) -> MutabilityCategory {
316+
match tcx.map.get(id) {
317+
ast_map::NodeLocal(p) | ast_map::NodeArg(p) => match p.node {
318+
ast::PatIdent(bind_mode, _, _) => {
319+
if bind_mode == ast::BindByValue(ast::MutMutable) {
320+
McDeclared
321+
} else {
322+
McImmutable
323+
}
324+
}
325+
_ => tcx.sess.span_bug(p.span, "expected identifier pattern")
332326
},
333-
334-
def::DefUpvar(_, def, _, _) => MutabilityCategory::from_def(&*def)
327+
_ => tcx.sess.span_bug(tcx.map.span(id), "expected identifier pattern")
335328
}
336329
}
337330

@@ -544,12 +537,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
544537
}))
545538
}
546539

547-
def::DefStatic(_, _) => {
540+
def::DefStatic(_, mutbl) => {
548541
Ok(Rc::new(cmt_ {
549542
id:id,
550543
span:span,
551544
cat:cat_static_item,
552-
mutbl: MutabilityCategory::from_def(&def),
545+
mutbl: if mutbl { McDeclared } else { McImmutable},
553546
ty:expr_ty
554547
}))
555548
}
@@ -582,7 +575,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
582575
onceness: closure_ty.onceness,
583576
capturing_proc: fn_node_id,
584577
}),
585-
mutbl: MutabilityCategory::from_def(&def),
578+
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
586579
ty:expr_ty
587580
}))
588581
}
@@ -605,7 +598,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
605598
onceness: onceness,
606599
capturing_proc: fn_node_id,
607600
}),
608-
mutbl: MutabilityCategory::from_def(&def),
601+
mutbl: MutabilityCategory::from_local(self.tcx(), var_id),
609602
ty: expr_ty
610603
}))
611604
}
@@ -619,12 +612,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
619612
}
620613
}
621614

622-
def::DefLocal(vid, _) => {
615+
def::DefLocal(vid) => {
623616
Ok(Rc::new(cmt_ {
624617
id: id,
625618
span: span,
626619
cat: cat_local(vid),
627-
mutbl: MutabilityCategory::from_def(&def),
620+
mutbl: MutabilityCategory::from_local(self.tcx(), vid),
628621
ty: expr_ty
629622
}))
630623
}

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4940,7 +4940,7 @@ impl<'a> Resolver<'a> {
49404940
debug!("(resolving pattern) binding `{}`",
49414941
token::get_name(renamed));
49424942

4943-
let def = DefLocal(pattern.id, binding_mode);
4943+
let def = DefLocal(pattern.id);
49444944

49454945
// Record the definition so that later passes
49464946
// will be able to distinguish variants from

src/librustc/middle/save/mod.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
230230
def::DefAssociatedTy(..) |
231231
def::DefTrait(_) => Some(recorder::TypeRef),
232232
def::DefStatic(_, _) |
233-
def::DefLocal(_, _) |
233+
def::DefLocal(_) |
234234
def::DefVariant(_, _, _) |
235235
def::DefUpvar(_, _, _, _) => Some(recorder::VarRef),
236236

@@ -737,18 +737,14 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
737737
let def = def_map.get(&ex.id);
738738
let sub_span = self.span.span_for_last_ident(ex.span);
739739
match *def {
740-
def::DefUpvar(id, _, _, _) |
741-
def::DefLocal(id, _) => self.fmt.ref_str(recorder::VarRef,
742-
ex.span,
743-
sub_span,
744-
ast_util::local_def(id),
745-
self.cur_scope),
746-
def::DefStatic(def_id,_) |
747-
def::DefVariant(_, def_id, _) => self.fmt.ref_str(recorder::VarRef,
748-
ex.span,
749-
sub_span,
750-
def_id,
751-
self.cur_scope),
740+
def::DefUpvar(..) |
741+
def::DefLocal(..) |
742+
def::DefStatic(..) |
743+
def::DefVariant(..) => self.fmt.ref_str(recorder::VarRef,
744+
ex.span,
745+
sub_span,
746+
def.def_id(),
747+
self.cur_scope),
752748
def::DefStruct(def_id) => self.fmt.ref_str(recorder::StructRef,
753749
ex.span,
754750
sub_span,
@@ -809,7 +805,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
809805
def::DefStaticMethod(_, _, _) => {
810806
self.write_sub_path_trait_truncated(path);
811807
},
812-
def::DefLocal(_, _) |
808+
def::DefLocal(_) |
813809
def::DefStatic(_,_) |
814810
def::DefStruct(_) |
815811
def::DefFn(_, _) => self.write_sub_paths_truncated(path),
@@ -1377,12 +1373,12 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
13771373
}
13781374
let def = def_map.get(&id);
13791375
match *def {
1380-
def::DefLocal(id, _) => self.fmt.variable_str(p.span,
1381-
sub_span,
1382-
id,
1383-
path_to_string(p).as_slice(),
1384-
value.as_slice(),
1385-
""),
1376+
def::DefLocal(id) => self.fmt.variable_str(p.span,
1377+
sub_span,
1378+
id,
1379+
path_to_string(p).as_slice(),
1380+
value.as_slice(),
1381+
""),
13861382
def::DefVariant(_,id,_) => self.fmt.ref_str(ref_kind,
13871383
p.span,
13881384
sub_span,

src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ pub fn trans_match<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
12261226
fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool {
12271227
match discr.node {
12281228
ast::ExprPath(..) => match bcx.def(discr.id) {
1229-
def::DefLocal(vid, _) | def::DefUpvar(vid, _, _, _) => {
1229+
def::DefLocal(vid) | def::DefUpvar(vid, _, _, _) => {
12301230
let mut rc = ReassignmentChecker {
12311231
node: vid,
12321232
reassigned: false

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11881188
}
11891189
}
11901190
}
1191-
def::DefLocal(nid, _) => {
1191+
def::DefLocal(nid) => {
11921192
let datum = match bcx.fcx.lllocals.borrow().find(&nid) {
11931193
Some(&v) => v,
11941194
None => {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5027,7 +5027,7 @@ pub fn polytype_for_def(fcx: &FnCtxt,
50275027
defn: def::Def)
50285028
-> Polytype {
50295029
match defn {
5030-
def::DefLocal(nid, _) => {
5030+
def::DefLocal(nid) => {
50315031
let typ = fcx.local_ty(sp, nid);
50325032
return no_params(typ);
50335033
}

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region {
242242

243243
let tcx = fcx.tcx();
244244
match def {
245-
def::DefLocal(node_id, _) => {
245+
def::DefLocal(node_id) => {
246246
tcx.region_maps.var_region(node_id)
247247
}
248248
def::DefUpvar(_, subdef, closure_id, body_id) => {

0 commit comments

Comments
 (0)