Skip to content

Commit 0f03b56

Browse files
committed
Move Def out of syntax crate, where it does not belong
1 parent 14d626a commit 0f03b56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+442
-392
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern crate time;
4646
extern crate log;
4747

4848
pub mod middle {
49+
pub mod def;
4950
pub mod trans;
5051
pub mod ty;
5152
pub mod ty_fold;

src/librustc/metadata/decoder.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use metadata::tydecode::{parse_ty_data, parse_def_id,
2222
parse_type_param_def_data,
2323
parse_bare_fn_ty_data, parse_trait_ref_data};
2424
use middle::lang_items;
25+
use middle::def;
2526
use middle::ty::{ImplContainer, TraitContainer};
2627
use middle::ty;
2728
use middle::typeck;
@@ -333,11 +334,11 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
333334
-> DefLike {
334335
let fam = item_family(item);
335336
match fam {
336-
ImmStatic => DlDef(ast::DefStatic(did, false)),
337-
MutStatic => DlDef(ast::DefStatic(did, true)),
338-
Struct => DlDef(ast::DefStruct(did)),
339-
UnsafeFn => DlDef(ast::DefFn(did, ast::UnsafeFn)),
340-
Fn => DlDef(ast::DefFn(did, ast::NormalFn)),
337+
ImmStatic => DlDef(def::DefStatic(did, false)),
338+
MutStatic => DlDef(def::DefStatic(did, true)),
339+
Struct => DlDef(def::DefStruct(did)),
340+
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn)),
341+
Fn => DlDef(def::DefFn(did, ast::NormalFn)),
341342
StaticMethod | UnsafeStaticMethod => {
342343
let fn_style = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
343344
{ ast::NormalFn };
@@ -348,27 +349,27 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
348349
// a trait_method_sort.
349350
let provenance = if reader::maybe_get_doc(
350351
item, tag_item_trait_method_sort).is_some() {
351-
ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
352+
def::FromTrait(item_reqd_and_translated_parent_item(cnum,
352353
item))
353354
} else {
354-
ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
355+
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
355356
item))
356357
};
357-
DlDef(ast::DefStaticMethod(did, provenance, fn_style))
358+
DlDef(def::DefStaticMethod(did, provenance, fn_style))
358359
}
359-
Type | ForeignType => DlDef(ast::DefTy(did)),
360-
Mod => DlDef(ast::DefMod(did)),
361-
ForeignMod => DlDef(ast::DefForeignMod(did)),
360+
Type | ForeignType => DlDef(def::DefTy(did)),
361+
Mod => DlDef(def::DefMod(did)),
362+
ForeignMod => DlDef(def::DefForeignMod(did)),
362363
StructVariant => {
363364
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
364-
DlDef(ast::DefVariant(enum_did, did, true))
365+
DlDef(def::DefVariant(enum_did, did, true))
365366
}
366367
TupleVariant => {
367368
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
368-
DlDef(ast::DefVariant(enum_did, did, false))
369+
DlDef(def::DefVariant(enum_did, did, false))
369370
}
370-
Trait => DlDef(ast::DefTrait(did)),
371-
Enum => DlDef(ast::DefTy(did)),
371+
Trait => DlDef(def::DefTrait(did)),
372+
Enum => DlDef(def::DefTy(did)),
372373
Impl => DlImpl(did),
373374
PublicField | InheritedField => DlField,
374375
}
@@ -459,7 +460,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
459460
// Something that a name can resolve to.
460461
#[deriving(Clone)]
461462
pub enum DefLike {
462-
DlDef(ast::Def),
463+
DlDef(def::Def),
463464
DlImpl(ast::DefId),
464465
DlField
465466
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> {
16311631
ItemImpl(_, Some(ref trait_ref), _, _) => {
16321632
let def_map = &self.ecx.tcx.def_map;
16331633
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
1634-
let def_id = ast_util::def_id_of_def(trait_def);
1634+
let def_id = trait_def.def_id();
16351635

16361636
// Load eagerly if this is an implementation of the Drop trait
16371637
// or if the trait is not defined in this crate.

src/librustc/middle/astencode.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use c = metadata::common;
1616
use cstore = metadata::cstore;
1717
use driver::session::Session;
1818
use metadata::decoder;
19+
use middle::def;
1920
use e = metadata::encoder;
2021
use middle::freevars::freevar_entry;
2122
use middle::region;
@@ -395,58 +396,58 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
395396
// ______________________________________________________________________
396397
// Encoding and decoding of ast::def
397398

398-
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> ast::Def {
399+
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def {
399400
let mut dsr = reader::Decoder::new(doc);
400-
let def: ast::Def = Decodable::decode(&mut dsr).unwrap();
401+
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
401402
def.tr(xcx)
402403
}
403404

404-
impl tr for ast::Def {
405-
fn tr(&self, xcx: &ExtendedDecodeContext) -> ast::Def {
405+
impl tr for def::Def {
406+
fn tr(&self, xcx: &ExtendedDecodeContext) -> def::Def {
406407
match *self {
407-
ast::DefFn(did, p) => ast::DefFn(did.tr(xcx), p),
408-
ast::DefStaticMethod(did, wrapped_did2, p) => {
409-
ast::DefStaticMethod(did.tr(xcx),
408+
def::DefFn(did, p) => def::DefFn(did.tr(xcx), p),
409+
def::DefStaticMethod(did, wrapped_did2, p) => {
410+
def::DefStaticMethod(did.tr(xcx),
410411
match wrapped_did2 {
411-
ast::FromTrait(did2) => {
412-
ast::FromTrait(did2.tr(xcx))
412+
def::FromTrait(did2) => {
413+
def::FromTrait(did2.tr(xcx))
413414
}
414-
ast::FromImpl(did2) => {
415-
ast::FromImpl(did2.tr(xcx))
415+
def::FromImpl(did2) => {
416+
def::FromImpl(did2.tr(xcx))
416417
}
417418
},
418419
p)
419420
}
420-
ast::DefMethod(did0, did1) => {
421-
ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
421+
def::DefMethod(did0, did1) => {
422+
def::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
422423
}
423-
ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
424-
ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
425-
ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
426-
ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
427-
ast::DefArg(nid, b) => { ast::DefArg(xcx.tr_id(nid), b) }
428-
ast::DefLocal(nid, b) => { ast::DefLocal(xcx.tr_id(nid), b) }
429-
ast::DefVariant(e_did, v_did, is_s) => {
430-
ast::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
424+
def::DefSelfTy(nid) => { def::DefSelfTy(xcx.tr_id(nid)) }
425+
def::DefMod(did) => { def::DefMod(did.tr(xcx)) }
426+
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(xcx)) }
427+
def::DefStatic(did, m) => { def::DefStatic(did.tr(xcx), m) }
428+
def::DefArg(nid, b) => { def::DefArg(xcx.tr_id(nid), b) }
429+
def::DefLocal(nid, b) => { def::DefLocal(xcx.tr_id(nid), b) }
430+
def::DefVariant(e_did, v_did, is_s) => {
431+
def::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
431432
},
432-
ast::DefTrait(did) => ast::DefTrait(did.tr(xcx)),
433-
ast::DefTy(did) => ast::DefTy(did.tr(xcx)),
434-
ast::DefPrimTy(p) => ast::DefPrimTy(p),
435-
ast::DefTyParam(did, v) => ast::DefTyParam(did.tr(xcx), v),
436-
ast::DefBinding(nid, bm) => ast::DefBinding(xcx.tr_id(nid), bm),
437-
ast::DefUse(did) => ast::DefUse(did.tr(xcx)),
438-
ast::DefUpvar(nid1, def, nid2, nid3) => {
439-
ast::DefUpvar(xcx.tr_id(nid1),
433+
def::DefTrait(did) => def::DefTrait(did.tr(xcx)),
434+
def::DefTy(did) => def::DefTy(did.tr(xcx)),
435+
def::DefPrimTy(p) => def::DefPrimTy(p),
436+
def::DefTyParam(did, v) => def::DefTyParam(did.tr(xcx), v),
437+
def::DefBinding(nid, bm) => def::DefBinding(xcx.tr_id(nid), bm),
438+
def::DefUse(did) => def::DefUse(did.tr(xcx)),
439+
def::DefUpvar(nid1, def, nid2, nid3) => {
440+
def::DefUpvar(xcx.tr_id(nid1),
440441
@(*def).tr(xcx),
441442
xcx.tr_id(nid2),
442443
xcx.tr_id(nid3))
443444
}
444-
ast::DefStruct(did) => ast::DefStruct(did.tr(xcx)),
445-
ast::DefRegion(nid) => ast::DefRegion(xcx.tr_id(nid)),
446-
ast::DefTyParamBinder(nid) => {
447-
ast::DefTyParamBinder(xcx.tr_id(nid))
445+
def::DefStruct(did) => def::DefStruct(did.tr(xcx)),
446+
def::DefRegion(nid) => def::DefRegion(xcx.tr_id(nid)),
447+
def::DefTyParamBinder(nid) => {
448+
def::DefTyParamBinder(xcx.tr_id(nid))
448449
}
449-
ast::DefLabel(nid) => ast::DefLabel(xcx.tr_id(nid))
450+
def::DefLabel(nid) => def::DefLabel(xcx.tr_id(nid))
450451
}
451452
}
452453
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use middle::dataflow::DataFlowContext;
1616
use middle::dataflow::DataFlowOperator;
17+
use middle::def;
1718
use euv = middle::expr_use_visitor;
1819
use mc = middle::mem_categorization;
1920
use middle::ty;
@@ -399,7 +400,7 @@ impl<'a> BorrowckCtxt<'a> {
399400
id: ast::NodeId,
400401
span: Span,
401402
ty: ty::t,
402-
def: ast::Def)
403+
def: def::Def)
403404
-> mc::cmt {
404405
match self.mc().cat_def(id, span, ty, def) {
405406
Ok(c) => c,
@@ -412,11 +413,11 @@ impl<'a> BorrowckCtxt<'a> {
412413
pub fn cat_captured_var(&self,
413414
closure_id: ast::NodeId,
414415
closure_span: Span,
415-
upvar_def: ast::Def)
416+
upvar_def: def::Def)
416417
-> mc::cmt {
417418
// Create the cmt for the variable being borrowed, from the
418419
// caller's perspective
419-
let var_id = ast_util::def_id_of_def(upvar_def).node;
420+
let var_id = upvar_def.def_id().node;
420421
let var_ty = ty::node_id_to_type(self.tcx, var_id);
421422
self.cat_def(closure_id, closure_span, var_ty, upvar_def)
422423
}

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use middle::cfg::*;
12+
use middle::def;
1213
use middle::graph;
1314
use middle::typeck;
1415
use middle::ty;
@@ -531,7 +532,7 @@ impl<'a> CFGBuilder<'a> {
531532

532533
Some(_) => {
533534
match self.tcx.def_map.borrow().find(&expr.id) {
534-
Some(&ast::DefLabel(loop_id)) => {
535+
Some(&def::DefLabel(loop_id)) => {
535536
for l in self.loop_scopes.iter() {
536537
if l.loop_id == loop_id {
537538
return *l;

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use driver::session::Session;
13+
use middle::def::*;
1314
use middle::resolve;
1415
use middle::ty;
1516
use middle::typeck;

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use middle::const_eval::{compare_const_vals, lookup_const_by_id};
1414
use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
15+
use middle::def::*;
1516
use middle::pat_util::*;
1617
use middle::ty::*;
1718
use middle::ty;

src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use metadata::csearch;
1515
use middle::astencode;
1616

17+
use middle::def;
1718
use middle::ty;
1819
use middle::typeck::astconv;
1920
use util::nodemap::{DefIdMap};
@@ -83,10 +84,10 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
8384
pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> {
8485
let opt_def = tcx.def_map.borrow().find_copy(&e.id);
8586
match opt_def {
86-
Some(ast::DefStatic(def_id, false)) => {
87+
Some(def::DefStatic(def_id, false)) => {
8788
lookup_const_by_id(tcx, def_id)
8889
}
89-
Some(ast::DefVariant(enum_def, variant_def, _)) => {
90+
Some(def::DefVariant(enum_def, variant_def, _)) => {
9091
lookup_variant_by_id(tcx, enum_def, variant_def)
9192
}
9293
_ => None

src/librustc/middle/dataflow.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
*/
1818

1919

20+
use middle::def;
21+
use middle::ty;
22+
use middle::typeck;
2023
use std::io;
2124
use std::string::String;
2225
use std::uint;
2326
use syntax::ast;
2427
use syntax::ast_util;
2528
use syntax::ast_util::IdRange;
2629
use syntax::print::{pp, pprust};
27-
use middle::ty;
28-
use middle::typeck;
2930
use util::ppaux::Repr;
3031
use util::nodemap::NodeMap;
3132

@@ -757,7 +758,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
757758

758759
Some(_) => {
759760
match self.tcx().def_map.borrow().find(&expr.id) {
760-
Some(&ast::DefLabel(loop_id)) => {
761+
Some(&def::DefLabel(loop_id)) => {
761762
match loop_scopes.iter().position(|l| l.loop_id == loop_id) {
762763
Some(i) => i,
763764
None => {

src/librustc/middle/dead.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// closely. The idea is that all reachable symbols are live, codes called
1313
// from live codes are live, and everything else is dead.
1414

15+
use middle::def;
1516
use middle::lint::{Allow, contains_lint, DeadCode};
1617
use middle::privacy;
1718
use middle::ty;
@@ -21,7 +22,7 @@ use util::nodemap::NodeSet;
2122
use std::collections::HashSet;
2223
use syntax::ast;
2324
use syntax::ast_map;
24-
use syntax::ast_util::{local_def, def_id_of_def, is_local};
25+
use syntax::ast_util::{local_def, is_local};
2526
use syntax::attr;
2627
use syntax::codemap;
2728
use syntax::parse::token;
@@ -77,9 +78,9 @@ impl<'a> MarkSymbolVisitor<'a> {
7778
None => return
7879
};
7980
let def_id = match def {
80-
ast::DefVariant(enum_id, _, _) => Some(enum_id),
81-
ast::DefPrimTy(_) => None,
82-
_ => Some(def_id_of_def(def)),
81+
def::DefVariant(enum_id, _, _) => Some(enum_id),
82+
def::DefPrimTy(_) => None,
83+
_ => Some(def.def_id())
8384
};
8485
match def_id {
8586
Some(def_id) => self.check_def_id(def_id),

0 commit comments

Comments
 (0)