Skip to content

Commit a0dc2d9

Browse files
committed
Introduce semi-duplicate DefIds into DefLocal/DefUpvar to remove use
of xxx_local.
1 parent 3b1399d commit a0dc2d9

File tree

16 files changed

+51
-45
lines changed

16 files changed

+51
-45
lines changed

src/librustc/middle/astencode.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ impl tr for def::Def {
461461
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
462462
def::DefConst(did) => { def::DefConst(did.tr(dcx)) }
463463
def::DefAssociatedConst(did) => def::DefAssociatedConst(did.tr(dcx)),
464-
def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) }
464+
def::DefLocal(_, nid) => {
465+
let nid = dcx.tr_id(nid);
466+
let did = dcx.tcx.map.local_def_id(nid);
467+
def::DefLocal(did, nid)
468+
}
465469
def::DefVariant(e_did, v_did, is_s) => {
466470
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
467471
},
@@ -472,8 +476,11 @@ impl tr for def::Def {
472476
def::DefPrimTy(p) => def::DefPrimTy(p),
473477
def::DefTyParam(s, index, def_id, n) => def::DefTyParam(s, index, def_id.tr(dcx), n),
474478
def::DefUse(did) => def::DefUse(did.tr(dcx)),
475-
def::DefUpvar(nid1, index, nid2) => {
476-
def::DefUpvar(dcx.tr_id(nid1), index, dcx.tr_id(nid2))
479+
def::DefUpvar(_, nid1, index, nid2) => {
480+
let nid1 = dcx.tr_id(nid1);
481+
let nid2 = dcx.tr_id(nid2);
482+
let did1 = dcx.tcx.map.local_def_id(nid1);
483+
def::DefUpvar(did1, nid1, index, nid2)
477484
}
478485
def::DefStruct(did) => def::DefStruct(did.tr(dcx)),
479486
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid))

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
659659
doesn't point to a constant");
660660
}
661661
}
662-
Some(def::DefLocal(_)) if v.mode == Mode::ConstFn => {
662+
Some(def::DefLocal(..)) if v.mode == Mode::ConstFn => {
663663
// Sadly, we can't determine whether the types are zero-sized.
664664
v.add_qualif(ConstQualif::NOT_CONST | ConstQualif::NON_ZERO_SIZED);
665665
}

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
245245
let pat_ty = cx.tcx.pat_ty(p);
246246
if let ty::TyEnum(edef, _) = pat_ty.sty {
247247
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
248-
if let Some(DefLocal(_)) = def {
248+
if let Some(DefLocal(..)) = def {
249249
if edef.variants.iter().any(|variant|
250250
variant.name == ident.node.name
251251
&& variant.kind() == VariantKind::Unit

src/librustc/middle/def.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ pub enum Def {
2929
DefStatic(DefId, bool /* is_mutbl */),
3030
DefConst(DefId),
3131
DefAssociatedConst(DefId),
32-
DefLocal(ast::NodeId),
32+
DefLocal(DefId, // def id of variable
33+
ast::NodeId), // node id of variable
3334
DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */),
3435
DefTy(DefId, bool /* is_enum */),
3536
DefAssociatedTy(DefId /* trait */, DefId),
3637
DefTrait(DefId),
3738
DefPrimTy(hir::PrimTy),
3839
DefTyParam(ParamSpace, u32, DefId, ast::Name),
3940
DefUse(DefId),
40-
DefUpvar(ast::NodeId, // id of closed over local
41+
DefUpvar(DefId, // def id of closed over local
42+
ast::NodeId, // node id of closed over local
4143
usize, // index in the freevars list of the closure
4244
ast::NodeId), // expr node that creates the closure
4345

@@ -115,8 +117,8 @@ pub struct Export {
115117
impl Def {
116118
pub fn var_id(&self) -> ast::NodeId {
117119
match *self {
118-
DefLocal(id) |
119-
DefUpvar(id, _, _) => {
120+
DefLocal(_, id) |
121+
DefUpvar(_, id, _, _) => {
120122
id
121123
}
122124

@@ -135,15 +137,11 @@ impl Def {
135137
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
136138
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
137139
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
138-
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) => {
140+
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) |
141+
DefLocal(id, _) | DefUpvar(id, _, _, _) => {
139142
id
140143
}
141144

142-
DefLocal(id) |
143-
DefUpvar(id, _, _) => {
144-
DefId::xxx_local(id) // TODO, clearly
145-
}
146-
147145
DefLabel(..) |
148146
DefPrimTy(..) |
149147
DefSelfTy(..) => {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,9 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
280280
typer: &'t infer::InferCtxt<'a, 'tcx>)
281281
-> ExprUseVisitor<'d,'t,'a,'tcx> where 'tcx:'a
282282
{
283-
ExprUseVisitor {
284-
typer: typer,
285-
mc: mc::MemCategorizationContext::new(typer),
286-
delegate: delegate,
287-
}
283+
let mc: mc::MemCategorizationContext<'t, 'a, 'tcx> =
284+
mc::MemCategorizationContext::new(typer);
285+
ExprUseVisitor { typer: typer, mc: mc, delegate: delegate }
288286
}
289287

290288
pub fn walk_fn(&mut self,

src/librustc/middle/liveness.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
465465
let mut call_caps = Vec::new();
466466
ir.tcx.with_freevars(expr.id, |freevars| {
467467
for fv in freevars {
468-
if let DefLocal(rv) = fv.def {
468+
if let DefLocal(_, rv) = fv.def {
469469
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
470470
call_caps.push(CaptureInfo {ln: fv_ln,
471471
var_nid: rv});
@@ -1268,7 +1268,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12681268
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
12691269
-> LiveNode {
12701270
match self.ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() {
1271-
DefLocal(nid) => {
1271+
DefLocal(_, nid) => {
12721272
let ln = self.live_node(expr.id, expr.span);
12731273
if acc != 0 {
12741274
self.init_from_succ(ln, succ);
@@ -1517,9 +1517,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15171517
fn check_lvalue(&mut self, expr: &Expr) {
15181518
match expr.node {
15191519
hir::ExprPath(..) => {
1520-
if let DefLocal(nid) = self.ir.tcx.def_map.borrow().get(&expr.id)
1521-
.unwrap()
1522-
.full_def() {
1520+
if let DefLocal(_, nid) = self.ir.tcx.def_map.borrow().get(&expr.id)
1521+
.unwrap()
1522+
.full_def() {
15231523
// Assignment to an immutable variable or argument: only legal
15241524
// if there is no later assignment. If this local is actually
15251525
// mutable, then check for a reassignment to flag the mutability

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
575575
}))
576576
}
577577

578-
def::DefUpvar(var_id, _, fn_node_id) => {
578+
def::DefUpvar(_, var_id, _, fn_node_id) => {
579579
let ty = try!(self.node_ty(fn_node_id));
580580
match ty.sty {
581581
ty::TyClosure(closure_id, _) => {
@@ -600,7 +600,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
600600
}
601601
}
602602

603-
def::DefLocal(vid) => {
603+
def::DefLocal(_, vid) => {
604604
Ok(Rc::new(cmt_ {
605605
id: id,
606606
span: span,

src/librustc_lint/bad_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl LateLintPass for NonSnakeCase {
274274
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
275275
if let &hir::PatIdent(_, ref path1, _) = &p.node {
276276
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
277-
if let Some(def::DefLocal(_)) = def {
277+
if let Some(def::DefLocal(..)) = def {
278278
self.check_snake_case(cx, "variable", &path1.node.name.as_str(), Some(p.span));
279279
}
280280
}

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ impl LateLintPass for NonShorthandFieldPatterns {
248248
return false;
249249
}
250250
let def = def_map.get(&fieldpat.node.pat.id).map(|d| d.full_def());
251-
def == Some(def::DefLocal(fieldpat.node.pat.id))
251+
let def_id = cx.tcx.map.local_def_id(fieldpat.node.pat.id);
252+
def == Some(def::DefLocal(def_id, fieldpat.node.pat.id))
252253
});
253254
for fieldpat in field_pats {
254255
if let hir::PatIdent(_, ident, None) = fieldpat.node.pat.node {

src/librustc_mir/tcx/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,13 @@ fn convert_var<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>,
569569
let temp_lifetime = cx.tcx.region_maps.temporary_scope(expr.id);
570570

571571
match def {
572-
def::DefLocal(node_id) => {
572+
def::DefLocal(_, node_id) => {
573573
ExprKind::VarRef {
574574
id: node_id,
575575
}
576576
}
577577

578-
def::DefUpvar(id_var, index, closure_expr_id) => {
578+
def::DefUpvar(_, id_var, index, closure_expr_id) => {
579579
debug!("convert_var(upvar({:?}, {:?}, {:?}))", id_var, index, closure_expr_id);
580580
let var_ty = cx.tcx.node_id_to_type(id_var);
581581

src/librustc_resolve/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,19 +1982,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19821982
self.session.span_bug(span,
19831983
&format!("unexpected {:?} in bindings", def))
19841984
}
1985-
DefLocal(node_id) => {
1985+
DefLocal(_, node_id) => {
19861986
for rib in ribs {
19871987
match rib.kind {
19881988
NormalRibKind => {
19891989
// Nothing to do. Continue.
19901990
}
19911991
ClosureRibKind(function_id) => {
19921992
let prev_def = def;
1993+
let node_def_id = self.ast_map.local_def_id(node_id);
19931994

19941995
let mut seen = self.freevars_seen.borrow_mut();
19951996
let seen = seen.entry(function_id).or_insert_with(|| NodeMap());
19961997
if let Some(&index) = seen.get(&node_id) {
1997-
def = DefUpvar(node_id, index, function_id);
1998+
def = DefUpvar(node_def_id, node_id, index, function_id);
19981999
continue;
19992000
}
20002001
let mut freevars = self.freevars.borrow_mut();
@@ -2003,7 +2004,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20032004
let depth = vec.len();
20042005
vec.push(Freevar { def: prev_def, span: span });
20052006

2006-
def = DefUpvar(node_id, depth, function_id);
2007+
def = DefUpvar(node_def_id, node_id, depth, function_id);
20072008
seen.insert(node_id, depth);
20082009
}
20092010
ItemRibKind | MethodRibKind => {
@@ -2817,7 +2818,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28172818
debug!("(resolving pattern) binding `{}`",
28182819
renamed);
28192820

2820-
let def = DefLocal(pattern.id);
2821+
let def_id = self.ast_map.local_def_id(pattern.id);
2822+
let def = DefLocal(def_id, pattern.id);
28212823

28222824
// Record the definition so that later passes
28232825
// will be able to distinguish variants from

src/librustc_trans/save/dump_csv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
258258
def::DefStatic(_, _) |
259259
def::DefConst(_) |
260260
def::DefAssociatedConst(..) |
261-
def::DefLocal(_) |
261+
def::DefLocal(..) |
262262
def::DefVariant(_, _, _) |
263263
def::DefUpvar(..) => Some(recorder::VarRef),
264264

@@ -721,7 +721,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
721721
}
722722
}
723723
}
724-
def::DefLocal(_) |
724+
def::DefLocal(..) |
725725
def::DefStatic(_,_) |
726726
def::DefConst(..) |
727727
def::DefAssociatedConst(..) |
@@ -1170,7 +1170,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
11701170
}
11711171
let def = def_map.get(&id).unwrap().full_def();
11721172
match def {
1173-
def::DefLocal(id) => {
1173+
def::DefLocal(_, id) => {
11741174
let value = if immut == ast::MutImmutable {
11751175
self.span.snippet(p.span).to_string()
11761176
} else {

src/librustc_trans/trans/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,19 +1432,19 @@ pub fn trans_match<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
14321432
fn is_discr_reassigned(bcx: Block, discr: &hir::Expr, body: &hir::Expr) -> bool {
14331433
let (vid, field) = match discr.node {
14341434
hir::ExprPath(..) => match bcx.def(discr.id) {
1435-
def::DefLocal(vid) | def::DefUpvar(vid, _, _) => (vid, None),
1435+
def::DefLocal(_, vid) | def::DefUpvar(_, vid, _, _) => (vid, None),
14361436
_ => return false
14371437
},
14381438
hir::ExprField(ref base, field) => {
14391439
let vid = match bcx.tcx().def_map.borrow().get(&base.id).map(|d| d.full_def()) {
1440-
Some(def::DefLocal(vid)) | Some(def::DefUpvar(vid, _, _)) => vid,
1440+
Some(def::DefLocal(_, vid)) | Some(def::DefUpvar(_, vid, _, _)) => vid,
14411441
_ => return false
14421442
};
14431443
(vid, Some(mc::NamedField(field.node)))
14441444
},
14451445
hir::ExprTupField(ref base, field) => {
14461446
let vid = match bcx.tcx().def_map.borrow().get(&base.id).map(|d| d.full_def()) {
1447-
Some(def::DefLocal(vid)) | Some(def::DefUpvar(vid, _, _)) => vid,
1447+
Some(def::DefLocal(_, vid)) | Some(def::DefUpvar(_, vid, _, _)) => vid,
14481448
_ => return false
14491449
};
14501450
(vid, Some(mc::PositionalField(field.node)))

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
783783
hir::ExprPath(..) => {
784784
let def = cx.tcx().def_map.borrow().get(&e.id).unwrap().full_def();
785785
match def {
786-
def::DefLocal(id) => {
786+
def::DefLocal(_, id) => {
787787
if let Some(val) = fn_args.and_then(|args| args.get(&id).cloned()) {
788788
val
789789
} else {

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
13581358
let _icx = push_ctxt("trans_local_var");
13591359

13601360
match def {
1361-
def::DefUpvar(nid, _, _) => {
1361+
def::DefUpvar(_, nid, _, _) => {
13621362
// Can't move upvars, so this is never a ZeroMemLastUse.
13631363
let local_ty = node_id_type(bcx, nid);
13641364
let lval = Lvalue::new_with_hint("expr::trans_local_var (upvar)",
@@ -1372,7 +1372,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
13721372
}
13731373
}
13741374
}
1375-
def::DefLocal(nid) => {
1375+
def::DefLocal(_, nid) => {
13761376
let datum = match bcx.fcx.lllocals.borrow().get(&nid) {
13771377
Some(&v) => v,
13781378
None => {

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4300,7 +4300,7 @@ fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
43004300
defn: def::Def)
43014301
-> (TypeScheme<'tcx>, GenericPredicates<'tcx>) {
43024302
match defn {
4303-
def::DefLocal(nid) | def::DefUpvar(nid, _, _) => {
4303+
def::DefLocal(_, nid) | def::DefUpvar(_, nid, _, _) => {
43044304
let typ = fcx.local_ty(sp, nid);
43054305
(ty::TypeScheme { generics: ty::Generics::empty(), ty: typ },
43064306
ty::GenericPredicates::empty())

0 commit comments

Comments
 (0)