auto merge of #12017 : FlaPer87/rust/replace-mod-crate, r=alexcrichton

The first setp for #9880 is to add a new `crate` keyword. This PR does exactly that. I took a chance to refactor `parse_item_foreign_mod` and I broke it down into 2 separate methods to isolate each feature.

The next step will be to push a new stage0 snapshot and then get rid of all `extern mod` around the code.
This commit is contained in:
bors 2014-02-13 16:32:01 -08:00
commit 89b1686bd7
76 changed files with 618 additions and 590 deletions

View File

@ -178,18 +178,18 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
/// standard library and prelude. /// standard library and prelude.
pub fn phase_2_configure_and_expand(sess: Session, pub fn phase_2_configure_and_expand(sess: Session,
loader: &mut CrateLoader, loader: &mut CrateLoader,
mut crate: ast::Crate) mut krate: ast::Crate)
-> (ast::Crate, syntax::ast_map::Map) { -> (ast::Crate, syntax::ast_map::Map) {
let time_passes = sess.time_passes(); let time_passes = sess.time_passes();
sess.building_library.set(session::building_library(sess.opts, &crate)); sess.building_library.set(session::building_library(sess.opts, &krate));
sess.crate_types.set(session::collect_crate_types(&sess, crate.attrs)); sess.crate_types.set(session::collect_crate_types(&sess, krate.attrs));
time(time_passes, "gated feature checking", (), |_| time(time_passes, "gated feature checking", (), |_|
front::feature_gate::check_crate(sess, &crate)); front::feature_gate::check_crate(sess, &krate));
crate = time(time_passes, "crate injection", crate, |crate| krate = time(time_passes, "crate injection", krate, |krate|
front::std_inject::maybe_inject_crates_ref(sess, crate)); front::std_inject::maybe_inject_crates_ref(sess, krate));
// strip before expansion to allow macros to depend on // strip before expansion to allow macros to depend on
// configuration variables e.g/ in // configuration variables e.g/ in
@ -199,29 +199,29 @@ pub fn phase_2_configure_and_expand(sess: Session,
// //
// baz! should not use this definition unless foo is enabled. // baz! should not use this definition unless foo is enabled.
crate = time(time_passes, "configuration 1", crate, |crate| krate = time(time_passes, "configuration 1", krate, |krate|
front::config::strip_unconfigured_items(crate)); front::config::strip_unconfigured_items(krate));
crate = time(time_passes, "expansion", crate, |crate| { krate = time(time_passes, "expansion", krate, |krate| {
syntax::ext::expand::expand_crate(sess.parse_sess, syntax::ext::expand::expand_crate(sess.parse_sess,
loader, loader,
crate) krate)
}); });
// dump the syntax-time crates // dump the syntax-time crates
sess.cstore.reset(); sess.cstore.reset();
// strip again, in case expansion added anything with a #[cfg]. // strip again, in case expansion added anything with a #[cfg].
crate = time(time_passes, "configuration 2", crate, |crate| krate = time(time_passes, "configuration 2", krate, |krate|
front::config::strip_unconfigured_items(crate)); front::config::strip_unconfigured_items(krate));
crate = time(time_passes, "maybe building test harness", crate, |crate| krate = time(time_passes, "maybe building test harness", krate, |krate|
front::test::modify_for_testing(sess, crate)); front::test::modify_for_testing(sess, krate));
crate = time(time_passes, "prelude injection", crate, |crate| krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, crate)); front::std_inject::maybe_inject_prelude(sess, krate));
time(time_passes, "assinging node ids and indexing ast", crate, |crate| time(time_passes, "assinging node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, crate)) front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
} }
pub struct CrateAnalysis { pub struct CrateAnalysis {
@ -237,18 +237,18 @@ pub struct CrateAnalysis {
/// miscellaneous analysis passes on the crate. Return various /// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis. /// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes(sess: Session, pub fn phase_3_run_analysis_passes(sess: Session,
crate: &ast::Crate, krate: &ast::Crate,
ast_map: syntax::ast_map::Map) -> CrateAnalysis { ast_map: syntax::ast_map::Map) -> CrateAnalysis {
let time_passes = sess.time_passes(); let time_passes = sess.time_passes();
time(time_passes, "external crate/lib resolution", (), |_| time(time_passes, "external crate/lib resolution", (), |_|
creader::read_crates(sess, crate, creader::read_crates(sess, krate,
session::sess_os_to_meta_os(sess.targ_cfg.os), session::sess_os_to_meta_os(sess.targ_cfg.os),
token::get_ident_interner())); token::get_ident_interner()));
let lang_items = time(time_passes, "language item collection", (), |_| let lang_items = time(time_passes, "language item collection", (), |_|
middle::lang_items::collect_language_items(crate, sess)); middle::lang_items::collect_language_items(krate, sess));
let middle::resolve::CrateMap { let middle::resolve::CrateMap {
def_map: def_map, def_map: def_map,
@ -258,72 +258,72 @@ pub fn phase_3_run_analysis_passes(sess: Session,
last_private_map: last_private_map last_private_map: last_private_map
} = } =
time(time_passes, "resolution", (), |_| time(time_passes, "resolution", (), |_|
middle::resolve::resolve_crate(sess, lang_items, crate)); middle::resolve::resolve_crate(sess, lang_items, krate));
let named_region_map = time(time_passes, "lifetime resolution", (), let named_region_map = time(time_passes, "lifetime resolution", (),
|_| middle::resolve_lifetime::crate(sess, crate)); |_| middle::resolve_lifetime::krate(sess, krate));
time(time_passes, "looking for entry point", (), time(time_passes, "looking for entry point", (),
|_| middle::entry::find_entry_point(sess, crate, ast_map)); |_| middle::entry::find_entry_point(sess, krate, ast_map));
sess.macro_registrar_fn.with_mut(|r| *r = sess.macro_registrar_fn.with_mut(|r| *r =
time(time_passes, "looking for macro registrar", (), |_| time(time_passes, "looking for macro registrar", (), |_|
syntax::ext::registrar::find_macro_registrar( syntax::ext::registrar::find_macro_registrar(
sess.span_diagnostic, crate))); sess.span_diagnostic, krate)));
let freevars = time(time_passes, "freevar finding", (), |_| let freevars = time(time_passes, "freevar finding", (), |_|
freevars::annotate_freevars(def_map, crate)); freevars::annotate_freevars(def_map, krate));
let region_map = time(time_passes, "region resolution", (), |_| let region_map = time(time_passes, "region resolution", (), |_|
middle::region::resolve_crate(sess, crate)); middle::region::resolve_crate(sess, krate));
let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars, let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
region_map, lang_items); region_map, lang_items);
// passes are timed inside typeck // passes are timed inside typeck
let (method_map, vtable_map) = typeck::check_crate(ty_cx, trait_map, crate); let (method_map, vtable_map) = typeck::check_crate(ty_cx, trait_map, krate);
// These next two const passes can probably be merged // These next two const passes can probably be merged
time(time_passes, "const marking", (), |_| time(time_passes, "const marking", (), |_|
middle::const_eval::process_crate(crate, ty_cx)); middle::const_eval::process_crate(krate, ty_cx));
time(time_passes, "const checking", (), |_| time(time_passes, "const checking", (), |_|
middle::check_const::check_crate(sess, crate, ast_map, def_map, middle::check_const::check_crate(sess, krate, ast_map, def_map,
method_map, ty_cx)); method_map, ty_cx));
let maps = (external_exports, last_private_map); let maps = (external_exports, last_private_map);
let (exported_items, public_items) = let (exported_items, public_items) =
time(time_passes, "privacy checking", maps, |(a, b)| time(time_passes, "privacy checking", maps, |(a, b)|
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, middle::privacy::check_crate(ty_cx, &method_map, &exp_map2,
a, b, crate)); a, b, krate));
time(time_passes, "effect checking", (), |_| time(time_passes, "effect checking", (), |_|
middle::effect::check_crate(ty_cx, method_map, crate)); middle::effect::check_crate(ty_cx, method_map, krate));
time(time_passes, "loop checking", (), |_| time(time_passes, "loop checking", (), |_|
middle::check_loop::check_crate(ty_cx, crate)); middle::check_loop::check_crate(ty_cx, krate));
let middle::moves::MoveMaps {moves_map, moved_variables_set, let middle::moves::MoveMaps {moves_map, moved_variables_set,
capture_map} = capture_map} =
time(time_passes, "compute moves", (), |_| time(time_passes, "compute moves", (), |_|
middle::moves::compute_moves(ty_cx, method_map, crate)); middle::moves::compute_moves(ty_cx, method_map, krate));
time(time_passes, "match checking", (), |_| time(time_passes, "match checking", (), |_|
middle::check_match::check_crate(ty_cx, method_map, middle::check_match::check_crate(ty_cx, method_map,
moves_map, crate)); moves_map, krate));
time(time_passes, "liveness checking", (), |_| time(time_passes, "liveness checking", (), |_|
middle::liveness::check_crate(ty_cx, method_map, middle::liveness::check_crate(ty_cx, method_map,
capture_map, crate)); capture_map, krate));
let root_map = let root_map =
time(time_passes, "borrow checking", (), |_| time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(ty_cx, method_map, middle::borrowck::check_crate(ty_cx, method_map,
moves_map, moved_variables_set, moves_map, moved_variables_set,
capture_map, crate)); capture_map, krate));
time(time_passes, "kind checking", (), |_| time(time_passes, "kind checking", (), |_|
kind::check_crate(ty_cx, method_map, crate)); kind::check_crate(ty_cx, method_map, krate));
let reachable_map = let reachable_map =
time(time_passes, "reachability checking", (), |_| time(time_passes, "reachability checking", (), |_|
@ -336,12 +336,12 @@ pub fn phase_3_run_analysis_passes(sess: Session,
method_map, method_map,
&exported_items, &exported_items,
reachable_map.get(), reachable_map.get(),
crate) krate)
}); });
} }
time(time_passes, "lint checking", (), |_| time(time_passes, "lint checking", (), |_|
lint::check_crate(ty_cx, method_map, &exported_items, crate)); lint::check_crate(ty_cx, method_map, &exported_items, krate));
CrateAnalysis { CrateAnalysis {
exp_map2: exp_map2, exp_map2: exp_map2,
@ -370,11 +370,11 @@ pub struct CrateTranslation {
/// Run the translation phase to LLVM, after which the AST and analysis can /// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded. /// be discarded.
pub fn phase_4_translate_to_llvm(sess: Session, pub fn phase_4_translate_to_llvm(sess: Session,
crate: ast::Crate, krate: ast::Crate,
analysis: &CrateAnalysis, analysis: &CrateAnalysis,
outputs: &OutputFilenames) -> CrateTranslation { outputs: &OutputFilenames) -> CrateTranslation {
time(sess.time_passes(), "translation", crate, |crate| time(sess.time_passes(), "translation", krate, |krate|
trans::base::trans_crate(sess, crate, analysis, outputs)) trans::base::trans_crate(sess, krate, analysis, outputs))
} }
/// Run LLVM itself, producing a bitcode file, assembly file or object file /// Run LLVM itself, producing a bitcode file, assembly file or object file
@ -450,8 +450,8 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
fn write_out_deps(sess: Session, fn write_out_deps(sess: Session,
input: &Input, input: &Input,
outputs: &OutputFilenames, outputs: &OutputFilenames,
crate: &ast::Crate) -> io::IoResult<()> { krate: &ast::Crate) -> io::IoResult<()> {
let lm = link::build_link_meta(crate.attrs, outputs, let lm = link::build_link_meta(krate.attrs, outputs,
&mut ::util::sha2::Sha256::new()); &mut ::util::sha2::Sha256::new());
let mut out_filenames = ~[]; let mut out_filenames = ~[];
@ -517,14 +517,14 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
// possible to keep the peak memory usage low // possible to keep the peak memory usage low
let (outputs, trans) = { let (outputs, trans) = {
let (expanded_crate, ast_map) = { let (expanded_crate, ast_map) = {
let crate = phase_1_parse_input(sess, cfg, input); let krate = phase_1_parse_input(sess, cfg, input);
if sess.show_span() { if sess.show_span() {
front::show_span::run(sess, &crate); front::show_span::run(sess, &krate);
return; return;
} }
if stop_after_phase_1(sess) { return; } if stop_after_phase_1(sess) { return; }
let loader = &mut Loader::new(sess); let loader = &mut Loader::new(sess);
phase_2_configure_and_expand(sess, loader, crate) phase_2_configure_and_expand(sess, loader, krate)
}; };
let outputs = build_output_filenames(input, outdir, output, let outputs = build_output_filenames(input, outdir, output,
expanded_crate.attrs, sess); expanded_crate.attrs, sess);
@ -609,15 +609,15 @@ pub fn pretty_print_input(sess: Session,
cfg: ast::CrateConfig, cfg: ast::CrateConfig,
input: &Input, input: &Input,
ppm: PpMode) { ppm: PpMode) {
let crate = phase_1_parse_input(sess, cfg, input); let krate = phase_1_parse_input(sess, cfg, input);
let (crate, ast_map, is_expanded) = match ppm { let (krate, ast_map, is_expanded) = match ppm {
PpmExpanded | PpmExpandedIdentified | PpmTyped => { PpmExpanded | PpmExpandedIdentified | PpmTyped => {
let loader = &mut Loader::new(sess); let loader = &mut Loader::new(sess);
let (crate, ast_map) = phase_2_configure_and_expand(sess, loader, crate); let (krate, ast_map) = phase_2_configure_and_expand(sess, loader, krate);
(crate, Some(ast_map), true) (krate, Some(ast_map), true)
} }
_ => (crate, None, false) _ => (krate, None, false)
}; };
let annotation = match ppm { let annotation = match ppm {
@ -626,7 +626,7 @@ pub fn pretty_print_input(sess: Session,
} }
PpmTyped => { PpmTyped => {
let ast_map = ast_map.expect("--pretty=typed missing ast_map"); let ast_map = ast_map.expect("--pretty=typed missing ast_map");
let analysis = phase_3_run_analysis_passes(sess, &crate, ast_map); let analysis = phase_3_run_analysis_passes(sess, &krate, ast_map);
~TypedAnnotation { ~TypedAnnotation {
analysis: analysis analysis: analysis
} as ~pprust::PpAnn: } as ~pprust::PpAnn:
@ -640,7 +640,7 @@ pub fn pretty_print_input(sess: Session,
pprust::print_crate(sess.codemap, pprust::print_crate(sess.codemap,
token::get_ident_interner(), token::get_ident_interner(),
sess.span_diagnostic, sess.span_diagnostic,
&crate, &krate,
source_name(input), source_name(input),
&mut rdr, &mut rdr,
~stdout as ~io::Writer, ~stdout as ~io::Writer,

View File

@ -456,7 +456,7 @@ pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: || -> ~str) -> T {
diagnostic::expect(sess.diagnostic(), opt, msg) diagnostic::expect(sess.diagnostic(), opt, msg)
} }
pub fn building_library(options: &Options, crate: &ast::Crate) -> bool { pub fn building_library(options: &Options, krate: &ast::Crate) -> bool {
if options.test { return false } if options.test { return false }
for output in options.crate_types.iter() { for output in options.crate_types.iter() {
match *output { match *output {
@ -464,7 +464,7 @@ pub fn building_library(options: &Options, crate: &ast::Crate) -> bool {
CrateTypeStaticlib | CrateTypeDylib | CrateTypeRlib => return true CrateTypeStaticlib | CrateTypeDylib | CrateTypeRlib => return true
} }
} }
match syntax::attr::first_attr_value_str_by_name(crate.attrs, "crate_type") { match syntax::attr::first_attr_value_str_by_name(krate.attrs, "crate_type") {
Some(s) => { Some(s) => {
s.equiv(&("lib")) || s.equiv(&("lib")) ||
s.equiv(&("rlib")) || s.equiv(&("rlib")) ||

View File

@ -24,6 +24,6 @@ impl ast_map::FoldOps for NodeIdAssigner {
} }
} }
pub fn assign_node_ids_and_map(sess: Session, crate: ast::Crate) -> (ast::Crate, ast_map::Map) { pub fn assign_node_ids_and_map(sess: Session, krate: ast::Crate) -> (ast::Crate, ast_map::Map) {
ast_map::map_crate(sess.diagnostic(), crate, NodeIdAssigner { sess: sess }) ast_map::map_crate(sess.diagnostic(), krate, NodeIdAssigner { sess: sess })
} }

View File

@ -19,9 +19,9 @@ struct Context<'a> {
// Support conditional compilation by transforming the AST, stripping out // Support conditional compilation by transforming the AST, stripping out
// any items that do not belong in the current configuration // any items that do not belong in the current configuration
pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate { pub fn strip_unconfigured_items(krate: ast::Crate) -> ast::Crate {
let config = crate.config.clone(); let config = krate.config.clone();
strip_items(crate, |attrs| in_cfg(config, attrs)) strip_items(krate, |attrs| in_cfg(config, attrs))
} }
impl<'a> fold::Folder for Context<'a> { impl<'a> fold::Folder for Context<'a> {
@ -39,13 +39,13 @@ impl<'a> fold::Folder for Context<'a> {
} }
} }
pub fn strip_items(crate: ast::Crate, pub fn strip_items(krate: ast::Crate,
in_cfg: |attrs: &[ast::Attribute]| -> bool) in_cfg: |attrs: &[ast::Attribute]| -> bool)
-> ast::Crate { -> ast::Crate {
let mut ctxt = Context { let mut ctxt = Context {
in_cfg: in_cfg, in_cfg: in_cfg,
}; };
ctxt.fold_crate(crate) ctxt.fold_crate(krate)
} }
fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem) fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem)

View File

@ -266,13 +266,13 @@ impl Visitor<()> for Context {
} }
} }
pub fn check_crate(sess: Session, crate: &ast::Crate) { pub fn check_crate(sess: Session, krate: &ast::Crate) {
let mut cx = Context { let mut cx = Context {
features: ~[], features: ~[],
sess: sess, sess: sess,
}; };
for attr in crate.attrs.iter() { for attr in krate.attrs.iter() {
if !attr.name().equiv(&("feature")) { if !attr.name().equiv(&("feature")) {
continue continue
} }
@ -315,7 +315,7 @@ pub fn check_crate(sess: Session, crate: &ast::Crate) {
} }
} }
visit::walk_crate(&mut cx, crate, ()); visit::walk_crate(&mut cx, krate, ());
sess.abort_if_errors(); sess.abort_if_errors();
} }

View File

@ -30,7 +30,7 @@ impl Visitor<()> for ShowSpanVisitor {
} }
} }
pub fn run(sess: Session, crate: &ast::Crate) { pub fn run(sess: Session, krate: &ast::Crate) {
let mut v = ShowSpanVisitor { sess: sess }; let mut v = ShowSpanVisitor { sess: sess };
visit::walk_crate(&mut v, crate, ()); visit::walk_crate(&mut v, krate, ());
} }

View File

@ -25,29 +25,29 @@ use syntax::util::small_vector::SmallVector;
pub static VERSION: &'static str = "0.10-pre"; pub static VERSION: &'static str = "0.10-pre";
pub fn maybe_inject_crates_ref(sess: Session, crate: ast::Crate) pub fn maybe_inject_crates_ref(sess: Session, krate: ast::Crate)
-> ast::Crate { -> ast::Crate {
if use_std(&crate) { if use_std(&krate) {
inject_crates_ref(sess, crate) inject_crates_ref(sess, krate)
} else { } else {
crate krate
} }
} }
pub fn maybe_inject_prelude(sess: Session, crate: ast::Crate) -> ast::Crate { pub fn maybe_inject_prelude(sess: Session, krate: ast::Crate) -> ast::Crate {
if use_std(&crate) { if use_std(&krate) {
inject_prelude(sess, crate) inject_prelude(sess, krate)
} else { } else {
crate krate
} }
} }
fn use_std(crate: &ast::Crate) -> bool { fn use_std(krate: &ast::Crate) -> bool {
!attr::contains_name(crate.attrs, "no_std") !attr::contains_name(krate.attrs, "no_std")
} }
fn use_uv(crate: &ast::Crate) -> bool { fn use_uv(krate: &ast::Crate) -> bool {
!attr::contains_name(crate.attrs, "no_uv") !attr::contains_name(krate.attrs, "no_uv")
} }
fn no_prelude(attrs: &[ast::Attribute]) -> bool { fn no_prelude(attrs: &[ast::Attribute]) -> bool {
@ -58,12 +58,12 @@ struct StandardLibraryInjector {
sess: Session, sess: Session,
} }
pub fn with_version(crate: &str) -> Option<(InternedString, ast::StrStyle)> { pub fn with_version(krate: &str) -> Option<(InternedString, ast::StrStyle)> {
match option_env!("CFG_DISABLE_INJECT_STD_VERSION") { match option_env!("CFG_DISABLE_INJECT_STD_VERSION") {
Some("1") => None, Some("1") => None,
_ => { _ => {
Some((token::intern_and_get_ident(format!("{}\\#{}", Some((token::intern_and_get_ident(format!("{}\\#{}",
crate, krate,
VERSION)), VERSION)),
ast::CookedStr)) ast::CookedStr))
} }
@ -71,7 +71,7 @@ pub fn with_version(crate: &str) -> Option<(InternedString, ast::StrStyle)> {
} }
impl fold::Folder for StandardLibraryInjector { impl fold::Folder for StandardLibraryInjector {
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate { fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate {
let mut vis = ~[ast::ViewItem { let mut vis = ~[ast::ViewItem {
node: ast::ViewItemExternMod(self.sess.ident_of("std"), node: ast::ViewItemExternMod(self.sess.ident_of("std"),
with_version("std"), with_version("std"),
@ -88,7 +88,7 @@ impl fold::Folder for StandardLibraryInjector {
span: DUMMY_SP span: DUMMY_SP
}]; }];
if use_uv(&crate) && !self.sess.building_library.get() { if use_uv(&krate) && !self.sess.building_library.get() {
vis.push(ast::ViewItem { vis.push(ast::ViewItem {
node: ast::ViewItemExternMod(self.sess.ident_of("green"), node: ast::ViewItemExternMod(self.sess.ident_of("green"),
with_version("green"), with_version("green"),
@ -107,24 +107,24 @@ impl fold::Folder for StandardLibraryInjector {
}); });
} }
vis.push_all(crate.module.view_items); vis.push_all(krate.module.view_items);
let new_module = ast::Mod { let new_module = ast::Mod {
view_items: vis, view_items: vis,
..crate.module.clone() ..krate.module.clone()
}; };
ast::Crate { ast::Crate {
module: new_module, module: new_module,
..crate ..krate
} }
} }
} }
fn inject_crates_ref(sess: Session, crate: ast::Crate) -> ast::Crate { fn inject_crates_ref(sess: Session, krate: ast::Crate) -> ast::Crate {
let mut fold = StandardLibraryInjector { let mut fold = StandardLibraryInjector {
sess: sess, sess: sess,
}; };
fold.fold_crate(crate) fold.fold_crate(krate)
} }
struct PreludeInjector { struct PreludeInjector {
@ -133,16 +133,16 @@ struct PreludeInjector {
impl fold::Folder for PreludeInjector { impl fold::Folder for PreludeInjector {
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate { fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate {
if !no_prelude(crate.attrs) { if !no_prelude(krate.attrs) {
// only add `use std::prelude::*;` if there wasn't a // only add `use std::prelude::*;` if there wasn't a
// `#[no_implicit_prelude];` at the crate level. // `#[no_implicit_prelude];` at the crate level.
ast::Crate { ast::Crate {
module: self.fold_mod(&crate.module), module: self.fold_mod(&krate.module),
..crate ..krate
} }
} else { } else {
crate krate
} }
} }
@ -194,9 +194,9 @@ impl fold::Folder for PreludeInjector {
} }
} }
fn inject_prelude(sess: Session, crate: ast::Crate) -> ast::Crate { fn inject_prelude(sess: Session, krate: ast::Crate) -> ast::Crate {
let mut fold = PreludeInjector { let mut fold = PreludeInjector {
sess: sess, sess: sess,
}; };
fold.fold_crate(crate) fold.fold_crate(krate)
} }

View File

@ -53,16 +53,16 @@ struct TestCtxt<'a> {
// Traverse the crate, collecting all the test functions, eliding any // Traverse the crate, collecting all the test functions, eliding any
// existing main functions, and synthesizing a main test harness // existing main functions, and synthesizing a main test harness
pub fn modify_for_testing(sess: session::Session, pub fn modify_for_testing(sess: session::Session,
crate: ast::Crate) -> ast::Crate { krate: ast::Crate) -> ast::Crate {
// We generate the test harness when building in the 'test' // We generate the test harness when building in the 'test'
// configuration, either with the '--test' or '--cfg test' // configuration, either with the '--test' or '--cfg test'
// command line options. // command line options.
let should_test = attr::contains_name(crate.config, "test"); let should_test = attr::contains_name(krate.config, "test");
if should_test { if should_test {
generate_test_harness(sess, crate) generate_test_harness(sess, krate)
} else { } else {
strip_test_functions(crate) strip_test_functions(krate)
} }
} }
@ -156,7 +156,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
} }
} }
fn generate_test_harness(sess: session::Session, crate: ast::Crate) fn generate_test_harness(sess: session::Session, krate: ast::Crate)
-> ast::Crate { -> ast::Crate {
let loader = &mut Loader::new(sess); let loader = &mut Loader::new(sess);
let mut cx: TestCtxt = TestCtxt { let mut cx: TestCtxt = TestCtxt {
@ -164,8 +164,8 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone(), loader), ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone(), loader),
path: RefCell::new(~[]), path: RefCell::new(~[]),
testfns: RefCell::new(~[]), testfns: RefCell::new(~[]),
is_extra: is_extra(&crate), is_extra: is_extra(&krate),
config: crate.config.clone(), config: krate.config.clone(),
}; };
cx.ext_cx.bt_push(ExpnInfo { cx.ext_cx.bt_push(ExpnInfo {
@ -180,15 +180,15 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
let mut fold = TestHarnessGenerator { let mut fold = TestHarnessGenerator {
cx: cx cx: cx
}; };
let res = fold.fold_crate(crate); let res = fold.fold_crate(krate);
fold.cx.ext_cx.bt_pop(); fold.cx.ext_cx.bt_pop();
return res; return res;
} }
fn strip_test_functions(crate: ast::Crate) -> ast::Crate { fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
// When not compiling with --test we should not compile the // When not compiling with --test we should not compile the
// #[test] functions // #[test] functions
config::strip_items(crate, |attrs| { config::strip_items(krate, |attrs| {
!attr::contains_name(attrs, "test") && !attr::contains_name(attrs, "test") &&
!attr::contains_name(attrs, "bench") !attr::contains_name(attrs, "bench")
}) })
@ -390,8 +390,8 @@ fn mk_tests(cx: &TestCtxt) -> @ast::Item {
)).unwrap() )).unwrap()
} }
fn is_extra(crate: &ast::Crate) -> bool { fn is_extra(krate: &ast::Crate) -> bool {
match attr::find_crateid(crate.attrs) { match attr::find_crateid(krate.attrs) {
Some(ref s) if "extra" == s.name => true, Some(ref s) if "extra" == s.name => true,
_ => false _ => false
} }

View File

@ -35,7 +35,7 @@ use syntax::visit;
// Traverses an AST, reading all the information about use'd crates and extern // Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc. // libraries necessary for later resolving, typechecking, linking, etc.
pub fn read_crates(sess: Session, pub fn read_crates(sess: Session,
crate: &ast::Crate, krate: &ast::Crate,
os: loader::Os, os: loader::Os,
intr: @IdentInterner) { intr: @IdentInterner) {
let mut e = Env { let mut e = Env {
@ -45,12 +45,12 @@ pub fn read_crates(sess: Session,
next_crate_num: 1, next_crate_num: 1,
intr: intr intr: intr
}; };
visit_crate(&e, crate); visit_crate(&e, krate);
{ {
let mut v = ReadCrateVisitor { let mut v = ReadCrateVisitor {
e: &mut e e: &mut e
}; };
visit::walk_crate(&mut v, crate, ()); visit::walk_crate(&mut v, krate, ());
} }
let crate_cache = e.crate_cache.borrow(); let crate_cache = e.crate_cache.borrow();
dump_crates(*crate_cache.get()); dump_crates(*crate_cache.get());
@ -424,14 +424,14 @@ impl Loader {
} }
impl CrateLoader for Loader { impl CrateLoader for Loader {
fn load_crate(&mut self, crate: &ast::ViewItem) -> MacroCrate { fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
let info = extract_crate_info(crate).unwrap(); let info = extract_crate_info(krate).unwrap();
let cnum = resolve_crate(&mut self.env, let cnum = resolve_crate(&mut self.env,
info.ident.clone(), info.ident.clone(),
info.name.clone(), info.name.clone(),
info.version.clone(), info.version.clone(),
~"", ~"",
crate.span); krate.span);
let library = self.env.sess.cstore.get_used_crate_source(cnum).unwrap(); let library = self.env.sess.cstore.get_used_crate_source(cnum).unwrap();
MacroCrate { MacroCrate {
lib: library.dylib, lib: library.dylib,

View File

@ -32,13 +32,13 @@ pub struct StaticMethodInfo {
} }
pub fn get_symbol(cstore: @cstore::CStore, def: ast::DefId) -> ~str { pub fn get_symbol(cstore: @cstore::CStore, def: ast::DefId) -> ~str {
let cdata = cstore.get_crate_data(def.crate).data(); let cdata = cstore.get_crate_data(def.krate).data();
return decoder::get_symbol(cdata, def.node); return decoder::get_symbol(cdata, def.node);
} }
pub fn get_type_param_count(cstore: @cstore::CStore, def: ast::DefId) pub fn get_type_param_count(cstore: @cstore::CStore, def: ast::DefId)
-> uint { -> uint {
let cdata = cstore.get_crate_data(def.crate).data(); let cdata = cstore.get_crate_data(def.krate).data();
return decoder::get_type_param_count(cdata, def.node); return decoder::get_type_param_count(cdata, def.node);
} }
@ -57,7 +57,7 @@ pub fn each_child_of_item(cstore: @cstore::CStore,
callback: |decoder::DefLike, callback: |decoder::DefLike,
ast::Ident, ast::Ident,
ast::Visibility|) { ast::Visibility|) {
let crate_data = cstore.get_crate_data(def_id.crate); let crate_data = cstore.get_crate_data(def_id.krate);
let get_crate_data: decoder::GetCrateDataCb = |cnum| { let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore.get_crate_data(cnum) cstore.get_crate_data(cnum)
}; };
@ -86,7 +86,7 @@ pub fn each_top_level_item_of_crate(cstore: @cstore::CStore,
pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ast_map::Path { pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ast_map::Path {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
let path = decoder::get_item_path(cdata, def.node); let path = decoder::get_item_path(cdata, def.node);
// FIXME #1920: This path is not always correct if the crate is not linked // FIXME #1920: This path is not always correct if the crate is not linked
@ -108,7 +108,7 @@ pub fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::DefId,
decode_inlined_item: decoder::decode_inlined_item) decode_inlined_item: decoder::decode_inlined_item)
-> found_ast { -> found_ast {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::maybe_get_item_ast(cdata, tcx, def.node, decoder::maybe_get_item_ast(cdata, tcx, def.node,
decode_inlined_item) decode_inlined_item)
} }
@ -116,19 +116,19 @@ pub fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::DefId,
pub fn get_enum_variants(tcx: ty::ctxt, def: ast::DefId) pub fn get_enum_variants(tcx: ty::ctxt, def: ast::DefId)
-> ~[@ty::VariantInfo] { -> ~[@ty::VariantInfo] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx) return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx)
} }
/// Returns information about the given implementation. /// Returns information about the given implementation.
pub fn get_impl(tcx: ty::ctxt, impl_def_id: ast::DefId) pub fn get_impl(tcx: ty::ctxt, impl_def_id: ast::DefId)
-> ty::Impl { -> ty::Impl {
let cdata = tcx.cstore.get_crate_data(impl_def_id.crate); let cdata = tcx.cstore.get_crate_data(impl_def_id.krate);
decoder::get_impl(tcx.cstore.intr, cdata, impl_def_id.node, tcx) decoder::get_impl(tcx.cstore.intr, cdata, impl_def_id.node, tcx)
} }
pub fn get_method(tcx: ty::ctxt, def: ast::DefId) -> ty::Method { pub fn get_method(tcx: ty::ctxt, def: ast::DefId) -> ty::Method {
let cdata = tcx.cstore.get_crate_data(def.crate); let cdata = tcx.cstore.get_crate_data(def.krate);
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx) decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)
} }
@ -136,19 +136,19 @@ pub fn get_method_name_and_explicit_self(cstore: @cstore::CStore,
def: ast::DefId) def: ast::DefId)
-> (ast::Ident, ast::ExplicitSelf_) -> (ast::Ident, ast::ExplicitSelf_)
{ {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node) decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
} }
pub fn get_trait_method_def_ids(cstore: @cstore::CStore, pub fn get_trait_method_def_ids(cstore: @cstore::CStore,
def: ast::DefId) -> ~[ast::DefId] { def: ast::DefId) -> ~[ast::DefId] {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_method_def_ids(cdata, def.node) decoder::get_trait_method_def_ids(cdata, def.node)
} }
pub fn get_item_variances(cstore: @cstore::CStore, pub fn get_item_variances(cstore: @cstore::CStore,
def: ast::DefId) -> ty::ItemVariances { def: ast::DefId) -> ty::ItemVariances {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_item_variances(cdata, def.node) decoder::get_item_variances(cdata, def.node)
} }
@ -156,40 +156,40 @@ pub fn get_provided_trait_methods(tcx: ty::ctxt,
def: ast::DefId) def: ast::DefId)
-> ~[@ty::Method] { -> ~[@ty::Method] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx) decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
} }
pub fn get_supertraits(tcx: ty::ctxt, def: ast::DefId) -> ~[@ty::TraitRef] { pub fn get_supertraits(tcx: ty::ctxt, def: ast::DefId) -> ~[@ty::TraitRef] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_supertraits(cdata, def.node, tcx) decoder::get_supertraits(cdata, def.node, tcx)
} }
pub fn get_type_name_if_impl(cstore: @cstore::CStore, def: ast::DefId) pub fn get_type_name_if_impl(cstore: @cstore::CStore, def: ast::DefId)
-> Option<ast::Ident> { -> Option<ast::Ident> {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_type_name_if_impl(cdata, def.node) decoder::get_type_name_if_impl(cdata, def.node)
} }
pub fn get_static_methods_if_impl(cstore: @cstore::CStore, pub fn get_static_methods_if_impl(cstore: @cstore::CStore,
def: ast::DefId) def: ast::DefId)
-> Option<~[StaticMethodInfo]> { -> Option<~[StaticMethodInfo]> {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node) decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node)
} }
pub fn get_item_attrs(cstore: @cstore::CStore, pub fn get_item_attrs(cstore: @cstore::CStore,
def_id: ast::DefId, def_id: ast::DefId,
f: |~[@ast::MetaItem]|) { f: |~[@ast::MetaItem]|) {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_item_attrs(cdata, def_id.node, f) decoder::get_item_attrs(cdata, def_id.node, f)
} }
pub fn get_struct_fields(cstore: @cstore::CStore, pub fn get_struct_fields(cstore: @cstore::CStore,
def: ast::DefId) def: ast::DefId)
-> ~[ty::field_ty] { -> ~[ty::field_ty] {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_struct_fields(cstore.intr, cdata, def.node) decoder::get_struct_fields(cstore.intr, cdata, def.node)
} }
@ -197,20 +197,20 @@ pub fn get_type(tcx: ty::ctxt,
def: ast::DefId) def: ast::DefId)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_type(cdata, def.node, tcx) decoder::get_type(cdata, def.node, tcx)
} }
pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef { pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_def(cdata, def.node, tcx) decoder::get_trait_def(cdata, def.node, tcx)
} }
pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId, pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
def: ast::DefId) -> ty::ty_param_bounds_and_ty { def: ast::DefId) -> ty::ty_param_bounds_and_ty {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(class_id.crate); let cdata = cstore.get_crate_data(class_id.krate);
let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items); let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
let class_doc = expect(tcx.diag, let class_doc = expect(tcx.diag,
decoder::maybe_find_item(class_id.node, all_items), decoder::maybe_find_item(class_id.node, all_items),
@ -233,7 +233,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
pub fn get_impl_trait(tcx: ty::ctxt, pub fn get_impl_trait(tcx: ty::ctxt,
def: ast::DefId) -> Option<@ty::TraitRef> { def: ast::DefId) -> Option<@ty::TraitRef> {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_trait(cdata, def.node, tcx) decoder::get_impl_trait(cdata, def.node, tcx)
} }
@ -241,7 +241,7 @@ pub fn get_impl_trait(tcx: ty::ctxt,
pub fn get_impl_vtables(tcx: ty::ctxt, pub fn get_impl_vtables(tcx: ty::ctxt,
def: ast::DefId) -> typeck::impl_res { def: ast::DefId) -> typeck::impl_res {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_vtables(cdata, def.node, tcx) decoder::get_impl_vtables(cdata, def.node, tcx)
} }
@ -249,14 +249,14 @@ pub fn get_impl_method(cstore: @cstore::CStore,
def: ast::DefId, def: ast::DefId,
mname: ast::Ident) mname: ast::Ident)
-> Option<ast::DefId> { -> Option<ast::DefId> {
let cdata = cstore.get_crate_data(def.crate); let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_method(cstore.intr, cdata, def.node, mname) decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
} }
pub fn get_item_visibility(cstore: @cstore::CStore, pub fn get_item_visibility(cstore: @cstore::CStore,
def_id: ast::DefId) def_id: ast::DefId)
-> ast::Visibility { -> ast::Visibility {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_item_visibility(cdata, def_id.node) decoder::get_item_visibility(cdata, def_id.node)
} }
@ -277,14 +277,14 @@ pub fn each_impl(cstore: @cstore::CStore,
pub fn each_implementation_for_type(cstore: @cstore::CStore, pub fn each_implementation_for_type(cstore: @cstore::CStore,
def_id: ast::DefId, def_id: ast::DefId,
callback: |ast::DefId|) { callback: |ast::DefId|) {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.krate);
decoder::each_implementation_for_type(cdata, def_id.node, callback) decoder::each_implementation_for_type(cdata, def_id.node, callback)
} }
pub fn each_implementation_for_trait(cstore: @cstore::CStore, pub fn each_implementation_for_trait(cstore: @cstore::CStore,
def_id: ast::DefId, def_id: ast::DefId,
callback: |ast::DefId|) { callback: |ast::DefId|) {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.krate);
decoder::each_implementation_for_trait(cdata, def_id.node, callback) decoder::each_implementation_for_trait(cdata, def_id.node, callback)
} }
@ -295,7 +295,7 @@ pub fn get_trait_of_method(cstore: @cstore::CStore,
def_id: ast::DefId, def_id: ast::DefId,
tcx: ty::ctxt) tcx: ty::ctxt)
-> Option<ast::DefId> { -> Option<ast::DefId> {
let cdata = cstore.get_crate_data(def_id.crate); let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_trait_of_method(cdata, def_id.node, tcx) decoder::get_trait_of_method(cdata, def_id.node, tcx)
} }

View File

@ -191,7 +191,7 @@ fn item_parent_item(d: ebml::Doc) -> Option<ast::DefId> {
fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum, fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum,
d: ebml::Doc) -> ast::DefId { d: ebml::Doc) -> ast::DefId {
let trait_did = item_parent_item(d).expect("item without parent"); let trait_did = item_parent_item(d).expect("item without parent");
ast::DefId { crate: cnum, node: trait_did.node } ast::DefId { krate: cnum, node: trait_did.node }
} }
fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId { fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId {
@ -290,7 +290,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] {
let v = tag_items_data_item_variant; let v = tag_items_data_item_variant;
reader::tagged_docs(item, v, |p| { reader::tagged_docs(item, v, |p| {
let ext = reader::with_doc_data(p, parse_def_id); let ext = reader::with_doc_data(p, parse_def_id);
ids.push(ast::DefId { crate: cdata.cnum, node: ext.node }); ids.push(ast::DefId { krate: cdata.cnum, node: ext.node });
true true
}); });
return ids; return ids;
@ -386,7 +386,7 @@ pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
pub fn lookup_def(cnum: ast::CrateNum, data: &[u8], did_: ast::DefId) -> pub fn lookup_def(cnum: ast::CrateNum, data: &[u8], did_: ast::DefId) ->
ast::Def { ast::Def {
let item = lookup_item(did_.node, data); let item = lookup_item(did_.node, data);
let did = ast::DefId { crate: cnum, node: did_.node }; let did = ast::DefId { krate: cnum, node: did_.node };
// We treat references to enums as references to types. // We treat references to enums as references to types.
return def_like_to_def(item_to_def_like(item, did, cnum)); return def_like_to_def(item_to_def_like(item, did, cnum));
} }
@ -423,7 +423,7 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
let item = lookup_item(id, cdata.data()); let item = lookup_item(id, cdata.data());
let t = item_type(ast::DefId { crate: cdata.cnum, node: id }, item, tcx, let t = item_type(ast::DefId { krate: cdata.cnum, node: id }, item, tcx,
cdata); cdata);
let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds); let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
@ -529,10 +529,10 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
// This item may be in yet another crate if it was the child of a // This item may be in yet another crate if it was the child of a
// reexport. // reexport.
let other_crates_items = if child_def_id.crate == cdata.cnum { let other_crates_items = if child_def_id.krate == cdata.cnum {
reader::get_doc(reader::Doc(cdata.data()), tag_items) reader::get_doc(reader::Doc(cdata.data()), tag_items)
} else { } else {
let crate_data = get_crate_data(child_def_id.crate); let crate_data = get_crate_data(child_def_id.krate);
reader::get_doc(reader::Doc(crate_data.data()), tag_items) reader::get_doc(reader::Doc(crate_data.data()), tag_items)
}; };
@ -617,10 +617,10 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
let name = name_doc.as_str_slice(); let name = name_doc.as_str_slice();
// This reexport may be in yet another crate. // This reexport may be in yet another crate.
let other_crates_items = if child_def_id.crate == cdata.cnum { let other_crates_items = if child_def_id.krate == cdata.cnum {
reader::get_doc(reader::Doc(cdata.data()), tag_items) reader::get_doc(reader::Doc(cdata.data()), tag_items)
} else { } else {
let crate_data = get_crate_data(child_def_id.crate); let crate_data = get_crate_data(child_def_id.krate);
reader::get_doc(reader::Doc(crate_data.data()), tag_items) reader::get_doc(reader::Doc(crate_data.data()), tag_items)
}; };
@ -730,7 +730,7 @@ pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
let mut disr_val = 0; let mut disr_val = 0;
for did in variant_ids.iter() { for did in variant_ids.iter() {
let item = find_item(did.node, items); let item = find_item(did.node, items);
let ctor_ty = item_type(ast::DefId { crate: cdata.cnum, node: id}, let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
item, tcx, cdata); item, tcx, cdata);
let name = item_name(intr, item); let name = item_name(intr, item);
let arg_tys = match ty::get(ctor_ty).sty { let arg_tys = match ty::get(ctor_ty).sty {
@ -799,7 +799,7 @@ pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
let impl_item = lookup_item(impl_id, data); let impl_item = lookup_item(impl_id, data);
ty::Impl { ty::Impl {
did: ast::DefId { did: ast::DefId {
crate: cdata.cnum, krate: cdata.cnum,
node: impl_id, node: impl_id,
}, },
ident: item_name(intr, impl_item), ident: item_name(intr, impl_item),
@ -1199,15 +1199,15 @@ pub fn list_crate_metadata(intr: @IdentInterner, bytes: &[u8],
// then we must translate the crate number from that encoded in the external // then we must translate the crate number from that encoded in the external
// crate to the correct local crate number. // crate to the correct local crate number.
pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
if did.crate == ast::LOCAL_CRATE { if did.krate == ast::LOCAL_CRATE {
return ast::DefId { crate: cdata.cnum, node: did.node }; return ast::DefId { krate: cdata.cnum, node: did.node };
} }
let cnum_map = cdata.cnum_map.borrow(); let cnum_map = cdata.cnum_map.borrow();
match cnum_map.get().find(&did.crate) { match cnum_map.get().find(&did.krate) {
Some(&n) => { Some(&n) => {
ast::DefId { ast::DefId {
crate: n, krate: n,
node: did.node, node: did.node,
} }
} }

View File

@ -167,7 +167,7 @@ fn encode_family(ebml_w: &mut writer::Encoder, c: char) {
} }
pub fn def_to_str(did: DefId) -> ~str { pub fn def_to_str(did: DefId) -> ~str {
format!("{}:{}", did.crate, did.node) format!("{}:{}", did.krate, did.node)
} }
fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder, fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder,
@ -344,7 +344,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
let mut disr_val = 0; let mut disr_val = 0;
let mut i = 0; let mut i = 0;
let vi = ty::enum_variants(ecx.tcx, let vi = ty::enum_variants(ecx.tcx,
ast::DefId { crate: LOCAL_CRATE, node: id }); ast::DefId { krate: LOCAL_CRATE, node: id });
for variant in variants.iter() { for variant in variants.iter() {
let def_id = local_def(variant.node.id); let def_id = local_def(variant.node.id);
{ {
@ -568,7 +568,7 @@ fn encode_reexports(ecx: &EncodeContext,
debug!("(encoding info for module) reexport '{}' ({}/{}) for \ debug!("(encoding info for module) reexport '{}' ({}/{}) for \
{}", {}",
exp.name, exp.name,
exp.def_id.crate, exp.def_id.krate,
exp.def_id.node, exp.def_id.node,
id); id);
ebml_w.start_tag(tag_items_data_item_reexport); ebml_w.start_tag(tag_items_data_item_reexport);
@ -1210,7 +1210,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// Now output the method info for each method. // Now output the method info for each method.
let r = ty::trait_method_def_ids(tcx, def_id); let r = ty::trait_method_def_ids(tcx, def_id);
for (i, &method_def_id) in r.iter().enumerate() { for (i, &method_def_id) in r.iter().enumerate() {
assert_eq!(method_def_id.crate, ast::LOCAL_CRATE); assert_eq!(method_def_id.krate, ast::LOCAL_CRATE);
let method_ty = ty::method(tcx, method_def_id); let method_ty = ty::method(tcx, method_def_id);
@ -1409,7 +1409,7 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> {
fn encode_info_for_items(ecx: &EncodeContext, fn encode_info_for_items(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder, ebml_w: &mut writer::Encoder,
crate: &Crate) krate: &Crate)
-> ~[entry<i64>] { -> ~[entry<i64>] {
let index = @RefCell::new(~[]); let index = @RefCell::new(~[]);
ebml_w.start_tag(tag_items_data); ebml_w.start_tag(tag_items_data);
@ -1422,7 +1422,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
} }
encode_info_for_mod(ecx, encode_info_for_mod(ecx,
ebml_w, ebml_w,
&crate.module, &krate.module,
CRATE_NODE_ID, CRATE_NODE_ID,
[], [],
syntax::parse::token::special_idents::invalid, syntax::parse::token::special_idents::invalid,
@ -1439,7 +1439,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
ebml_w_for_visit_item: &mut *ebml_w, ebml_w_for_visit_item: &mut *ebml_w,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
ebml_w.end_tag(); ebml_w.end_tag();
@ -1559,7 +1559,7 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[Attribute]) {
// metadata that Rust cares about for linking crates. If the user didn't // metadata that Rust cares about for linking crates. If the user didn't
// provide it we will throw it in anyway with a default value. // provide it we will throw it in anyway with a default value.
fn synthesize_crate_attrs(ecx: &EncodeContext, fn synthesize_crate_attrs(ecx: &EncodeContext,
crate: &Crate) -> ~[Attribute] { krate: &Crate) -> ~[Attribute] {
fn synthesize_crateid_attr(ecx: &EncodeContext) -> Attribute { fn synthesize_crateid_attr(ecx: &EncodeContext) -> Attribute {
assert!(!ecx.link_meta.crateid.name.is_empty()); assert!(!ecx.link_meta.crateid.name.is_empty());
@ -1571,7 +1571,7 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
} }
let mut attrs = ~[]; let mut attrs = ~[];
for attr in crate.attrs.iter() { for attr in krate.attrs.iter() {
if !attr.name().equiv(&("crate_id")) { if !attr.name().equiv(&("crate_id")) {
attrs.push(*attr); attrs.push(*attr);
} }
@ -1628,7 +1628,7 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
for (i, def_id) in ecx.tcx.lang_items.items() { for (i, def_id) in ecx.tcx.lang_items.items() {
for id in def_id.iter() { for id in def_id.iter() {
if id.crate == LOCAL_CRATE { if id.krate == LOCAL_CRATE {
ebml_w.start_tag(tag_lang_items_item); ebml_w.start_tag(tag_lang_items_item);
ebml_w.start_tag(tag_lang_items_item_id); ebml_w.start_tag(tag_lang_items_item_id);
@ -1714,7 +1714,7 @@ impl<'a, 'b> Visitor<()> for MacroDefVisitor<'a, 'b> {
} }
fn encode_macro_defs(ecx: &EncodeContext, fn encode_macro_defs(ecx: &EncodeContext,
crate: &Crate, krate: &Crate,
ebml_w: &mut writer::Encoder) { ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_exported_macros); ebml_w.start_tag(tag_exported_macros);
{ {
@ -1722,7 +1722,7 @@ fn encode_macro_defs(ecx: &EncodeContext,
ecx: ecx, ecx: ecx,
ebml_w: ebml_w, ebml_w: ebml_w,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
ebml_w.end_tag(); ebml_w.end_tag();
} }
@ -1744,7 +1744,7 @@ impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> {
// Load eagerly if this is an implementation of the Drop trait // Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate. // or if the trait is not defined in this crate.
if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() || if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() ||
def_id.crate != LOCAL_CRATE { def_id.krate != LOCAL_CRATE {
self.ebml_w.start_tag(tag_impls_impl); self.ebml_w.start_tag(tag_impls_impl);
encode_def_id(self.ebml_w, local_def(item.id)); encode_def_id(self.ebml_w, local_def(item.id));
self.ebml_w.end_tag(); self.ebml_w.end_tag();
@ -1767,7 +1767,7 @@ impl<'a,'b> Visitor<()> for ImplVisitor<'a,'b> {
/// ///
/// * Implementations of traits not defined in this crate. /// * Implementations of traits not defined in this crate.
fn encode_impls(ecx: &EncodeContext, fn encode_impls(ecx: &EncodeContext,
crate: &Crate, krate: &Crate,
ebml_w: &mut writer::Encoder) { ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_impls); ebml_w.start_tag(tag_impls);
@ -1776,18 +1776,18 @@ fn encode_impls(ecx: &EncodeContext,
ecx: ecx, ecx: ecx,
ebml_w: ebml_w, ebml_w: ebml_w,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn encode_misc_info(ecx: &EncodeContext, fn encode_misc_info(ecx: &EncodeContext,
crate: &Crate, krate: &Crate,
ebml_w: &mut writer::Encoder) { ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_misc_info); ebml_w.start_tag(tag_misc_info);
ebml_w.start_tag(tag_misc_info_crate_items); ebml_w.start_tag(tag_misc_info_crate_items);
for &item in crate.module.items.iter() { for &item in krate.module.items.iter() {
ebml_w.start_tag(tag_mod_child); ebml_w.start_tag(tag_mod_child);
ebml_w.wr_str(def_to_str(local_def(item.id))); ebml_w.wr_str(def_to_str(local_def(item.id)));
ebml_w.end_tag(); ebml_w.end_tag();
@ -1838,13 +1838,13 @@ pub static metadata_encoding_version : &'static [u8] =
0x74, //'t' as u8, 0x74, //'t' as u8,
0, 0, 0, 1 ]; 0, 0, 0, 1 ];
pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] { pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> ~[u8] {
let mut wr = MemWriter::new(); let mut wr = MemWriter::new();
encode_metadata_inner(&mut wr, parms, crate); encode_metadata_inner(&mut wr, parms, krate);
wr.unwrap() wr.unwrap()
} }
fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, crate: &Crate) { fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) {
let stats = Stats { let stats = Stats {
inline_bytes: Cell::new(0), inline_bytes: Cell::new(0),
attr_bytes: Cell::new(0), attr_bytes: Cell::new(0),
@ -1895,7 +1895,7 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, crate: &Crate)
encode_hash(&mut ebml_w, ecx.link_meta.crate_hash); encode_hash(&mut ebml_w, ecx.link_meta.crate_hash);
let mut i = ebml_w.writer.tell().unwrap(); let mut i = ebml_w.writer.tell().unwrap();
let crate_attrs = synthesize_crate_attrs(&ecx, crate); let crate_attrs = synthesize_crate_attrs(&ecx, krate);
encode_attributes(&mut ebml_w, crate_attrs); encode_attributes(&mut ebml_w, crate_attrs);
ecx.stats.attr_bytes.set(ebml_w.writer.tell().unwrap() - i); ecx.stats.attr_bytes.set(ebml_w.writer.tell().unwrap() - i);
@ -1920,23 +1920,23 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, crate: &Crate)
// Encode macro definitions // Encode macro definitions
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_macro_defs(&ecx, crate, &mut ebml_w); encode_macro_defs(&ecx, krate, &mut ebml_w);
ecx.stats.macro_defs_bytes.set(ebml_w.writer.tell().unwrap() - i); ecx.stats.macro_defs_bytes.set(ebml_w.writer.tell().unwrap() - i);
// Encode the def IDs of impls, for coherence checking. // Encode the def IDs of impls, for coherence checking.
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_impls(&ecx, crate, &mut ebml_w); encode_impls(&ecx, krate, &mut ebml_w);
ecx.stats.impl_bytes.set(ebml_w.writer.tell().unwrap() - i); ecx.stats.impl_bytes.set(ebml_w.writer.tell().unwrap() - i);
// Encode miscellaneous info. // Encode miscellaneous info.
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_misc_info(&ecx, crate, &mut ebml_w); encode_misc_info(&ecx, krate, &mut ebml_w);
ecx.stats.misc_bytes.set(ebml_w.writer.tell().unwrap() - i); ecx.stats.misc_bytes.set(ebml_w.writer.tell().unwrap() - i);
// Encode and index the items. // Encode and index the items.
ebml_w.start_tag(tag_items); ebml_w.start_tag(tag_items);
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
let items_index = encode_info_for_items(&ecx, &mut ebml_w, crate); let items_index = encode_info_for_items(&ecx, &mut ebml_w, krate);
ecx.stats.item_bytes.set(ebml_w.writer.tell().unwrap() - i); ecx.stats.item_bytes.set(ebml_w.writer.tell().unwrap() - i);
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();

View File

@ -57,7 +57,7 @@ type conv_did<'a> =
pub struct PState<'a> { pub struct PState<'a> {
data: &'a [u8], data: &'a [u8],
crate: ast::CrateNum, krate: ast::CrateNum,
pos: uint, pos: uint,
tcx: ty::ctxt tcx: ty::ctxt
} }
@ -106,7 +106,7 @@ pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum,
pos: uint, tcx: ty::ctxt) -> PState<'a> { pos: uint, tcx: ty::ctxt) -> PState<'a> {
PState { PState {
data: data, data: data,
crate: crate_num, krate: crate_num,
pos: pos, pos: pos,
tcx: tcx tcx: tcx
} }
@ -377,7 +377,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
assert_eq!(next(st), ':'); assert_eq!(next(st), ':');
let len = parse_hex(st); let len = parse_hex(st);
assert_eq!(next(st), '#'); assert_eq!(next(st), '#');
let key = ty::creader_cache_key {cnum: st.crate, let key = ty::creader_cache_key {cnum: st.krate,
pos: pos, pos: pos,
len: len }; len: len };
@ -559,7 +559,7 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
None => fail!("internal error: parse_def_id: id expected, but found {:?}", None => fail!("internal error: parse_def_id: id expected, but found {:?}",
def_part) def_part)
}; };
ast::DefId { crate: crate_num, node: def_num } ast::DefId { krate: crate_num, node: def_num }
} }
pub fn parse_type_param_def_data(data: &[u8], start: uint, pub fn parse_type_param_def_data(data: &[u8], start: uint,

View File

@ -236,8 +236,8 @@ impl ExtendedDecodeContext {
* refer to the current crate and to the new, inlined node-id. * refer to the current crate and to the new, inlined node-id.
*/ */
assert_eq!(did.crate, ast::LOCAL_CRATE); assert_eq!(did.krate, ast::LOCAL_CRATE);
ast::DefId { crate: ast::LOCAL_CRATE, node: self.tr_id(did.node) } ast::DefId { krate: ast::LOCAL_CRATE, node: self.tr_id(did.node) }
} }
pub fn tr_span(&self, _span: Span) -> Span { pub fn tr_span(&self, _span: Span) -> Span {
codemap::DUMMY_SP // FIXME (#1972): handle span properly codemap::DUMMY_SP // FIXME (#1972): handle span properly
@ -989,7 +989,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
} }
} }
let lid = ast::DefId { crate: ast::LOCAL_CRATE, node: id }; let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
{ {
let tcache = tcx.tcache.borrow(); let tcache = tcx.tcache.borrow();
let r = tcache.get().find(&lid); let r = tcache.get().find(&lid);
@ -1350,7 +1350,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
} }
c::tag_table_tcache => { c::tag_table_tcache => {
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx); let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
let lid = ast::DefId { crate: ast::LOCAL_CRATE, node: id }; let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
let mut tcache = dcx.tcx.tcache.borrow_mut(); let mut tcache = dcx.tcx.tcache.borrow_mut();
tcache.get().insert(lid, tpbt); tcache.get().insert(lid, tpbt);
} }

View File

@ -73,7 +73,7 @@ pub fn check_crate(tcx: ty::ctxt,
moves_map: moves::MovesMap, moves_map: moves::MovesMap,
moved_variables_set: moves::MovedVariablesSet, moved_variables_set: moves::MovedVariablesSet,
capture_map: moves::CaptureMap, capture_map: moves::CaptureMap,
crate: &ast::Crate) krate: &ast::Crate)
-> root_map { -> root_map {
let mut bccx = BorrowckCtxt { let mut bccx = BorrowckCtxt {
tcx: tcx, tcx: tcx,
@ -91,7 +91,7 @@ pub fn check_crate(tcx: ty::ctxt,
}; };
let bccx = &mut bccx; let bccx = &mut bccx;
visit::walk_crate(bccx, crate, ()); visit::walk_crate(bccx, krate, ());
if tcx.sess.borrowck_stats() { if tcx.sess.borrowck_stats() {
println!("--- borrowck stats ---"); println!("--- borrowck stats ---");

View File

@ -42,7 +42,7 @@ impl Visitor<bool> for CheckCrateVisitor {
} }
pub fn check_crate(sess: Session, pub fn check_crate(sess: Session,
crate: &Crate, krate: &Crate,
ast_map: ast_map::Map, ast_map: ast_map::Map,
def_map: resolve::DefMap, def_map: resolve::DefMap,
method_map: typeck::method_map, method_map: typeck::method_map,
@ -54,7 +54,7 @@ pub fn check_crate(sess: Session,
method_map: method_map, method_map: method_map,
tcx: tcx, tcx: tcx,
}; };
visit::walk_crate(&mut v, crate, false); visit::walk_crate(&mut v, krate, false);
sess.abort_if_errors(); sess.abort_if_errors();
} }

View File

@ -24,8 +24,8 @@ struct CheckLoopVisitor {
tcx: ty::ctxt, tcx: ty::ctxt,
} }
pub fn check_crate(tcx: ty::ctxt, crate: &ast::Crate) { pub fn check_crate(tcx: ty::ctxt, krate: &ast::Crate) {
visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx }, crate, Normal) visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx }, krate, Normal)
} }
impl Visitor<Context> for CheckLoopVisitor { impl Visitor<Context> for CheckLoopVisitor {

View File

@ -52,13 +52,13 @@ impl Visitor<()> for CheckMatchVisitor {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
method_map: method_map, method_map: method_map,
moves_map: moves::MovesMap, moves_map: moves::MovesMap,
crate: &Crate) { krate: &Crate) {
let cx = @MatchCheckCtxt {tcx: tcx, let cx = @MatchCheckCtxt {tcx: tcx,
method_map: method_map, method_map: method_map,
moves_map: moves_map}; moves_map: moves_map};
let mut v = CheckMatchVisitor { cx: cx }; let mut v = CheckMatchVisitor { cx: cx };
visit::walk_crate(&mut v, crate, ()); visit::walk_crate(&mut v, krate, ());
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
} }

View File

@ -302,13 +302,13 @@ impl Visitor<()> for ConstEvalVisitor {
} }
} }
pub fn process_crate(crate: &ast::Crate, pub fn process_crate(krate: &ast::Crate,
tcx: ty::ctxt) { tcx: ty::ctxt) {
let mut v = ConstEvalVisitor { let mut v = ConstEvalVisitor {
tcx: tcx, tcx: tcx,
ccache: HashMap::new(), ccache: HashMap::new(),
}; };
visit::walk_crate(&mut v, crate, ()); visit::walk_crate(&mut v, krate, ());
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
} }

View File

@ -254,7 +254,7 @@ impl Visitor<()> for LifeSeeder {
fn create_and_seed_worklist(tcx: ty::ctxt, fn create_and_seed_worklist(tcx: ty::ctxt,
exported_items: &privacy::ExportedItems, exported_items: &privacy::ExportedItems,
reachable_symbols: &HashSet<ast::NodeId>, reachable_symbols: &HashSet<ast::NodeId>,
crate: &ast::Crate) -> ~[ast::NodeId] { krate: &ast::Crate) -> ~[ast::NodeId] {
let mut worklist = ~[]; let mut worklist = ~[];
// Preferably, we would only need to seed the worklist with reachable // Preferably, we would only need to seed the worklist with reachable
@ -279,7 +279,7 @@ fn create_and_seed_worklist(tcx: ty::ctxt,
let mut life_seeder = LifeSeeder { let mut life_seeder = LifeSeeder {
worklist: worklist worklist: worklist
}; };
visit::walk_crate(&mut life_seeder, crate, ()); visit::walk_crate(&mut life_seeder, krate, ());
return life_seeder.worklist; return life_seeder.worklist;
} }
@ -288,10 +288,10 @@ fn find_live(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
exported_items: &privacy::ExportedItems, exported_items: &privacy::ExportedItems,
reachable_symbols: &HashSet<ast::NodeId>, reachable_symbols: &HashSet<ast::NodeId>,
crate: &ast::Crate) krate: &ast::Crate)
-> ~HashSet<ast::NodeId> { -> ~HashSet<ast::NodeId> {
let worklist = create_and_seed_worklist(tcx, exported_items, let worklist = create_and_seed_worklist(tcx, exported_items,
reachable_symbols, crate); reachable_symbols, krate);
let mut symbol_visitor = MarkSymbolVisitor::new(tcx, method_map, worklist); let mut symbol_visitor = MarkSymbolVisitor::new(tcx, method_map, worklist);
symbol_visitor.mark_live_symbols(); symbol_visitor.mark_live_symbols();
symbol_visitor.live_symbols symbol_visitor.live_symbols
@ -412,9 +412,9 @@ pub fn check_crate(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
exported_items: &privacy::ExportedItems, exported_items: &privacy::ExportedItems,
reachable_symbols: &HashSet<ast::NodeId>, reachable_symbols: &HashSet<ast::NodeId>,
crate: &ast::Crate) { krate: &ast::Crate) {
let live_symbols = find_live(tcx, method_map, exported_items, let live_symbols = find_live(tcx, method_map, exported_items,
reachable_symbols, crate); reachable_symbols, krate);
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols }; let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }

View File

@ -175,12 +175,12 @@ impl Visitor<()> for EffectCheckVisitor {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
method_map: method_map, method_map: method_map,
crate: &ast::Crate) { krate: &ast::Crate) {
let mut visitor = EffectCheckVisitor { let mut visitor = EffectCheckVisitor {
tcx: tcx, tcx: tcx,
method_map: method_map, method_map: method_map,
unsafe_context: SafeContext, unsafe_context: SafeContext,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }

View File

@ -44,14 +44,14 @@ impl Visitor<()> for EntryContext {
} }
} }
pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::Map) { pub fn find_entry_point(session: Session, krate: &Crate, ast_map: ast_map::Map) {
if session.building_library.get() { if session.building_library.get() {
// No need to find a main function // No need to find a main function
return; return;
} }
// If the user wants no main function at all, then stop here. // If the user wants no main function at all, then stop here.
if attr::contains_name(crate.attrs, "no_main") { if attr::contains_name(krate.attrs, "no_main") {
session.entry_type.set(Some(session::EntryNone)); session.entry_type.set(Some(session::EntryNone));
return return
} }
@ -65,7 +65,7 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::Map)
non_main_fns: ~[], non_main_fns: ~[],
}; };
visit::walk_crate(&mut ctxt, crate, ()); visit::walk_crate(&mut ctxt, krate, ());
configure_main(&mut ctxt); configure_main(&mut ctxt);
} }

View File

@ -124,13 +124,13 @@ impl Visitor<()> for AnnotateFreevarsVisitor {
// efficient as it fully recomputes the free variables at every // efficient as it fully recomputes the free variables at every
// node of interest rather than building up the free variables in // node of interest rather than building up the free variables in
// one pass. This could be improved upon if it turns out to matter. // one pass. This could be improved upon if it turns out to matter.
pub fn annotate_freevars(def_map: resolve::DefMap, crate: &ast::Crate) -> pub fn annotate_freevars(def_map: resolve::DefMap, krate: &ast::Crate) ->
freevar_map { freevar_map {
let mut visitor = AnnotateFreevarsVisitor { let mut visitor = AnnotateFreevarsVisitor {
def_map: def_map, def_map: def_map,
freevars: HashMap::new(), freevars: HashMap::new(),
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
let AnnotateFreevarsVisitor { let AnnotateFreevarsVisitor {
freevars, freevars,

View File

@ -77,12 +77,12 @@ impl Visitor<()> for Context {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
crate: &Crate) { krate: &Crate) {
let mut ctx = Context { let mut ctx = Context {
tcx: tcx, tcx: tcx,
method_map: method_map, method_map: method_map,
}; };
visit::walk_crate(&mut ctx, crate, ()); visit::walk_crate(&mut ctx, krate, ());
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
} }

View File

@ -161,24 +161,24 @@ impl LanguageItemCollector {
self.items.items[item_index] = Some(item_def_id); self.items.items[item_index] = Some(item_def_id);
} }
pub fn collect_local_language_items(&mut self, crate: &ast::Crate) { pub fn collect_local_language_items(&mut self, krate: &ast::Crate) {
let mut v = LanguageItemVisitor { this: self }; let mut v = LanguageItemVisitor { this: self };
visit::walk_crate(&mut v, crate, ()); visit::walk_crate(&mut v, krate, ());
} }
pub fn collect_external_language_items(&mut self) { pub fn collect_external_language_items(&mut self) {
let crate_store = self.session.cstore; let crate_store = self.session.cstore;
crate_store.iter_crate_data(|crate_number, _crate_metadata| { crate_store.iter_crate_data(|crate_number, _crate_metadata| {
each_lang_item(crate_store, crate_number, |node_id, item_index| { each_lang_item(crate_store, crate_number, |node_id, item_index| {
let def_id = ast::DefId { crate: crate_number, node: node_id }; let def_id = ast::DefId { krate: crate_number, node: node_id };
self.collect_item(item_index, def_id); self.collect_item(item_index, def_id);
true true
}); });
}) })
} }
pub fn collect(&mut self, crate: &ast::Crate) { pub fn collect(&mut self, krate: &ast::Crate) {
self.collect_local_language_items(crate); self.collect_local_language_items(krate);
self.collect_external_language_items(); self.collect_external_language_items();
} }
} }
@ -196,10 +196,10 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
return None; return None;
} }
pub fn collect_language_items(crate: &ast::Crate, pub fn collect_language_items(krate: &ast::Crate,
session: Session) -> @LanguageItems { session: Session) -> @LanguageItems {
let mut collector = LanguageItemCollector::new(session); let mut collector = LanguageItemCollector::new(session);
collector.collect(crate); collector.collect(krate);
let LanguageItemCollector { items, .. } = collector; let LanguageItemCollector { items, .. } = collector;
session.abort_if_errors(); session.abort_if_errors();
@items @items

View File

@ -1341,7 +1341,7 @@ fn check_missing_doc_item(cx: &Context, it: &ast::Item) {
fn check_missing_doc_method(cx: &Context, m: &ast::Method) { fn check_missing_doc_method(cx: &Context, m: &ast::Method) {
let did = ast::DefId { let did = ast::DefId {
crate: ast::LOCAL_CRATE, krate: ast::LOCAL_CRATE,
node: m.id node: m.id
}; };
@ -1643,7 +1643,7 @@ impl<'a> IdVisitingOperation for Context<'a> {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
exported_items: &privacy::ExportedItems, exported_items: &privacy::ExportedItems,
crate: &ast::Crate) { krate: &ast::Crate) {
let mut cx = Context { let mut cx = Context {
dict: @get_lint_dict(), dict: @get_lint_dict(),
cur: SmallIntMap::new(), cur: SmallIntMap::new(),
@ -1664,19 +1664,19 @@ pub fn check_crate(tcx: ty::ctxt,
for &(lint, level) in tcx.sess.opts.lint_opts.iter() { for &(lint, level) in tcx.sess.opts.lint_opts.iter() {
cx.set_level(lint, level, CommandLine); cx.set_level(lint, level, CommandLine);
} }
cx.with_lint_attrs(crate.attrs, |cx| { cx.with_lint_attrs(krate.attrs, |cx| {
cx.visit_id(ast::CRATE_NODE_ID); cx.visit_id(ast::CRATE_NODE_ID);
cx.visit_ids(|v| { cx.visit_ids(|v| {
v.visited_outermost = true; v.visited_outermost = true;
visit::walk_crate(v, crate, ()); visit::walk_crate(v, krate, ());
}); });
check_crate_attrs_usage(cx, crate.attrs); check_crate_attrs_usage(cx, krate.attrs);
// since the root module isn't visited as an item (because it isn't an item), warn for it // since the root module isn't visited as an item (because it isn't an item), warn for it
// here. // here.
check_missing_doc_attrs(cx, None, crate.attrs, crate.span, "crate"); check_missing_doc_attrs(cx, None, krate.attrs, krate.span, "crate");
visit::walk_crate(cx, crate, ()); visit::walk_crate(cx, krate, ());
}); });
// If we missed any lints added to the session, then there's a bug somewhere // If we missed any lints added to the session, then there's a bug somewhere

View File

@ -176,11 +176,11 @@ impl Visitor<@IrMaps> for LivenessVisitor {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
method_map: typeck::method_map, method_map: typeck::method_map,
capture_map: moves::CaptureMap, capture_map: moves::CaptureMap,
crate: &Crate) { krate: &Crate) {
let mut visitor = LivenessVisitor; let mut visitor = LivenessVisitor;
let initial_maps = @IrMaps(tcx, method_map, capture_map); let initial_maps = @IrMaps(tcx, method_map, capture_map);
visit::walk_crate(&mut visitor, crate, initial_maps); visit::walk_crate(&mut visitor, krate, initial_maps);
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
} }

View File

@ -209,7 +209,7 @@ impl visit::Visitor<()> for VisitContext {
pub fn compute_moves(tcx: ty::ctxt, pub fn compute_moves(tcx: ty::ctxt,
method_map: method_map, method_map: method_map,
crate: &Crate) -> MoveMaps krate: &Crate) -> MoveMaps
{ {
let mut visit_cx = VisitContext { let mut visit_cx = VisitContext {
tcx: tcx, tcx: tcx,
@ -221,7 +221,7 @@ pub fn compute_moves(tcx: ty::ctxt,
} }
}; };
let visit_cx = &mut visit_cx; let visit_cx = &mut visit_cx;
visit::walk_crate(visit_cx, crate, ()); visit::walk_crate(visit_cx, krate, ());
return visit_cx.move_maps; return visit_cx.move_maps;
} }

View File

@ -1091,13 +1091,13 @@ pub fn check_crate(tcx: ty::ctxt,
exp_map2: &resolve::ExportMap2, exp_map2: &resolve::ExportMap2,
external_exports: resolve::ExternalExports, external_exports: resolve::ExternalExports,
last_private_map: resolve::LastPrivateMap, last_private_map: resolve::LastPrivateMap,
crate: &ast::Crate) -> (ExportedItems, PublicItems) { krate: &ast::Crate) -> (ExportedItems, PublicItems) {
// Figure out who everyone's parent is // Figure out who everyone's parent is
let mut visitor = ParentVisitor { let mut visitor = ParentVisitor {
parents: HashMap::new(), parents: HashMap::new(),
curparent: ast::DUMMY_NODE_ID, curparent: ast::DUMMY_NODE_ID,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
// Use the parent map to check the privacy of everything // Use the parent map to check the privacy of everything
let mut visitor = PrivacyVisitor { let mut visitor = PrivacyVisitor {
@ -1110,7 +1110,7 @@ pub fn check_crate(tcx: ty::ctxt,
external_exports: external_exports, external_exports: external_exports,
last_private_map: last_private_map, last_private_map: last_private_map,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
// Sanity check to make sure that all privacy usage and controls are // Sanity check to make sure that all privacy usage and controls are
// reasonable. // reasonable.
@ -1118,7 +1118,7 @@ pub fn check_crate(tcx: ty::ctxt,
in_fn: false, in_fn: false,
tcx: tcx, tcx: tcx,
}; };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
@ -1135,7 +1135,7 @@ pub fn check_crate(tcx: ty::ctxt,
}; };
loop { loop {
let before = visitor.exported_items.len(); let before = visitor.exported_items.len();
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
if before == visitor.exported_items.len() { if before == visitor.exported_items.len() {
break break
} }

View File

@ -207,7 +207,7 @@ impl ReachableContext {
// eligible for inlining and false otherwise. // eligible for inlining and false otherwise.
fn def_id_represents_local_inlined_item(tcx: ty::ctxt, def_id: ast::DefId) fn def_id_represents_local_inlined_item(tcx: ty::ctxt, def_id: ast::DefId)
-> bool { -> bool {
if def_id.crate != ast::LOCAL_CRATE { if def_id.krate != ast::LOCAL_CRATE {
return false return false
} }
@ -232,7 +232,7 @@ impl ReachableContext {
} else { } else {
// Check the impl. If the generics on the self type of the // Check the impl. If the generics on the self type of the
// impl require inlining, this method does too. // impl require inlining, this method does too.
assert!(impl_did.crate == ast::LOCAL_CRATE); assert!(impl_did.krate == ast::LOCAL_CRATE);
match tcx.items.find(impl_did.node) { match tcx.items.find(impl_did.node) {
Some(ast_map::NodeItem(item, _)) => { Some(ast_map::NodeItem(item, _)) => {
match item.node { match item.node {
@ -410,7 +410,7 @@ impl ReachableContext {
fn mark_destructors_reachable(&self) { fn mark_destructors_reachable(&self) {
let destructor_for_type = self.tcx.destructor_for_type.borrow(); let destructor_for_type = self.tcx.destructor_for_type.borrow();
for (_, destructor_def_id) in destructor_for_type.get().iter() { for (_, destructor_def_id) in destructor_for_type.get().iter() {
if destructor_def_id.crate == ast::LOCAL_CRATE { if destructor_def_id.krate == ast::LOCAL_CRATE {
let mut reachable_symbols = self.reachable_symbols let mut reachable_symbols = self.reachable_symbols
.borrow_mut(); .borrow_mut();
reachable_symbols.get().insert(destructor_def_id.node); reachable_symbols.get().insert(destructor_def_id.node);

View File

@ -908,7 +908,7 @@ impl<'a> Visitor<Context> for RegionResolutionVisitor<'a> {
} }
} }
pub fn resolve_crate(sess: Session, crate: &ast::Crate) -> RegionMaps { pub fn resolve_crate(sess: Session, krate: &ast::Crate) -> RegionMaps {
let maps = RegionMaps { let maps = RegionMaps {
scope_map: RefCell::new(HashMap::new()), scope_map: RefCell::new(HashMap::new()),
var_map: RefCell::new(HashMap::new()), var_map: RefCell::new(HashMap::new()),
@ -922,7 +922,7 @@ pub fn resolve_crate(sess: Session, crate: &ast::Crate) -> RegionMaps {
region_maps: &maps region_maps: &maps
}; };
let cx = Context { parent: None, var_parent: None }; let cx = Context { parent: None, var_parent: None };
visit::walk_crate(&mut visitor, crate, cx); visit::walk_crate(&mut visitor, krate, cx);
} }
return maps; return maps;
} }

View File

@ -769,7 +769,7 @@ fn Resolver(session: Session,
let graph_root = @NameBindings(); let graph_root = @NameBindings();
graph_root.define_module(NoParentLink, graph_root.define_module(NoParentLink,
Some(DefId { crate: 0, node: 0 }), Some(DefId { krate: 0, node: 0 }),
NormalModuleKind, NormalModuleKind,
false, false,
true, true,
@ -918,8 +918,8 @@ impl<'a> Visitor<()> for UnusedImportCheckVisitor<'a> {
impl Resolver { impl Resolver {
/// The main name resolution procedure. /// The main name resolution procedure.
fn resolve(&mut self, crate: &ast::Crate) { fn resolve(&mut self, krate: &ast::Crate) {
self.build_reduced_graph(crate); self.build_reduced_graph(krate);
self.session.abort_if_errors(); self.session.abort_if_errors();
self.resolve_imports(); self.resolve_imports();
@ -928,10 +928,10 @@ impl Resolver {
self.record_exports(); self.record_exports();
self.session.abort_if_errors(); self.session.abort_if_errors();
self.resolve_crate(crate); self.resolve_crate(krate);
self.session.abort_if_errors(); self.session.abort_if_errors();
self.check_for_unused_imports(crate); self.check_for_unused_imports(krate);
} }
// //
@ -942,12 +942,12 @@ impl Resolver {
// //
/// Constructs the reduced graph for the entire crate. /// Constructs the reduced graph for the entire crate.
fn build_reduced_graph(&mut self, crate: &ast::Crate) { fn build_reduced_graph(&mut self, krate: &ast::Crate) {
let initial_parent = let initial_parent =
ModuleReducedGraphParent(self.graph_root.get_module()); ModuleReducedGraphParent(self.graph_root.get_module());
let mut visitor = BuildReducedGraphVisitor { resolver: self, }; let mut visitor = BuildReducedGraphVisitor { resolver: self, };
visit::walk_crate(&mut visitor, crate, initial_parent); visit::walk_crate(&mut visitor, krate, initial_parent);
} }
/// Returns the current module tracked by the reduced graph parent. /// Returns the current module tracked by the reduced graph parent.
@ -1138,7 +1138,7 @@ impl Resolver {
self.add_child(ident, parent, ForbidDuplicateModules, sp); self.add_child(ident, parent, ForbidDuplicateModules, sp);
let parent_link = self.get_parent_link(new_parent, ident); let parent_link = self.get_parent_link(new_parent, ident);
let def_id = DefId { crate: 0, node: item.id }; let def_id = DefId { krate: 0, node: item.id };
name_bindings.define_module(parent_link, name_bindings.define_module(parent_link,
Some(def_id), Some(def_id),
NormalModuleKind, NormalModuleKind,
@ -1500,7 +1500,7 @@ impl Resolver {
// n.b. we don't need to look at the path option here, because cstore already did // n.b. we don't need to look at the path option here, because cstore already did
match self.session.cstore.find_extern_mod_stmt_cnum(node_id) { match self.session.cstore.find_extern_mod_stmt_cnum(node_id) {
Some(crate_id) => { Some(crate_id) => {
let def_id = DefId { crate: crate_id, node: 0 }; let def_id = DefId { krate: crate_id, node: 0 };
self.external_exports.insert(def_id); self.external_exports.insert(def_id);
let parent_link = ModuleParentLink let parent_link = ModuleParentLink
(self.get_module_from_parent(parent), name); (self.get_module_from_parent(parent), name);
@ -1921,7 +1921,7 @@ impl Resolver {
root.def_id root.def_id
.get() .get()
.unwrap() .unwrap()
.crate, .krate,
|def_like, ident, visibility| { |def_like, ident, visibility| {
self.build_reduced_graph_for_external_crate_def(root, self.build_reduced_graph_for_external_crate_def(root,
def_like, def_like,
@ -3298,11 +3298,11 @@ impl Resolver {
fn record_exports_for_module_subtree(&mut self, fn record_exports_for_module_subtree(&mut self,
module_: @Module) { module_: @Module) {
// If this isn't a local crate, then bail out. We don't need to record // If this isn't a local krate, then bail out. We don't need to record
// exports for nonlocal crates. // exports for nonlocal crates.
match module_.def_id.get() { match module_.def_id.get() {
Some(def_id) if def_id.crate == LOCAL_CRATE => { Some(def_id) if def_id.krate == LOCAL_CRATE => {
// OK. Continue. // OK. Continue.
debug!("(recording exports for module subtree) recording \ debug!("(recording exports for module subtree) recording \
exports for local module `{}`", exports for local module `{}`",
@ -3610,10 +3610,10 @@ impl Resolver {
return None; return None;
} }
fn resolve_crate(&mut self, crate: &ast::Crate) { fn resolve_crate(&mut self, krate: &ast::Crate) {
debug!("(resolving crate) starting"); debug!("(resolving crate) starting");
visit::walk_crate(self, crate, ()); visit::walk_crate(self, krate, ());
} }
fn resolve_item(&mut self, item: &Item) { fn resolve_item(&mut self, item: &Item) {
@ -5401,7 +5401,7 @@ impl Resolver {
trait_def_id: DefId, trait_def_id: DefId,
name: Ident) { name: Ident) {
debug!("(adding trait info) found trait {}:{} for method '{}'", debug!("(adding trait info) found trait {}:{} for method '{}'",
trait_def_id.crate, trait_def_id.krate,
trait_def_id.node, trait_def_id.node,
self.session.str_of(name)); self.session.str_of(name));
found_traits.push(trait_def_id); found_traits.push(trait_def_id);
@ -5456,9 +5456,9 @@ impl Resolver {
// resolve data structures. // resolve data structures.
// //
fn check_for_unused_imports(&self, crate: &ast::Crate) { fn check_for_unused_imports(&self, krate: &ast::Crate) {
let mut visitor = UnusedImportCheckVisitor{ resolver: self }; let mut visitor = UnusedImportCheckVisitor{ resolver: self };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
fn check_for_item_unused_imports(&self, vi: &ViewItem) { fn check_for_item_unused_imports(&self, vi: &ViewItem) {
@ -5579,10 +5579,10 @@ pub struct CrateMap {
/// Entry point to crate resolution. /// Entry point to crate resolution.
pub fn resolve_crate(session: Session, pub fn resolve_crate(session: Session,
lang_items: @LanguageItems, lang_items: @LanguageItems,
crate: &Crate) krate: &Crate)
-> CrateMap { -> CrateMap {
let mut resolver = Resolver(session, lang_items, crate.span); let mut resolver = Resolver(session, lang_items, krate.span);
resolver.resolve(crate); resolver.resolve(krate);
let Resolver { def_map, export_map2, trait_map, last_private, let Resolver { def_map, export_map2, trait_map, last_private,
external_exports, .. } = resolver; external_exports, .. } = resolver;
CrateMap { CrateMap {

View File

@ -44,13 +44,13 @@ enum ScopeChain<'a> {
RootScope RootScope
} }
pub fn crate(sess: session::Session, crate: &ast::Crate) pub fn krate(sess: session::Session, krate: &ast::Crate)
-> @RefCell<NamedRegionMap> { -> @RefCell<NamedRegionMap> {
let mut ctxt = LifetimeContext { let mut ctxt = LifetimeContext {
sess: sess, sess: sess,
named_region_map: @RefCell::new(HashMap::new()) named_region_map: @RefCell::new(HashMap::new())
}; };
visit::walk_crate(&mut ctxt, crate, &RootScope); visit::walk_crate(&mut ctxt, krate, &RootScope);
sess.abort_if_errors(); sess.abort_if_errors();
ctxt.named_region_map ctxt.named_region_map
} }

View File

@ -522,13 +522,13 @@ pub fn get_res_dtor(ccx: @CrateContext,
substs: &[ty::t]) substs: &[ty::t])
-> ValueRef { -> ValueRef {
let _icx = push_ctxt("trans_res_dtor"); let _icx = push_ctxt("trans_res_dtor");
let did = if did.crate != ast::LOCAL_CRATE { let did = if did.krate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did) inline::maybe_instantiate_inline(ccx, did)
} else { } else {
did did
}; };
if !substs.is_empty() { if !substs.is_empty() {
assert_eq!(did.crate, ast::LOCAL_CRATE); assert_eq!(did.krate, ast::LOCAL_CRATE);
let tsubsts = ty::substs {regions: ty::ErasedRegions, let tsubsts = ty::substs {regions: ty::ErasedRegions,
self_ty: None, self_ty: None,
tps: /*bad*/ substs.to_owned() }; tps: /*bad*/ substs.to_owned() };
@ -547,7 +547,7 @@ pub fn get_res_dtor(ccx: @CrateContext,
None); None);
val val
} else if did.crate == ast::LOCAL_CRATE { } else if did.krate == ast::LOCAL_CRATE {
get_item_val(ccx, did.node) get_item_val(ccx, did.node)
} else { } else {
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -1895,7 +1895,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
Ok(id) => id, Ok(id) => id,
Err(s) => { ccx.tcx.sess.fatal(s); } Err(s) => { ccx.tcx.sess.fatal(s); }
}; };
let start_fn = if start_def_id.crate == ast::LOCAL_CRATE { let start_fn = if start_def_id.krate == ast::LOCAL_CRATE {
get_item_val(ccx, start_def_id.node) get_item_val(ccx, start_def_id.node)
} else { } else {
let start_fn_type = csearch::get_type(ccx.tcx, let start_fn_type = csearch::get_type(ccx.tcx,
@ -2610,7 +2610,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_
} }
} }
pub fn write_metadata(cx: &CrateContext, crate: &ast::Crate) -> ~[u8] { pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> ~[u8] {
use flate; use flate;
if !cx.sess.building_library.get() { if !cx.sess.building_library.get() {
@ -2622,7 +2622,7 @@ pub fn write_metadata(cx: &CrateContext, crate: &ast::Crate) -> ~[u8] {
astencode::encode_inlined_item(ecx, ebml_w, path, ii, cx.maps); astencode::encode_inlined_item(ecx, ebml_w, path, ii, cx.maps);
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item); let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let metadata = encoder::encode_metadata(encode_parms, crate); let metadata = encoder::encode_metadata(encode_parms, krate);
let compressed = encoder::metadata_encoding_version + let compressed = encoder::metadata_encoding_version +
flate::deflate_bytes(metadata); flate::deflate_bytes(metadata);
let llmeta = C_bytes(compressed); let llmeta = C_bytes(compressed);
@ -2644,7 +2644,7 @@ pub fn write_metadata(cx: &CrateContext, crate: &ast::Crate) -> ~[u8] {
} }
pub fn trans_crate(sess: session::Session, pub fn trans_crate(sess: session::Session,
crate: ast::Crate, krate: ast::Crate,
analysis: &CrateAnalysis, analysis: &CrateAnalysis,
output: &OutputFilenames) -> CrateTranslation { output: &OutputFilenames) -> CrateTranslation {
// Before we touch LLVM, make sure that multithreading is enabled. // Before we touch LLVM, make sure that multithreading is enabled.
@ -2666,7 +2666,7 @@ pub fn trans_crate(sess: session::Session,
} }
let mut symbol_hasher = Sha256::new(); let mut symbol_hasher = Sha256::new();
let link_meta = link::build_link_meta(crate.attrs, output, let link_meta = link::build_link_meta(krate.attrs, output,
&mut symbol_hasher); &mut symbol_hasher);
// Append ".rs" to crate name as LLVM module identifier. // Append ".rs" to crate name as LLVM module identifier.
@ -2689,7 +2689,7 @@ pub fn trans_crate(sess: session::Session,
analysis.reachable); analysis.reachable);
{ {
let _icx = push_ctxt("text"); let _icx = push_ctxt("text");
trans_mod(ccx, &crate.module); trans_mod(ccx, &krate.module);
} }
decl_gc_metadata(ccx, llmod_id); decl_gc_metadata(ccx, llmod_id);
@ -2719,7 +2719,7 @@ pub fn trans_crate(sess: session::Session,
} }
// Translate the metadata. // Translate the metadata.
let metadata = write_metadata(ccx, &crate); let metadata = write_metadata(ccx, &krate);
if ccx.sess.trans_stats() { if ccx.sess.trans_stats() {
println!("--- trans stats ---"); println!("--- trans stats ---");
println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs.get()); println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs.get());

View File

@ -346,7 +346,7 @@ pub fn trans_fn_ref_with_vtables(
// Check whether this fn has an inlined copy and, if so, redirect // Check whether this fn has an inlined copy and, if so, redirect
// def_id to the local id of the inlined copy. // def_id to the local id of the inlined copy.
let def_id = { let def_id = {
if def_id.crate != ast::LOCAL_CRATE { if def_id.krate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, def_id) inline::maybe_instantiate_inline(ccx, def_id)
} else { } else {
def_id def_id
@ -360,7 +360,7 @@ pub fn trans_fn_ref_with_vtables(
let must_monomorphise; let must_monomorphise;
if type_params.len() > 0 || is_default { if type_params.len() > 0 || is_default {
must_monomorphise = true; must_monomorphise = true;
} else if def_id.crate == ast::LOCAL_CRATE { } else if def_id.krate == ast::LOCAL_CRATE {
{ {
let map_node = session::expect( let map_node = session::expect(
ccx.sess, ccx.sess,
@ -383,7 +383,7 @@ pub fn trans_fn_ref_with_vtables(
// Create a monomorphic verison of generic functions // Create a monomorphic verison of generic functions
if must_monomorphise { if must_monomorphise {
// Should be either intra-crate or inlined. // Should be either intra-crate or inlined.
assert_eq!(def_id.crate, ast::LOCAL_CRATE); assert_eq!(def_id.krate, ast::LOCAL_CRATE);
let (val, must_cast) = let (val, must_cast) =
monomorphize::monomorphic_fn(ccx, def_id, &substs, monomorphize::monomorphic_fn(ccx, def_id, &substs,
@ -403,7 +403,7 @@ pub fn trans_fn_ref_with_vtables(
// Find the actual function pointer. // Find the actual function pointer.
let mut val = { let mut val = {
if def_id.crate == ast::LOCAL_CRATE { if def_id.krate == ast::LOCAL_CRATE {
// Internal reference. // Internal reference.
get_item_val(ccx, def_id.node) get_item_val(ccx, def_id.node)
} else { } else {
@ -512,7 +512,7 @@ pub fn trans_lang_call<'a>(
args: &[ValueRef], args: &[ValueRef],
dest: Option<expr::Dest>) dest: Option<expr::Dest>)
-> Result<'a> { -> Result<'a> {
let fty = if did.crate == ast::LOCAL_CRATE { let fty = if did.krate == ast::LOCAL_CRATE {
ty::node_id_to_type(bcx.ccx().tcx, did.node) ty::node_id_to_type(bcx.ccx().tcx, did.node)
} else { } else {
csearch::get_type(bcx.ccx().tcx, did).ty csearch::get_type(bcx.ccx().tcx, did).ty
@ -541,7 +541,7 @@ pub fn trans_lang_call_with_type_params<'a>(
dest: expr::Dest) dest: expr::Dest)
-> &'a Block<'a> { -> &'a Block<'a> {
let fty; let fty;
if did.crate == ast::LOCAL_CRATE { if did.krate == ast::LOCAL_CRATE {
fty = ty::node_id_to_type(bcx.tcx(), did.node); fty = ty::node_id_to_type(bcx.tcx(), did.node);
} else { } else {
fty = csearch::get_type(bcx.tcx(), did).ty; fty = csearch::get_type(bcx.tcx(), did).ty;

View File

@ -1398,7 +1398,7 @@ fn describe_enum_variant(cx: &CrateContext,
// Could some consistency checks here: size, align, field count, discr type // Could some consistency checks here: size, align, field count, discr type
// Find the source code location of the variant's definition // Find the source code location of the variant's definition
let variant_definition_span = if variant_info.id.crate == ast::LOCAL_CRATE { let variant_definition_span = if variant_info.id.krate == ast::LOCAL_CRATE {
{ {
match cx.tcx.items.find(variant_info.id.node) { match cx.tcx.items.find(variant_info.id.node) {
Some(ast_map::NodeVariant(ref variant, _, _)) => variant.span, Some(ast_map::NodeVariant(ref variant, _, _)) => variant.span,
@ -2261,7 +2261,7 @@ fn get_namespace_and_span_for_item(cx: &CrateContext,
warning_span: Span) warning_span: Span)
-> (DIScope, Span) { -> (DIScope, Span) {
let containing_scope = namespace_for_item(cx, def_id, warning_span).scope; let containing_scope = namespace_for_item(cx, def_id, warning_span).scope;
let definition_span = if def_id.crate == ast::LOCAL_CRATE { let definition_span = if def_id.krate == ast::LOCAL_CRATE {
{ {
let definition_span = match cx.tcx.items.find(def_id.node) { let definition_span = match cx.tcx.items.find(def_id.node) {
Some(ast_map::NodeItem(item, _)) => item.span, Some(ast_map::NodeItem(item, _)) => item.span,
@ -2782,8 +2782,8 @@ fn namespace_for_item(cx: &CrateContext,
let namespace_path = { let namespace_path = {
let mut item_path = ty::item_path(cx.tcx, def_id); let mut item_path = ty::item_path(cx.tcx, def_id);
if (def_id.crate == ast::LOCAL_CRATE && item_path.len() < 1) || if (def_id.krate == ast::LOCAL_CRATE && item_path.len() < 1) ||
(def_id.crate != ast::LOCAL_CRATE && item_path.len() < 2) { (def_id.krate != ast::LOCAL_CRATE && item_path.len() < 2) {
cx.sess.bug(format!("debuginfo::namespace_for_item() - Item path too short: {}", cx.sess.bug(format!("debuginfo::namespace_for_item() - Item path too short: {}",
ast_map::path_to_str(item_path, token::get_ident_interner()))); ast_map::path_to_str(item_path, token::get_ident_interner())));
} }
@ -2791,7 +2791,7 @@ fn namespace_for_item(cx: &CrateContext,
// remove the name of the item // remove the name of the item
item_path.pop(); item_path.pop();
if def_id.crate == ast::LOCAL_CRATE { if def_id.krate == ast::LOCAL_CRATE {
// prepend crate name if not already present // prepend crate name if not already present
let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name); let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name);
item_path.insert(0, ast_map::PathMod(crate_namespace_ident)); item_path.insert(0, ast_map::PathMod(crate_namespace_ident));

View File

@ -582,7 +582,7 @@ fn trans_def<'a>(bcx: &'a Block<'a>,
fn get_did(ccx: @CrateContext, did: ast::DefId) fn get_did(ccx: @CrateContext, did: ast::DefId)
-> ast::DefId { -> ast::DefId {
if did.crate != ast::LOCAL_CRATE { if did.krate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did) inline::maybe_instantiate_inline(ccx, did)
} else { } else {
did did
@ -592,7 +592,7 @@ fn trans_def<'a>(bcx: &'a Block<'a>,
fn get_val<'a>(bcx: &'a Block<'a>, did: ast::DefId, const_ty: ty::t) fn get_val<'a>(bcx: &'a Block<'a>, did: ast::DefId, const_ty: ty::t)
-> ValueRef { -> ValueRef {
// For external constants, we don't inline. // For external constants, we don't inline.
if did.crate == ast::LOCAL_CRATE { if did.krate == ast::LOCAL_CRATE {
// The LLVM global has the type of its initializer, // The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for // which may not be equal to the enum's type for
// non-C-like enums. // non-C-like enums.
@ -1710,7 +1710,7 @@ fn trans_log_level<'a>(bcx: &'a Block<'a>)
let external_srcs = ccx.external_srcs.borrow(); let external_srcs = ccx.external_srcs.borrow();
srccrate = match external_srcs.get().find(&bcx.fcx.id) { srccrate = match external_srcs.get().find(&bcx.fcx.id) {
Some(&src) => { Some(&src) => {
ccx.sess.cstore.get_crate_data(src.crate).name.clone() ccx.sess.cstore.get_crate_data(src.krate).name.clone()
} }
None => ccx.link_meta.crateid.name.to_str(), None => ccx.link_meta.crateid.name.to_str(),
}; };

View File

@ -184,7 +184,7 @@ pub fn trans_static_method_callee(bcx: &Block,
let bound_index = ty::lookup_trait_def(bcx.tcx(), trait_id). let bound_index = ty::lookup_trait_def(bcx.tcx(), trait_id).
generics.type_param_defs().len(); generics.type_param_defs().len();
let mname = if method_id.crate == ast::LOCAL_CRATE { let mname = if method_id.krate == ast::LOCAL_CRATE {
{ {
match bcx.tcx().items.get(method_id.node) { match bcx.tcx().items.get(method_id.node) {
ast_map::NodeTraitMethod(trait_method, _, _) => { ast_map::NodeTraitMethod(trait_method, _, _) => {

View File

@ -321,10 +321,10 @@ pub fn llvm_type_name(cx: &CrateContext,
let tstr = ppaux::parameterized(cx.tcx, ty::item_path_str(cx.tcx, did), let tstr = ppaux::parameterized(cx.tcx, ty::item_path_str(cx.tcx, did),
&ty::NonerasedRegions(opt_vec::Empty), &ty::NonerasedRegions(opt_vec::Empty),
tps, did, false); tps, did, false);
if did.crate == 0 { if did.krate == 0 {
format!("{}.{}", name, tstr) format!("{}.{}", name, tstr)
} else { } else {
format!("{}.{}[\\#{}]", name, tstr, did.crate) format!("{}.{}[\\#{}]", name, tstr, did.krate)
} }
} }

View File

@ -2187,7 +2187,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
// If this assertion failures, it is likely because of a // If this assertion failures, it is likely because of a
// failure in the cross-crate inlining code to translate a // failure in the cross-crate inlining code to translate a
// def-id. // def-id.
assert_eq!(p.def_id.crate, ast::LOCAL_CRATE); assert_eq!(p.def_id.krate, ast::LOCAL_CRATE);
let ty_param_defs = cx.ty_param_defs.borrow(); let ty_param_defs = cx.ty_param_defs.borrow();
let tp_def = ty_param_defs.get().get(&p.def_id.node); let tp_def = ty_param_defs.get().get(&p.def_id.node);
@ -3842,8 +3842,8 @@ fn lookup_locally_or_in_crate_store<V:Clone>(
None => { } None => { }
} }
if def_id.crate == ast::LOCAL_CRATE { if def_id.krate == ast::LOCAL_CRATE {
fail!("no def'n found for {:?} in tcx.{}", def_id, descr); fail!("No def'n found for {:?} in tcx.{}", def_id, descr);
} }
let v = load_external(); let v = load_external();
map.insert(def_id, v.clone()); map.insert(def_id, v.clone());
@ -3895,7 +3895,7 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::DefId) -> Option<@TraitRef> {
} }
} }
let ret = if id.crate == ast::LOCAL_CRATE { let ret = if id.krate == ast::LOCAL_CRATE {
debug!("(impl_trait_ref) searching for trait impl {:?}", id); debug!("(impl_trait_ref) searching for trait impl {:?}", id);
{ {
match cx.items.find(id.node) { match cx.items.find(id.node) {
@ -4085,7 +4085,7 @@ pub fn has_dtor(cx: ctxt, struct_id: DefId) -> bool {
} }
pub fn item_path(cx: ctxt, id: ast::DefId) -> ast_map::Path { pub fn item_path(cx: ctxt, id: ast::DefId) -> ast_map::Path {
if id.crate != ast::LOCAL_CRATE { if id.krate != ast::LOCAL_CRATE {
return csearch::get_item_path(cx, id) return csearch::get_item_path(cx, id)
} }
@ -4155,7 +4155,7 @@ pub fn enum_variants(cx: ctxt, id: ast::DefId) -> @~[@VariantInfo] {
} }
} }
let result = if ast::LOCAL_CRATE != id.crate { let result = if ast::LOCAL_CRATE != id.krate {
@csearch::get_enum_variants(cx, id) @csearch::get_enum_variants(cx, id)
} else { } else {
/* /*
@ -4274,7 +4274,7 @@ pub fn lookup_trait_def(cx: ctxt, did: ast::DefId) -> @ty::TraitDef {
return trait_def; return trait_def;
} }
None => { None => {
assert!(did.crate != ast::LOCAL_CRATE); assert!(did.krate != ast::LOCAL_CRATE);
let trait_def = @csearch::get_trait_def(cx, did); let trait_def = @csearch::get_trait_def(cx, did);
trait_defs.get().insert(did, trait_def); trait_defs.get().insert(did, trait_def);
return trait_def; return trait_def;
@ -4348,7 +4348,7 @@ pub fn lookup_field_type(tcx: ctxt,
id: DefId, id: DefId,
substs: &substs) substs: &substs)
-> ty::t { -> ty::t {
let t = if id.crate == ast::LOCAL_CRATE { let t = if id.krate == ast::LOCAL_CRATE {
node_id_to_type(tcx, id.node) node_id_to_type(tcx, id.node)
} else { } else {
{ {
@ -4369,7 +4369,7 @@ pub fn lookup_field_type(tcx: ctxt,
// Look up the list of field names and IDs for a given struct // Look up the list of field names and IDs for a given struct
// Fails if the id is not bound to a struct. // Fails if the id is not bound to a struct.
pub fn lookup_struct_fields(cx: ctxt, did: ast::DefId) -> ~[field_ty] { pub fn lookup_struct_fields(cx: ctxt, did: ast::DefId) -> ~[field_ty] {
if did.crate == ast::LOCAL_CRATE { if did.krate == ast::LOCAL_CRATE {
{ {
match cx.items.find(did.node) { match cx.items.find(did.node) {
Some(ast_map::NodeItem(i,_)) => { Some(ast_map::NodeItem(i,_)) => {
@ -4799,7 +4799,7 @@ fn record_trait_implementation(tcx: ctxt,
/// if necessary. /// if necessary.
pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, pub fn populate_implementations_for_type_if_necessary(tcx: ctxt,
type_id: ast::DefId) { type_id: ast::DefId) {
if type_id.crate == LOCAL_CRATE { if type_id.krate == LOCAL_CRATE {
return return
} }
{ {
@ -4867,7 +4867,7 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt,
pub fn populate_implementations_for_trait_if_necessary( pub fn populate_implementations_for_trait_if_necessary(
tcx: ctxt, tcx: ctxt,
trait_id: ast::DefId) { trait_id: ast::DefId) {
if trait_id.crate == LOCAL_CRATE { if trait_id.krate == LOCAL_CRATE {
return return
} }
{ {
@ -4931,7 +4931,7 @@ pub fn trait_id_of_impl(tcx: ctxt,
/// the trait that the method belongs to. Otherwise, return `None`. /// the trait that the method belongs to. Otherwise, return `None`.
pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId) pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId)
-> Option<ast::DefId> { -> Option<ast::DefId> {
if def_id.crate != LOCAL_CRATE { if def_id.krate != LOCAL_CRATE {
return csearch::get_trait_of_method(tcx.cstore, def_id, tcx); return csearch::get_trait_of_method(tcx.cstore, def_id, tcx);
} }
let method; let method;
@ -5012,7 +5012,7 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
let h = if ast_util::is_local(did) { let h = if ast_util::is_local(did) {
local_hash.clone() local_hash.clone()
} else { } else {
tcx.sess.cstore.get_crate_hash(did.crate) tcx.sess.cstore.get_crate_hash(did.krate)
}; };
hash.input(h.as_bytes()); hash.input(h.as_bytes());
iter(hash, &did.node); iter(hash, &did.node);

View File

@ -1297,7 +1297,7 @@ impl<'a> LookupContext<'a> {
} }
fn report_static_candidate(&self, idx: uint, did: DefId) { fn report_static_candidate(&self, idx: uint, did: DefId) {
let span = if did.crate == ast::LOCAL_CRATE { let span = if did.krate == ast::LOCAL_CRATE {
{ {
match self.tcx().items.find(did.node) { match self.tcx().items.find(did.node) {
Some(ast_map::NodeMethod(m, _, _)) => m.span, Some(ast_map::NodeMethod(m, _, _)) => m.span,

View File

@ -312,9 +312,9 @@ impl Visitor<()> for CheckItemTypesVisitor {
} }
} }
pub fn check_item_types(ccx: @CrateCtxt, crate: &ast::Crate) { pub fn check_item_types(ccx: @CrateCtxt, krate: &ast::Crate) {
let mut visit = CheckItemTypesVisitor { ccx: ccx }; let mut visit = CheckItemTypesVisitor { ccx: ccx };
visit::walk_crate(&mut visit, crate, ()); visit::walk_crate(&mut visit, krate, ());
} }
fn check_bare_fn(ccx: @CrateCtxt, fn check_bare_fn(ccx: @CrateCtxt,
@ -2648,7 +2648,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
Err(msg) => { Err(msg) => {
tcx.sess.span_err(expr.span, msg); tcx.sess.span_err(expr.span, msg);
ast::DefId { ast::DefId {
crate: ast::CRATE_NODE_ID, krate: ast::CRATE_NODE_ID,
node: ast::DUMMY_NODE_ID, node: ast::DUMMY_NODE_ID,
} }
} }
@ -3625,7 +3625,7 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
return variants; return variants;
} }
let hint = ty::lookup_repr_hint(ccx.tcx, ast::DefId { crate: ast::LOCAL_CRATE, node: id }); let hint = ty::lookup_repr_hint(ccx.tcx, ast::DefId { krate: ast::LOCAL_CRATE, node: id });
if hint != attr::ReprAny && vs.len() <= 1 { if hint != attr::ReprAny && vs.len() <= 1 {
ccx.tcx.sess.span_err(sp, format!("unsupported representation for {}variant enum", ccx.tcx.sess.span_err(sp, format!("unsupported representation for {}variant enum",
if vs.len() == 1 { "uni" } else { "zero-" })) if vs.len() == 1 { "uni" } else { "zero-" }))

View File

@ -631,7 +631,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
// Identify the variable being closed over and its node-id. // Identify the variable being closed over and its node-id.
let def = freevar.def; let def = freevar.def;
let def_id = ast_util::def_id_of_def(def); let def_id = ast_util::def_id_of_def(def);
assert!(def_id.crate == ast::LOCAL_CRATE); assert!(def_id.krate == ast::LOCAL_CRATE);
let upvar_id = ty::UpvarId { var_id: def_id.node, let upvar_id = ty::UpvarId { var_id: def_id.node,
closure_expr_id: expr.id }; closure_expr_id: expr.id };

View File

@ -107,7 +107,7 @@ fn type_is_defined_in_local_crate(original_type: t) -> bool {
ty_enum(def_id, _) | ty_enum(def_id, _) |
ty_trait(def_id, _, _, _, _) | ty_trait(def_id, _, _, _, _) |
ty_struct(def_id, _) => { ty_struct(def_id, _) => {
if def_id.crate == ast::LOCAL_CRATE { if def_id.krate == ast::LOCAL_CRATE {
found_nominal = true; found_nominal = true;
} }
} }
@ -209,7 +209,7 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> {
let trait_def_id = let trait_def_id =
self.cc.trait_ref_to_trait_def_id(trait_ref); self.cc.trait_ref_to_trait_def_id(trait_ref);
if trait_def_id.crate != LOCAL_CRATE { if trait_def_id.krate != LOCAL_CRATE {
let session = self.cc.crate_context.tcx.sess; let session = self.cc.crate_context.tcx.sess;
session.span_err(item.span, session.span_err(item.span,
"cannot provide an extension implementation \ "cannot provide an extension implementation \
@ -234,18 +234,18 @@ impl CoherenceChecker {
} }
} }
fn check(&self, crate: &Crate) { fn check(&self, krate: &Crate) {
// Check implementations and traits. This populates the tables // Check implementations and traits. This populates the tables
// containing the inherent methods and extension methods. It also // containing the inherent methods and extension methods. It also
// builds up the trait inheritance table. // builds up the trait inheritance table.
let mut visitor = CoherenceCheckVisitor { cc: self }; let mut visitor = CoherenceCheckVisitor { cc: self };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
// Check that there are no overlapping trait instances // Check that there are no overlapping trait instances
self.check_implementation_coherence(); self.check_implementation_coherence();
// Check whether traits with base types are in privileged scopes. // Check whether traits with base types are in privileged scopes.
self.check_privileged_scopes(crate); self.check_privileged_scopes(krate);
// Bring in external crates. It's fine for this to happen after the // Bring in external crates. It's fine for this to happen after the
// coherence checks, because we ensure by construction that no errors // coherence checks, because we ensure by construction that no errors
@ -453,12 +453,12 @@ impl CoherenceChecker {
format!("conflicting implementations for trait `{}`", format!("conflicting implementations for trait `{}`",
ty::item_path_str(self.crate_context.tcx, ty::item_path_str(self.crate_context.tcx,
trait_def_id))); trait_def_id)));
if implementation_b.did.crate == LOCAL_CRATE { if implementation_b.did.krate == LOCAL_CRATE {
session.span_note(self.span_of_impl(implementation_b), session.span_note(self.span_of_impl(implementation_b),
"note conflicting implementation here"); "note conflicting implementation here");
} else { } else {
let crate_store = self.crate_context.tcx.sess.cstore; let crate_store = self.crate_context.tcx.sess.cstore;
let cdata = crate_store.get_crate_data(implementation_b.did.crate); let cdata = crate_store.get_crate_data(implementation_b.did.krate);
session.note( session.note(
"conflicting implementation in crate `" + cdata.name + "`"); "conflicting implementation in crate `" + cdata.name + "`");
} }
@ -471,7 +471,7 @@ impl CoherenceChecker {
fn iter_impls_of_trait(&self, trait_def_id: DefId, f: |@Impl|) { fn iter_impls_of_trait(&self, trait_def_id: DefId, f: |@Impl|) {
self.iter_impls_of_trait_local(trait_def_id, |x| f(x)); self.iter_impls_of_trait_local(trait_def_id, |x| f(x));
if trait_def_id.crate == LOCAL_CRATE { if trait_def_id.krate == LOCAL_CRATE {
return; return;
} }
@ -556,9 +556,9 @@ impl CoherenceChecker {
} }
// Privileged scope checking // Privileged scope checking
fn check_privileged_scopes(&self, crate: &Crate) { fn check_privileged_scopes(&self, krate: &Crate) {
let mut visitor = PrivilegedScopeVisitor { cc: self }; let mut visitor = PrivilegedScopeVisitor{ cc: self };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId { fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
@ -578,7 +578,7 @@ impl CoherenceChecker {
let def_map = self.crate_context.tcx.def_map.borrow(); let def_map = self.crate_context.tcx.def_map.borrow();
match def_map.get().get_copy(&path_id) { match def_map.get().get_copy(&path_id) {
DefTy(def_id) | DefStruct(def_id) => { DefTy(def_id) | DefStruct(def_id) => {
if def_id.crate != LOCAL_CRATE { if def_id.krate != LOCAL_CRATE {
return false; return false;
} }
@ -640,7 +640,7 @@ impl CoherenceChecker {
} }
fn span_of_impl(&self, implementation: @Impl) -> Span { fn span_of_impl(&self, implementation: @Impl) -> Span {
assert_eq!(implementation.did.crate, LOCAL_CRATE); assert_eq!(implementation.did.krate, LOCAL_CRATE);
match self.crate_context.tcx.items.find(implementation.did.node) { match self.crate_context.tcx.items.find(implementation.did.node) {
Some(NodeItem(item, _)) => { Some(NodeItem(item, _)) => {
return item.span; return item.span;
@ -700,7 +700,7 @@ impl CoherenceChecker {
let crate_store = self.crate_context.tcx.sess.cstore; let crate_store = self.crate_context.tcx.sess.cstore;
crate_store.iter_crate_data(|crate_number, _crate_metadata| { crate_store.iter_crate_data(|crate_number, _crate_metadata| {
each_impl(crate_store, crate_number, |def_id| { each_impl(crate_store, crate_number, |def_id| {
assert_eq!(crate_number, def_id.crate); assert_eq!(crate_number, def_id.krate);
self.add_external_impl(&mut impls_seen, def_id) self.add_external_impl(&mut impls_seen, def_id)
}) })
}) })
@ -744,7 +744,7 @@ impl CoherenceChecker {
} }
_ => { _ => {
// Destructors only work on nominal types. // Destructors only work on nominal types.
if impl_info.did.crate == ast::LOCAL_CRATE { if impl_info.did.krate == ast::LOCAL_CRATE {
{ {
match tcx.items.find(impl_info.did.node) { match tcx.items.find(impl_info.did.node) {
Some(ast_map::NodeItem(item, _)) => { Some(ast_map::NodeItem(item, _)) => {
@ -845,6 +845,6 @@ fn subst_receiver_types_in_method_ty(tcx: ty::ctxt,
) )
} }
pub fn check_coherence(crate_context: @CrateCtxt, crate: &Crate) { pub fn check_coherence(crate_context: @CrateCtxt, krate: &Crate) {
CoherenceChecker::new(crate_context).check(crate); CoherenceChecker::new(crate_context).check(krate);
} }

View File

@ -73,7 +73,7 @@ impl visit::Visitor<()> for CollectItemTypesVisitor {
} }
} }
pub fn collect_item_types(ccx: @CrateCtxt, crate: &ast::Crate) { pub fn collect_item_types(ccx: @CrateCtxt, krate: &ast::Crate) {
fn collect_intrinsic_type(ccx: &CrateCtxt, fn collect_intrinsic_type(ccx: &CrateCtxt,
lang_item: ast::DefId) { lang_item: ast::DefId) {
let ty::ty_param_bounds_and_ty { ty: ty, .. } = let ty::ty_param_bounds_and_ty { ty: ty, .. } =
@ -90,7 +90,7 @@ pub fn collect_item_types(ccx: @CrateCtxt, crate: &ast::Crate) {
} }
let mut visitor = CollectItemTypesVisitor{ ccx: ccx }; let mut visitor = CollectItemTypesVisitor{ ccx: ccx };
visit::walk_crate(&mut visitor, crate, ()); visit::walk_crate(&mut visitor, krate, ());
} }
pub trait ToTy { pub trait ToTy {
@ -107,7 +107,7 @@ impl AstConv for CrateCtxt {
fn tcx(&self) -> ty::ctxt { self.tcx } fn tcx(&self) -> ty::ctxt { self.tcx }
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty { fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty {
if id.crate != ast::LOCAL_CRATE { if id.krate != ast::LOCAL_CRATE {
return csearch::get_type(self.tcx, id) return csearch::get_type(self.tcx, id)
} }
@ -283,7 +283,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
let tcx = ccx.tcx; let tcx = ccx.tcx;
let dummy_defid = ast::DefId {crate: 0, node: 0}; let dummy_defid = ast::DefId {krate: 0, node: 0};
// Represents [A',B',C'] // Represents [A',B',C']
let num_trait_bounds = trait_ty_generics.type_param_defs().len(); let num_trait_bounds = trait_ty_generics.type_param_defs().len();
@ -765,7 +765,7 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt,
} }
fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> @ty::TraitDef { fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> @ty::TraitDef {
if trait_id.crate != ast::LOCAL_CRATE { if trait_id.krate != ast::LOCAL_CRATE {
return ty::lookup_trait_def(ccx.tcx, trait_id) return ty::lookup_trait_def(ccx.tcx, trait_id)
} }

View File

@ -31,7 +31,7 @@ use syntax::parse::parse_crate_from_source_str;
use syntax::{ast, attr, parse}; use syntax::{ast, attr, parse};
struct Env { struct Env {
crate: @ast::Crate, krate: @ast::Crate,
tcx: ty::ctxt, tcx: ty::ctxt,
infcx: infer::infer_ctxt, infcx: infer::infer_ctxt,
err_messages: @DVec<~str> err_messages: @DVec<~str>
@ -59,7 +59,7 @@ fn setup_env(test_name: &str, source_string: &str) -> Env {
let lang_items = LanguageItems::new(); let lang_items = LanguageItems::new();
let parse_sess = parse::new_parse_sess(None); let parse_sess = parse::new_parse_sess(None);
let crate = parse_crate_from_source_str( let krate = parse_crate_from_source_str(
test_name.to_str(), @source_string.to_str(), test_name.to_str(), @source_string.to_str(),
cfg, parse_sess); cfg, parse_sess);
@ -68,7 +68,7 @@ fn setup_env(test_name: &str, source_string: &str) -> Env {
let infcx = infer::new_infer_ctxt(tcx); let infcx = infer::new_infer_ctxt(tcx);
return Env {crate: crate, return Env {krate: krate,
tcx: tcx, tcx: tcx,
infcx: infcx, infcx: infcx,
err_messages: messages}; err_messages: messages};
@ -94,7 +94,7 @@ impl Env {
} }
pub fn lookup_item(&self, names: &[~str]) -> ast::node_id { pub fn lookup_item(&self, names: &[~str]) -> ast::node_id {
return match search_mod(self, &self.crate.node.module, 0, names) { return match search_mod(self, &self.krate.node.module, 0, names) {
Some(id) => id, Some(id) => id,
None => { None => {
fail!("no item found: `%s`", names.connect("::")); fail!("no item found: `%s`", names.connect("::"));

View File

@ -441,7 +441,7 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
pub fn check_crate(tcx: ty::ctxt, pub fn check_crate(tcx: ty::ctxt,
trait_map: resolve::TraitMap, trait_map: resolve::TraitMap,
crate: &ast::Crate) krate: &ast::Crate)
-> (method_map, vtable_map) { -> (method_map, vtable_map) {
let time_passes = tcx.sess.time_passes(); let time_passes = tcx.sess.time_passes();
let ccx = @CrateCtxt { let ccx = @CrateCtxt {
@ -452,20 +452,20 @@ pub fn check_crate(tcx: ty::ctxt,
}; };
time(time_passes, "type collecting", (), |_| time(time_passes, "type collecting", (), |_|
collect::collect_item_types(ccx, crate)); collect::collect_item_types(ccx, krate));
// this ensures that later parts of type checking can assume that items // this ensures that later parts of type checking can assume that items
// have valid types and not error // have valid types and not error
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
time(time_passes, "variance inference", (), |_| time(time_passes, "variance inference", (), |_|
variance::infer_variance(tcx, crate)); variance::infer_variance(tcx, krate));
time(time_passes, "coherence checking", (), |_| time(time_passes, "coherence checking", (), |_|
coherence::check_coherence(ccx, crate)); coherence::check_coherence(ccx, krate));
time(time_passes, "type checking", (), |_| time(time_passes, "type checking", (), |_|
check::check_item_types(ccx, crate)); check::check_item_types(ccx, krate));
check_for_entry_fn(ccx); check_for_entry_fn(ccx);
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();

View File

@ -76,7 +76,7 @@ impl RegionScope for BindingRscope {
pub fn bound_type_regions(defs: &[ty::RegionParameterDef]) pub fn bound_type_regions(defs: &[ty::RegionParameterDef])
-> OptVec<ty::Region> { -> OptVec<ty::Region> {
assert!(defs.iter().all(|def| def.def_id.crate == ast::LOCAL_CRATE)); assert!(defs.iter().all(|def| def.def_id.krate == ast::LOCAL_CRATE));
defs.iter().enumerate().map( defs.iter().enumerate().map(
|(i, def)| ty::ReEarlyBound(def.def_id.node, i, def.ident)).collect() |(i, def)| ty::ReEarlyBound(def.def_id.node, i, def.ident)).collect()
} }

View File

@ -207,10 +207,10 @@ use syntax::visit::Visitor;
use util::ppaux::Repr; use util::ppaux::Repr;
pub fn infer_variance(tcx: ty::ctxt, pub fn infer_variance(tcx: ty::ctxt,
crate: &ast::Crate) { krate: &ast::Crate) {
let mut arena = arena::Arena::new(); let mut arena = arena::Arena::new();
let terms_cx = determine_parameters_to_be_inferred(tcx, &mut arena, crate); let terms_cx = determine_parameters_to_be_inferred(tcx, &mut arena, krate);
let constraints_cx = add_constraints_from_crate(terms_cx, crate); let constraints_cx = add_constraints_from_crate(terms_cx, krate);
solve_constraints(constraints_cx); solve_constraints(constraints_cx);
} }
@ -278,7 +278,7 @@ struct InferredInfo<'a> {
fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt, fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt,
arena: &'a mut Arena, arena: &'a mut Arena,
crate: &ast::Crate) krate: &ast::Crate)
-> TermsContext<'a> { -> TermsContext<'a> {
let mut terms_cx = TermsContext { let mut terms_cx = TermsContext {
tcx: tcx, tcx: tcx,
@ -293,7 +293,7 @@ fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt,
region_params: opt_vec::Empty } region_params: opt_vec::Empty }
}; };
visit::walk_crate(&mut terms_cx, crate, ()); visit::walk_crate(&mut terms_cx, krate, ());
terms_cx terms_cx
} }
@ -423,7 +423,7 @@ struct Constraint<'a> {
} }
fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>, fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>,
crate: &ast::Crate) krate: &ast::Crate)
-> ConstraintContext<'a> { -> ConstraintContext<'a> {
let mut invariant_lang_items = [None, ..3]; let mut invariant_lang_items = [None, ..3];
let mut covariant_lang_items = [None, ..3]; let mut covariant_lang_items = [None, ..3];
@ -461,7 +461,7 @@ fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>,
bivariant: bivariant, bivariant: bivariant,
constraints: ~[], constraints: ~[],
}; };
visit::walk_crate(&mut constraint_cx, crate, ()); visit::walk_crate(&mut constraint_cx, krate, ());
constraint_cx constraint_cx
} }
@ -496,7 +496,7 @@ impl<'a> Visitor<()> for ConstraintContext<'a> {
ast::ItemStruct(..) => { ast::ItemStruct(..) => {
let struct_fields = ty::lookup_struct_fields(tcx, did); let struct_fields = ty::lookup_struct_fields(tcx, did);
for field_info in struct_fields.iter() { for field_info in struct_fields.iter() {
assert_eq!(field_info.id.crate, ast::LOCAL_CRATE); assert_eq!(field_info.id.krate, ast::LOCAL_CRATE);
let field_ty = ty::node_id_to_type(tcx, field_info.id.node); let field_ty = ty::node_id_to_type(tcx, field_info.id.node);
self.add_constraints_from_ty(field_ty, self.covariant); self.add_constraints_from_ty(field_ty, self.covariant);
} }
@ -552,7 +552,7 @@ impl<'a> ConstraintContext<'a> {
* the type/region parameter with the given id. * the type/region parameter with the given id.
*/ */
assert_eq!(param_def_id.crate, item_def_id.crate); assert_eq!(param_def_id.krate, item_def_id.krate);
if self.invariant_lang_items[kind as uint] == Some(item_def_id) { if self.invariant_lang_items[kind as uint] == Some(item_def_id) {
self.invariant self.invariant
@ -560,7 +560,7 @@ impl<'a> ConstraintContext<'a> {
self.covariant self.covariant
} else if self.contravariant_lang_items[kind as uint] == Some(item_def_id) { } else if self.contravariant_lang_items[kind as uint] == Some(item_def_id) {
self.contravariant self.contravariant
} else if param_def_id.crate == ast::LOCAL_CRATE { } else if param_def_id.krate == ast::LOCAL_CRATE {
// Parameter on an item defined within current crate: // Parameter on an item defined within current crate:
// variance not yet inferred, so return a symbolic // variance not yet inferred, so return a symbolic
// variance. // variance.
@ -686,7 +686,7 @@ impl<'a> ConstraintContext<'a> {
} }
ty::ty_param(ty::param_ty { def_id: ref def_id, .. }) => { ty::ty_param(ty::param_ty { def_id: ref def_id, .. }) => {
assert_eq!(def_id.crate, ast::LOCAL_CRATE); assert_eq!(def_id.krate, ast::LOCAL_CRATE);
match self.terms_cx.inferred_map.find(&def_id.node) { match self.terms_cx.inferred_map.find(&def_id.node) {
Some(&index) => { Some(&index) => {
self.add_constraint(index, variance); self.add_constraint(index, variance);
@ -700,7 +700,7 @@ impl<'a> ConstraintContext<'a> {
} }
ty::ty_self(ref def_id) => { ty::ty_self(ref def_id) => {
assert_eq!(def_id.crate, ast::LOCAL_CRATE); assert_eq!(def_id.krate, ast::LOCAL_CRATE);
let index = self.inferred_index(def_id.node); let index = self.inferred_index(def_id.node);
self.add_constraint(index, variance); self.add_constraint(index, variance);
} }

View File

@ -781,7 +781,7 @@ impl Repr for ast::DefId {
// Unfortunately, there seems to be no way to attempt to print // Unfortunately, there seems to be no way to attempt to print
// a path for a def-id, so I'll just make a best effort for now // a path for a def-id, so I'll just make a best effort for now
// and otherwise fallback to just printing the crate/node pair // and otherwise fallback to just printing the crate/node pair
if self.crate == ast::LOCAL_CRATE { if self.krate == ast::LOCAL_CRATE {
{ {
match tcx.items.find(self.node) { match tcx.items.find(self.node) {
Some(ast_map::NodeItem(..)) | Some(ast_map::NodeItem(..)) |

View File

@ -615,7 +615,7 @@ pub enum Type {
typarams: Option<~[TyParamBound]>, typarams: Option<~[TyParamBound]>,
fqn: ~[~str], fqn: ~[~str],
kind: TypeKind, kind: TypeKind,
crate: ast::CrateNum, krate: ast::CrateNum,
}, },
// I have no idea how to usefully use this. // I have no idea how to usefully use this.
TyParamBinder(ast::NodeId), TyParamBinder(ast::NodeId),
@ -1250,7 +1250,7 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
} }
}).to_owned_vec(); }).to_owned_vec();
ExternalPath{ path: path, typarams: tpbs, fqn: fqn, kind: kind, ExternalPath{ path: path, typarams: tpbs, fqn: fqn, kind: kind,
crate: def_id.crate } krate: def_id.krate }
} }
} }

View File

@ -28,7 +28,7 @@ use clean;
use clean::Clean; use clean::Clean;
pub struct DocContext { pub struct DocContext {
crate: ast::Crate, krate: ast::Crate,
tycx: Option<middle::ty::ctxt>, tycx: Option<middle::ty::ctxt>,
sess: driver::session::Session sess: driver::session::Session
} }
@ -73,15 +73,15 @@ fn get_ast_and_resolve(cpath: &Path,
cfg.push(@dummy_spanned(ast::MetaWord(cfg_))); cfg.push(@dummy_spanned(ast::MetaWord(cfg_)));
} }
let crate = phase_1_parse_input(sess, cfg, &input); let krate = phase_1_parse_input(sess, cfg, &input);
let loader = &mut Loader::new(sess); let loader = &mut Loader::new(sess);
let (crate, ast_map) = phase_2_configure_and_expand(sess, loader, crate); let (krate, ast_map) = phase_2_configure_and_expand(sess, loader, krate);
let driver::driver::CrateAnalysis { let driver::driver::CrateAnalysis {
exported_items, public_items, ty_cx, .. exported_items, public_items, ty_cx, ..
} = phase_3_run_analysis_passes(sess, &crate, ast_map); } = phase_3_run_analysis_passes(sess, &krate, ast_map);
debug!("crate: {:?}", crate); debug!("crate: {:?}", krate);
return (DocContext { crate: crate, tycx: Some(ty_cx), sess: sess }, return (DocContext { krate: krate, tycx: Some(ty_cx), sess: sess },
CrateAnalysis { CrateAnalysis {
exported_items: exported_items, exported_items: exported_items,
public_items: public_items, public_items: public_items,
@ -93,11 +93,11 @@ pub fn run_core (libs: HashSet<Path>, cfgs: ~[~str], path: &Path) -> (clean::Cra
let ctxt = @ctxt; let ctxt = @ctxt;
local_data::set(super::ctxtkey, ctxt); local_data::set(super::ctxtkey, ctxt);
let crate = { let krate = {
let mut v = RustdocVisitor::new(ctxt, Some(&analysis)); let mut v = RustdocVisitor::new(ctxt, Some(&analysis));
v.visit(&ctxt.crate); v.visit(&ctxt.krate);
v.clean() v.clean()
}; };
(crate, analysis) (krate, analysis)
} }

View File

@ -160,10 +160,10 @@ fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
/// will invoke `path` with proper linking-style arguments. /// will invoke `path` with proper linking-style arguments.
fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool, fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
fqn: &[~str], kind: clean::TypeKind, fqn: &[~str], kind: clean::TypeKind,
crate: ast::CrateNum) -> fmt::Result { krate: ast::CrateNum) -> fmt::Result {
path(w, p, print_all, path(w, p, print_all,
|cache, loc| { |cache, loc| {
match *cache.extern_locations.get(&crate) { match *cache.extern_locations.get(&krate) {
render::Remote(ref s) => Some(s.clone()), render::Remote(ref s) => Some(s.clone()),
render::Local => Some("../".repeat(loc.len())), render::Local => Some("../".repeat(loc.len())),
render::Unknown => None, render::Unknown => None,
@ -310,9 +310,9 @@ impl fmt::Show for clean::Type {
typarams(f.buf, tp) typarams(f.buf, tp)
} }
clean::ExternalPath{path: ref path, typarams: ref tp, clean::ExternalPath{path: ref path, typarams: ref tp,
fqn: ref fqn, kind, crate} => { fqn: ref fqn, kind, krate} => {
if_ok!(external_path(f.buf, path, false, fqn.as_slice(), kind, if_ok!(external_path(f.buf, path, false, fqn.as_slice(), kind,
crate)) krate))
typarams(f.buf, tp) typarams(f.buf, tp)
} }
clean::Self(..) => f.buf.write("Self".as_bytes()), clean::Self(..) => f.buf.write("Self".as_bytes()),

View File

@ -15,7 +15,7 @@ use std::io;
pub struct Layout { pub struct Layout {
logo: ~str, logo: ~str,
favicon: ~str, favicon: ~str,
crate: ~str, krate: ~str,
} }
pub struct Page<'a> { pub struct Page<'a> {
@ -37,7 +37,7 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
<link href='http://fonts.googleapis.com/css?family=Oswald:700|Inconsolata:400' <link href='http://fonts.googleapis.com/css?family=Oswald:700|Inconsolata:400'
rel='stylesheet' type='text/css'> rel='stylesheet' type='text/css'>
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}{crate}/main.css\"> <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}{krate}/main.css\">
{favicon, select, none{} other{<link rel=\"shortcut icon\" href=\"#\" />}} {favicon, select, none{} other{<link rel=\"shortcut icon\" href=\"#\" />}}
</head> </head>
@ -51,7 +51,7 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
<section class=\"sidebar\"> <section class=\"sidebar\">
{logo, select, none{} other{ {logo, select, none{} other{
<a href='{root_path}{crate}/index.html'><img src='#' alt=''/></a> <a href='{root_path}{krate}/index.html'><img src='#' alt=''/></a>
}} }}
{sidebar} {sidebar}
@ -77,9 +77,9 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
<script> <script>
var rootPath = \"{root_path}\"; var rootPath = \"{root_path}\";
</script> </script>
<script src=\"{root_path}{crate}/jquery.js\"></script> <script src=\"{root_path}{krate}/jquery.js\"></script>
<script src=\"{root_path}{crate}/search-index.js\"></script> <script src=\"{root_path}{krate}/search-index.js\"></script>
<script src=\"{root_path}{crate}/main.js\"></script> <script src=\"{root_path}{krate}/main.js\"></script>
<div id=\"help\" class=\"hidden\"> <div id=\"help\" class=\"hidden\">
<div class=\"shortcuts\"> <div class=\"shortcuts\">
@ -121,7 +121,7 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
title = page.title, title = page.title,
favicon = nonestr(layout.favicon), favicon = nonestr(layout.favicon),
sidebar = *sidebar, sidebar = *sidebar,
crate = layout.crate, krate = layout.krate,
) )
} }

View File

@ -195,7 +195,7 @@ local_data_key!(pub cache_key: Arc<Cache>)
local_data_key!(pub current_location_key: ~[~str]) local_data_key!(pub current_location_key: ~[~str])
/// Generates the documentation for `crate` into the directory `dst` /// Generates the documentation for `crate` into the directory `dst`
pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> { pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
let mut cx = Context { let mut cx = Context {
dst: dst, dst: dst,
current: ~[], current: ~[],
@ -204,13 +204,13 @@ pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> {
layout: layout::Layout { layout: layout::Layout {
logo: ~"", logo: ~"",
favicon: ~"", favicon: ~"",
crate: crate.name.clone(), krate: krate.name.clone(),
}, },
include_sources: true, include_sources: true,
}; };
if_ok!(mkdir(&cx.dst)); if_ok!(mkdir(&cx.dst));
match crate.module.as_ref().map(|m| m.doc_list().unwrap_or(&[])) { match krate.module.as_ref().map(|m| m.doc_list().unwrap_or(&[])) {
Some(attrs) => { Some(attrs) => {
for attr in attrs.iter() { for attr in attrs.iter() {
match *attr { match *attr {
@ -243,11 +243,11 @@ pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> {
extern_locations: HashMap::new(), extern_locations: HashMap::new(),
privmod: false, privmod: false,
}; };
cache.stack.push(crate.name.clone()); cache.stack.push(krate.name.clone());
crate = cache.fold_crate(crate); krate = cache.fold_crate(krate);
// Add all the static files // Add all the static files
let mut dst = cx.dst.join(crate.name.as_slice()); let mut dst = cx.dst.join(krate.name.as_slice());
if_ok!(mkdir(&dst)); if_ok!(mkdir(&dst));
if_ok!(write(dst.join("jquery.js"), if_ok!(write(dst.join("jquery.js"),
include_str!("static/jquery-2.1.0.min.js"))); include_str!("static/jquery-2.1.0.min.js")));
@ -295,22 +295,22 @@ pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> {
info!("emitting source files"); info!("emitting source files");
let dst = cx.dst.join("src"); let dst = cx.dst.join("src");
if_ok!(mkdir(&dst)); if_ok!(mkdir(&dst));
let dst = dst.join(crate.name.as_slice()); let dst = dst.join(krate.name.as_slice());
if_ok!(mkdir(&dst)); if_ok!(mkdir(&dst));
let mut folder = SourceCollector { let mut folder = SourceCollector {
dst: dst, dst: dst,
seen: HashSet::new(), seen: HashSet::new(),
cx: &mut cx, cx: &mut cx,
}; };
crate = folder.fold_crate(crate); krate = folder.fold_crate(krate);
} }
for (&n, e) in crate.externs.iter() { for (&n, e) in krate.externs.iter() {
cache.extern_locations.insert(n, extern_location(e, &cx.dst)); cache.extern_locations.insert(n, extern_location(e, &cx.dst));
} }
// And finally render the whole crate's documentation // And finally render the whole crate's documentation
cx.crate(crate, cache) cx.krate(krate, cache)
} }
/// Writes the entire contents of a string to a destination, not attempting to /// Writes the entire contents of a string to a destination, not attempting to
@ -677,12 +677,12 @@ impl Context {
/// ///
/// This currently isn't parallelized, but it'd be pretty easy to add /// This currently isn't parallelized, but it'd be pretty easy to add
/// parallelization to this function. /// parallelization to this function.
fn crate(self, mut crate: clean::Crate, cache: Cache) -> io::IoResult<()> { fn krate(self, mut krate: clean::Crate, cache: Cache) -> io::IoResult<()> {
let mut item = match crate.module.take() { let mut item = match krate.module.take() {
Some(i) => i, Some(i) => i,
None => return Ok(()) None => return Ok(())
}; };
item.name = Some(crate.name); item.name = Some(krate.name);
// using a rwarc makes this parallelizable in the future // using a rwarc makes this parallelizable in the future
local_data::set(cache_key, Arc::new(cache)); local_data::set(cache_key, Arc::new(cache));
@ -827,10 +827,10 @@ impl<'a> fmt::Show for Item<'a> {
}; };
if_ok!(write!(fmt.buf, if_ok!(write!(fmt.buf,
"<a class='source' "<a class='source'
href='{root}src/{crate}/{path}.html\\#{href}'>\ href='{root}src/{krate}/{path}.html\\#{href}'>\
[src]</a>", [src]</a>",
root = self.cx.root_path, root = self.cx.root_path,
crate = self.cx.layout.crate, krate = self.cx.layout.krate,
path = path.connect("/"), path = path.connect("/"),
href = href)); href = href));
} }

View File

@ -151,7 +151,7 @@ pub fn main_args(args: &[~str]) -> int {
return 0; return 0;
} }
let (crate, res) = match acquire_input(input, &matches) { let (krate, res) = match acquire_input(input, &matches) {
Ok(pair) => pair, Ok(pair) => pair,
Err(s) => { Err(s) => {
println!("input error: {}", s); println!("input error: {}", s);
@ -164,13 +164,13 @@ pub fn main_args(args: &[~str]) -> int {
let output = matches.opt_str("o").map(|s| Path::new(s)); let output = matches.opt_str("o").map(|s| Path::new(s));
match matches.opt_str("w") { match matches.opt_str("w") {
Some(~"html") | None => { Some(~"html") | None => {
match html::render::run(crate, output.unwrap_or(Path::new("doc"))) { match html::render::run(krate, output.unwrap_or(Path::new("doc"))) {
Ok(()) => {} Ok(()) => {}
Err(e) => fail!("failed to generate documentation: {}", e), Err(e) => fail!("failed to generate documentation: {}", e),
} }
} }
Some(~"json") => { Some(~"json") => {
match json_output(crate, res, output.unwrap_or(Path::new("doc.json"))) { match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) {
Ok(()) => {} Ok(()) => {}
Err(e) => fail!("failed to write json: {}", e), Err(e) => fail!("failed to write json: {}", e),
} }
@ -219,7 +219,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
let cfgs = matches.opt_strs("cfg"); let cfgs = matches.opt_strs("cfg");
let cr = Path::new(cratefile); let cr = Path::new(cratefile);
info!("starting to run rustc"); info!("starting to run rustc");
let (crate, analysis) = std::task::try(proc() { let (krate, analysis) = std::task::try(proc() {
let cr = cr; let cr = cr;
core::run_core(libs.move_iter().collect(), cfgs, &cr) core::run_core(libs.move_iter().collect(), cfgs, &cr)
}).unwrap(); }).unwrap();
@ -228,7 +228,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
// Process all of the crate attributes, extracting plugin metadata along // Process all of the crate attributes, extracting plugin metadata along
// with the passes which we are supposed to run. // with the passes which we are supposed to run.
match crate.module.get_ref().doc_list() { match krate.module.get_ref().doc_list() {
Some(nested) => { Some(nested) => {
for inner in nested.iter() { for inner in nested.iter() {
match *inner { match *inner {
@ -277,7 +277,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
// Run everything! // Run everything!
info!("Executing passes/plugins"); info!("Executing passes/plugins");
return pm.run_plugins(crate); return pm.run_plugins(krate);
} }
/// This input format purely deserializes the json output file. No passes are /// This input format purely deserializes the json output file. No passes are
@ -302,7 +302,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
Some(..) => return Err(~"malformed json"), Some(..) => return Err(~"malformed json"),
None => return Err(~"expected a schema version"), None => return Err(~"expected a schema version"),
} }
let crate = match obj.pop(&~"crate") { let krate = match obj.pop(&~"crate") {
Some(json) => { Some(json) => {
let mut d = json::Decoder::new(json); let mut d = json::Decoder::new(json);
Decodable::decode(&mut d) Decodable::decode(&mut d)
@ -312,7 +312,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
// FIXME: this should read from the "plugins" field, but currently // FIXME: this should read from the "plugins" field, but currently
// Json doesn't implement decodable... // Json doesn't implement decodable...
let plugin_output = ~[]; let plugin_output = ~[];
Ok((crate, plugin_output)) Ok((krate, plugin_output))
} }
Ok(..) => Err(~"malformed json input: expected an object at the top"), Ok(..) => Err(~"malformed json input: expected an object at the top"),
} }
@ -320,7 +320,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
/// Outputs the crate/plugin json as a giant json blob at the specified /// Outputs the crate/plugin json as a giant json blob at the specified
/// destination. /// destination.
fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson],
dst: Path) -> io::IoResult<()> { dst: Path) -> io::IoResult<()> {
// { // {
// "schema": version, // "schema": version,
@ -337,7 +337,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson],
let mut w = MemWriter::new(); let mut w = MemWriter::new();
{ {
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer); let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
crate.encode(&mut encoder); krate.encode(&mut encoder);
} }
str::from_utf8_owned(w.unwrap()).unwrap() str::from_utf8_owned(w.unwrap()).unwrap()
}; };

View File

@ -21,7 +21,7 @@ use fold;
use fold::DocFolder; use fold::DocFolder;
/// Strip items marked `#[doc(hidden)]` /// Strip items marked `#[doc(hidden)]`
pub fn strip_hidden(crate: clean::Crate) -> plugins::PluginResult { pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
struct Stripper; struct Stripper;
impl fold::DocFolder for Stripper { impl fold::DocFolder for Stripper {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
@ -45,19 +45,19 @@ pub fn strip_hidden(crate: clean::Crate) -> plugins::PluginResult {
} }
} }
let mut stripper = Stripper; let mut stripper = Stripper;
let crate = stripper.fold_crate(crate); let krate = stripper.fold_crate(krate);
(crate, None) (krate, None)
} }
/// Strip private items from the point of view of a crate or externally from a /// Strip private items from the point of view of a crate or externally from a
/// crate, specified by the `xcrate` flag. /// crate, specified by the `xcrate` flag.
pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult { pub fn strip_private(krate: clean::Crate) -> plugins::PluginResult {
// This stripper collects all *retained* nodes. // This stripper collects all *retained* nodes.
let mut retained = HashSet::new(); let mut retained = HashSet::new();
let exported_items = local_data::get(super::analysiskey, |analysis| { let exported_items = local_data::get(super::analysiskey, |analysis| {
analysis.unwrap().exported_items.clone() analysis.unwrap().exported_items.clone()
}); });
let mut crate = crate; let mut krate = krate;
// strip all private items // strip all private items
{ {
@ -65,15 +65,15 @@ pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult {
retained: &mut retained, retained: &mut retained,
exported_items: &exported_items, exported_items: &exported_items,
}; };
crate = stripper.fold_crate(crate); krate = stripper.fold_crate(krate);
} }
// strip all private implementations of traits // strip all private implementations of traits
{ {
let mut stripper = ImplStripper(&retained); let mut stripper = ImplStripper(&retained);
crate = stripper.fold_crate(crate); krate = stripper.fold_crate(krate);
} }
(crate, None) (krate, None)
} }
struct Stripper<'a> { struct Stripper<'a> {
@ -174,7 +174,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
} }
pub fn unindent_comments(crate: clean::Crate) -> plugins::PluginResult { pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
struct CommentCleaner; struct CommentCleaner;
impl fold::DocFolder for CommentCleaner { impl fold::DocFolder for CommentCleaner {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
@ -192,11 +192,11 @@ pub fn unindent_comments(crate: clean::Crate) -> plugins::PluginResult {
} }
} }
let mut cleaner = CommentCleaner; let mut cleaner = CommentCleaner;
let crate = cleaner.fold_crate(crate); let krate = cleaner.fold_crate(krate);
(crate, None) (krate, None)
} }
pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult { pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
struct Collapser; struct Collapser;
impl fold::DocFolder for Collapser { impl fold::DocFolder for Collapser {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
@ -223,8 +223,8 @@ pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult {
} }
} }
let mut collapser = Collapser; let mut collapser = Collapser;
let crate = collapser.fold_crate(crate); let krate = collapser.fold_crate(krate);
(crate, None) (krate, None)
} }
pub fn unindent(s: &str) -> ~str { pub fn unindent(s: &str) -> ~str {

View File

@ -57,15 +57,15 @@ impl PluginManager {
self.callbacks.push(plugin); self.callbacks.push(plugin);
} }
/// Run all the loaded plugins over the crate, returning their results /// Run all the loaded plugins over the crate, returning their results
pub fn run_plugins(&self, crate: clean::Crate) -> (clean::Crate, ~[PluginJson]) { pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, ~[PluginJson]) {
let mut out_json = ~[]; let mut out_json = ~[];
let mut crate = crate; let mut krate = krate;
for &callback in self.callbacks.iter() { for &callback in self.callbacks.iter() {
let (c, res) = callback(crate); let (c, res) = callback(krate);
crate = c; krate = c;
out_json.push(res); out_json.push(res);
} }
(crate, out_json) (krate, out_json)
} }
} }

View File

@ -58,31 +58,31 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int {
span_diagnostic_handler); span_diagnostic_handler);
let cfg = driver::build_configuration(sess); let cfg = driver::build_configuration(sess);
let crate = driver::phase_1_parse_input(sess, cfg, &input); let krate = driver::phase_1_parse_input(sess, cfg, &input);
let loader = &mut Loader::new(sess); let loader = &mut Loader::new(sess);
let (crate, _) = driver::phase_2_configure_and_expand(sess, loader, crate); let (krate, _) = driver::phase_2_configure_and_expand(sess, loader, krate);
let ctx = @core::DocContext { let ctx = @core::DocContext {
crate: crate, krate: krate,
tycx: None, tycx: None,
sess: sess, sess: sess,
}; };
local_data::set(super::ctxtkey, ctx); local_data::set(super::ctxtkey, ctx);
let mut v = RustdocVisitor::new(ctx, None); let mut v = RustdocVisitor::new(ctx, None);
v.visit(&ctx.crate); v.visit(&ctx.krate);
let crate = v.clean(); let krate = v.clean();
let (crate, _) = passes::unindent_comments(crate); let (krate, _) = passes::unindent_comments(krate);
let (crate, _) = passes::collapse_docs(crate); let (krate, _) = passes::collapse_docs(krate);
let mut collector = Collector { let mut collector = Collector {
tests: ~[], tests: ~[],
names: ~[], names: ~[],
cnt: 0, cnt: 0,
libs: libs, libs: libs,
cratename: crate.name.to_owned(), cratename: krate.name.to_owned(),
}; };
collector.fold_crate(crate); collector.fold_crate(krate);
let args = matches.opt_strs("test-args"); let args = matches.opt_strs("test-args");
let mut args = args.iter().flat_map(|s| s.words()).map(|s| s.to_owned()); let mut args = args.iter().flat_map(|s| s.words()).map(|s| s.to_owned());

View File

@ -38,12 +38,12 @@ impl<'a> RustdocVisitor<'a> {
} }
} }
pub fn visit(&mut self, crate: &ast::Crate) { pub fn visit(&mut self, krate: &ast::Crate) {
self.attrs = crate.attrs.clone(); self.attrs = krate.attrs.clone();
self.module = self.visit_mod_contents(crate.span, crate.attrs.clone(), self.module = self.visit_mod_contents(krate.span, krate.attrs.clone(),
ast::Public, ast::CRATE_NODE_ID, ast::Public, ast::CRATE_NODE_ID,
&crate.module, None); &krate.module, None);
} }
pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef, pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,

View File

@ -181,7 +181,7 @@ pub type NodeId = u32;
#[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, IterBytes, ToStr)] #[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, IterBytes, ToStr)]
pub struct DefId { pub struct DefId {
crate: CrateNum, krate: CrateNum,
node: NodeId, node: NodeId,
} }

View File

@ -406,7 +406,7 @@ pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate,
diag: diag, diag: diag,
fold_ops: fold_ops fold_ops: fold_ops
}; };
let crate = cx.fold_crate(c); let krate = cx.fold_crate(c);
if log_enabled!(logging::DEBUG) { if log_enabled!(logging::DEBUG) {
let map = cx.map.map.borrow(); let map = cx.map.map.borrow();
@ -421,7 +421,7 @@ pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate,
entries, vector_length, (entries as f64 / vector_length as f64) * 100.); entries, vector_length, (entries as f64 / vector_length as f64) * 100.);
} }
(crate, cx.map) (krate, cx.map)
} }
// Used for items loaded from external crate that are being inlined into this // Used for items loaded from external crate that are being inlined into this

View File

@ -38,10 +38,10 @@ pub fn path_to_ident(path: &Path) -> Ident {
} }
pub fn local_def(id: NodeId) -> DefId { pub fn local_def(id: NodeId) -> DefId {
ast::DefId { crate: LOCAL_CRATE, node: id } ast::DefId { krate: LOCAL_CRATE, node: id }
} }
pub fn is_local(did: ast::DefId) -> bool { did.crate == LOCAL_CRATE } pub fn is_local(did: ast::DefId) -> bool { did.krate == LOCAL_CRATE }
pub fn stmt_id(s: &Stmt) -> NodeId { pub fn stmt_id(s: &Stmt) -> NodeId {
match s.node { match s.node {

View File

@ -264,7 +264,7 @@ pub struct MacroCrate {
} }
pub trait CrateLoader { pub trait CrateLoader {
fn load_crate(&mut self, crate: &ast::ViewItem) -> MacroCrate; fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate;
fn get_exported_macros(&mut self, crate_num: ast::CrateNum) -> ~[~str]; fn get_exported_macros(&mut self, crate_num: ast::CrateNum) -> ~[~str];
fn get_registrar_symbol(&mut self, crate_num: ast::CrateNum) -> Option<~str>; fn get_registrar_symbol(&mut self, crate_num: ast::CrateNum) -> Option<~str>;
} }

View File

@ -414,10 +414,10 @@ pub fn expand_view_item(vi: &ast::ViewItem,
noop_fold_view_item(vi, fld) noop_fold_view_item(vi, fld)
} }
fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) { fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) {
let MacroCrate { lib, cnum } = fld.cx.loader.load_crate(crate); let MacroCrate { lib, cnum } = fld.cx.loader.load_crate(krate);
let crate_name = match crate.node { let crate_name = match krate.node {
ast::ViewItemExternMod(ref name, _, _) => { ast::ViewItemExternMod(ref name, _, _) => {
let string = token::get_ident(name.name); let string = token::get_ident(name.name);
string.get().to_str() string.get().to_str()
@ -453,19 +453,19 @@ fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) {
// this is fatal: there are almost certainly macros we need // this is fatal: there are almost certainly macros we need
// inside this crate, so continue would spew "macro undefined" // inside this crate, so continue would spew "macro undefined"
// errors // errors
Err(err) => fld.cx.span_fatal(crate.span, err) Err(err) => fld.cx.span_fatal(krate.span, err)
}; };
unsafe { unsafe {
let registrar: MacroCrateRegistrationFun = match lib.symbol(registrar) { let registrar: MacroCrateRegistrationFun = match lib.symbol(registrar) {
Ok(registrar) => registrar, Ok(registrar) => registrar,
// again fatal if we can't register macros // again fatal if we can't register macros
Err(err) => fld.cx.span_fatal(crate.span, err) Err(err) => fld.cx.span_fatal(krate.span, err)
}; };
registrar(|name, extension| { registrar(|name, extension| {
let extension = match extension { let extension = match extension {
NormalTT(ext, _) => NormalTT(ext, Some(crate.span)), NormalTT(ext, _) => NormalTT(ext, Some(krate.span)),
IdentTT(ext, _) => IdentTT(ext, Some(crate.span)), IdentTT(ext, _) => IdentTT(ext, Some(krate.span)),
ItemDecorator(ext) => ItemDecorator(ext), ItemDecorator(ext) => ItemDecorator(ext),
}; };
fld.extsbox.insert(name, extension); fld.extsbox.insert(name, extension);
@ -1036,10 +1036,10 @@ mod test {
} }
} }
//fn fake_print_crate(crate: &ast::Crate) { //fn fake_print_crate(krate: &ast::Crate) {
// let mut out = ~std::io::stderr() as ~std::io::Writer; // let mut out = ~std::io::stderr() as ~std::io::Writer;
// let mut s = pprust::rust_printer(out, get_ident_interner()); // let mut s = pprust::rust_printer(out, get_ident_interner());
// pprust::print_crate_(&mut s, crate); // pprust::print_crate_(&mut s, krate);
//} //}
fn expand_crate_str(crate_str: ~str) -> ast::Crate { fn expand_crate_str(crate_str: ~str) -> ast::Crate {

View File

@ -35,16 +35,16 @@ impl Visitor<()> for MacroRegistrarContext {
} }
pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler, pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler,
crate: &ast::Crate) -> Option<ast::DefId> { krate: &ast::Crate) -> Option<ast::DefId> {
let mut ctx = MacroRegistrarContext { registrars: ~[] }; let mut ctx = MacroRegistrarContext { registrars: ~[] };
visit::walk_crate(&mut ctx, crate, ()); visit::walk_crate(&mut ctx, krate, ());
match ctx.registrars.len() { match ctx.registrars.len() {
0 => None, 0 => None,
1 => { 1 => {
let (node_id, _) = ctx.registrars.pop().unwrap(); let (node_id, _) = ctx.registrars.pop().unwrap();
Some(ast::DefId { Some(ast::DefId {
crate: ast::LOCAL_CRATE, krate: ast::LOCAL_CRATE,
node: node_id node: node_id
}) })
}, },

View File

@ -859,8 +859,8 @@ mod test {
// this version doesn't care about getting comments or docstrings in. // this version doesn't care about getting comments or docstrings in.
fn fake_print_crate(s: &mut pprust::State, fn fake_print_crate(s: &mut pprust::State,
crate: &ast::Crate) -> io::IoResult<()> { krate: &ast::Crate) -> io::IoResult<()> {
pprust::print_mod(s, &crate.module, crate.attrs) pprust::print_mod(s, &krate.module, krate.attrs)
} }
// change every identifier to "zz" // change every identifier to "zz"

View File

@ -30,7 +30,6 @@ pub enum ObsoleteSyntax {
ObsoleteSwap, ObsoleteSwap,
ObsoleteUnsafeBlock, ObsoleteUnsafeBlock,
ObsoleteBareFnType, ObsoleteBareFnType,
ObsoleteNamedExternModule,
ObsoleteMultipleLocalDecl, ObsoleteMultipleLocalDecl,
ObsoleteUnsafeExternFn, ObsoleteUnsafeExternFn,
ObsoleteTraitFuncVisibility, ObsoleteTraitFuncVisibility,
@ -42,7 +41,6 @@ pub enum ObsoleteSyntax {
ObsoleteBoxedClosure, ObsoleteBoxedClosure,
ObsoleteClosureType, ObsoleteClosureType,
ObsoleteMultipleImport, ObsoleteMultipleImport,
ObsoleteExternModAttributesInParens,
ObsoleteManagedPattern, ObsoleteManagedPattern,
ObsoleteManagedString, ObsoleteManagedString,
ObsoleteManagedVec, ObsoleteManagedVec,
@ -86,11 +84,6 @@ impl ParserObsoleteMethods for Parser {
"bare function type", "bare function type",
"use `|A| -> B` or `extern fn(A) -> B` instead" "use `|A| -> B` or `extern fn(A) -> B` instead"
), ),
ObsoleteNamedExternModule => (
"named external module",
"instead of `extern mod foo { ... }`, write `mod foo { \
extern { ... } }`"
),
ObsoleteMultipleLocalDecl => ( ObsoleteMultipleLocalDecl => (
"declaration of multiple locals at once", "declaration of multiple locals at once",
"instead of e.g. `let a = 1, b = 2`, write \ "instead of e.g. `let a = 1, b = 2`, write \
@ -141,11 +134,6 @@ impl ParserObsoleteMethods for Parser {
"multiple imports", "multiple imports",
"only one import is allowed per `use` statement" "only one import is allowed per `use` statement"
), ),
ObsoleteExternModAttributesInParens => (
"`extern mod` with linkage attribute list",
"use `extern mod foo = \"bar\";` instead of \
`extern mod foo (name = \"bar\")`"
),
ObsoleteManagedPattern => ( ObsoleteManagedPattern => (
"managed pointer pattern", "managed pointer pattern",
"use a nested `match` expression instead of a managed box \ "use a nested `match` expression instead of a managed box \

View File

@ -866,7 +866,10 @@ impl Parser {
*/ */
let opt_abis = self.parse_opt_abis(); let opt_abis = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abis()
} else { None };
let abis = opt_abis.unwrap_or(AbiSet::Rust()); let abis = opt_abis.unwrap_or(AbiSet::Rust());
let purity = self.parse_unsafety(); let purity = self.parse_unsafety();
self.expect_keyword(keywords::Fn); self.expect_keyword(keywords::Fn);
@ -4308,91 +4311,78 @@ impl Parser {
} }
} }
// parse extern foo; or extern mod foo { ... } or extern { ... } /// Parse extern crate links
///
/// # Example
///
/// extern crate extra;
/// extern crate foo = "bar";
fn parse_item_extern_crate(&mut self,
lo: BytePos,
visibility: Visibility,
attrs: ~[Attribute])
-> ItemOrViewItem {
let (maybe_path, ident) = match self.token {
token::IDENT(..) => {
let the_ident = self.parse_ident();
self.expect_one_of(&[], &[token::EQ, token::SEMI]);
let path = if self.token == token::EQ {
self.bump();
Some(self.parse_str())
} else {None};
self.expect(&token::SEMI);
(path, the_ident)
}
_ => {
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
format!("expected extern crate name but found `{}`",
token_str));
}
};
IoviViewItem(ast::ViewItem {
node: ViewItemExternMod(ident, maybe_path, ast::DUMMY_NODE_ID),
attrs: attrs,
vis: visibility,
span: mk_sp(lo, self.last_span.hi)
})
}
/// Parse `extern` for foreign ABIs
/// modules.
///
/// `extern` is expected to have been
/// consumed before calling this method
///
/// # Examples:
///
/// extern "C" {}
/// extern {}
fn parse_item_foreign_mod(&mut self, fn parse_item_foreign_mod(&mut self,
lo: BytePos, lo: BytePos,
opt_abis: Option<AbiSet>, opt_abis: Option<AbiSet>,
visibility: Visibility, visibility: Visibility,
attrs: ~[Attribute], attrs: ~[Attribute])
items_allowed: bool)
-> ItemOrViewItem { -> ItemOrViewItem {
let mut must_be_named_mod = false;
if self.is_keyword(keywords::Mod) {
must_be_named_mod = true;
self.expect_keyword(keywords::Mod);
} else if self.token != token::LBRACE {
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
format!("expected `\\{` or `mod` but found `{}`",
token_str))
}
let (named, maybe_path, ident) = match self.token { self.expect(&token::LBRACE);
token::IDENT(..) => {
let the_ident = self.parse_ident();
let path = if self.token == token::EQ {
self.bump();
Some(self.parse_str())
}
else { None };
(true, path, the_ident)
}
_ => {
if must_be_named_mod {
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
format!("expected foreign module name but \
found `{}`",
token_str))
}
(false, None, let abis = opt_abis.unwrap_or(AbiSet::C());
special_idents::clownshoes_foreign_mod)
}
};
// extern mod foo { ... } or extern { ... } let (inner, next) = self.parse_inner_attrs_and_next();
if items_allowed && self.eat(&token::LBRACE) { let m = self.parse_foreign_mod_items(abis, next);
// `extern mod foo { ... }` is obsolete. self.expect(&token::RBRACE);
if named {
self.obsolete(self.last_span, ObsoleteNamedExternModule);
}
let abis = opt_abis.unwrap_or(AbiSet::C()); let item = self.mk_item(lo,
self.last_span.hi,
let (inner, next) = self.parse_inner_attrs_and_next(); special_idents::clownshoes_foreign_mod,
let m = self.parse_foreign_mod_items(abis, next); ItemForeignMod(m),
self.expect(&token::RBRACE); visibility,
maybe_append(attrs, Some(inner)));
let item = self.mk_item(lo, return IoviItem(item);
self.last_span.hi,
ident,
ItemForeignMod(m),
visibility,
maybe_append(attrs, Some(inner)));
return IoviItem(item);
}
if opt_abis.is_some() {
self.span_err(self.span, "an ABI may not be specified here");
}
if self.token == token::LPAREN {
// `extern mod foo (name = "bar"[,vers = "version"]) is obsolete,
// `extern mod foo = "bar#[version]";` should be used.
// Parse obsolete options to avoid wired parser errors
self.parse_optional_meta();
self.obsolete(self.span, ObsoleteExternModAttributesInParens);
}
// extern mod foo;
self.expect(&token::SEMI);
IoviViewItem(ast::ViewItem {
node: ViewItemExternMod(ident, maybe_path, ast::DUMMY_NODE_ID),
attrs: attrs,
vis: visibility,
span: mk_sp(lo, self.last_span.hi)
})
} }
// parse type Foo = Bar; // parse type Foo = Bar;
@ -4504,10 +4494,6 @@ impl Parser {
// Parses a string as an ABI spec on an extern type or module. Consumes // Parses a string as an ABI spec on an extern type or module. Consumes
// the `extern` keyword, if one is found. // the `extern` keyword, if one is found.
fn parse_opt_abis(&mut self) -> Option<AbiSet> { fn parse_opt_abis(&mut self) -> Option<AbiSet> {
if !self.eat_keyword(keywords::Extern) {
return None
}
match self.token { match self.token {
token::LIT_STR(s) token::LIT_STR(s)
| token::LIT_STR_RAW(s, _) => { | token::LIT_STR_RAW(s, _) => {
@ -4585,7 +4571,20 @@ impl Parser {
}); });
} }
// either a view item or an item: // either a view item or an item:
if self.is_keyword(keywords::Extern) { if self.eat_keyword(keywords::Extern) {
let next_is_mod = self.eat_keyword(keywords::Mod);
if next_is_mod || self.eat_keyword(keywords::Crate) {
// NOTE(flaper87): Uncomment this when this changes gets into stage0
//
// if next_is_mod {
// self.span_err(self.span,
// format!("`extern mod` is obsolete, use `extern crate` instead \
// to refer to external crates."))
// }
return self.parse_item_extern_crate(lo, visibility, attrs);
}
let opt_abis = self.parse_opt_abis(); let opt_abis = self.parse_opt_abis();
if self.eat_keyword(keywords::Fn) { if self.eat_keyword(keywords::Fn) {
@ -4600,12 +4599,15 @@ impl Parser {
visibility, visibility,
maybe_append(attrs, extra_attrs)); maybe_append(attrs, extra_attrs));
return IoviItem(item); return IoviItem(item);
} else { } else if self.token == token::LBRACE {
// EXTERN MODULE ITEM (IoviViewItem) return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs);
return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs,
true);
} }
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
format!("expected `\\{` or `fn` but found `{}`", token_str));
} }
// the rest are all guaranteed to be items: // the rest are all guaranteed to be items:
if self.is_keyword(keywords::Static) { if self.is_keyword(keywords::Static) {
// STATIC ITEM // STATIC ITEM

View File

@ -462,37 +462,38 @@ declare_special_idents_and_keywords! {
(28, Loop, "loop"); (28, Loop, "loop");
(29, Match, "match"); (29, Match, "match");
(30, Mod, "mod"); (30, Mod, "mod");
(31, Mut, "mut"); (31, Crate, "crate");
(32, Once, "once"); (32, Mut, "mut");
(33, Priv, "priv"); (33, Once, "once");
(34, Pub, "pub"); (34, Priv, "priv");
(35, Ref, "ref"); (35, Pub, "pub");
(36, Return, "return"); (36, Ref, "ref");
(37, Return, "return");
// Static and Self are also special idents (prefill de-dupes) // Static and Self are also special idents (prefill de-dupes)
(super::STATIC_KEYWORD_NAME, Static, "static"); (super::STATIC_KEYWORD_NAME, Static, "static");
(super::SELF_KEYWORD_NAME, Self, "self"); (super::SELF_KEYWORD_NAME, Self, "self");
(37, Struct, "struct"); (38, Struct, "struct");
(38, Super, "super"); (39, Super, "super");
(39, True, "true"); (40, True, "true");
(40, Trait, "trait"); (41, Trait, "trait");
(41, Type, "type"); (42, Type, "type");
(42, Unsafe, "unsafe"); (43, Unsafe, "unsafe");
(43, Use, "use"); (44, Use, "use");
(44, While, "while"); (45, While, "while");
(45, Continue, "continue"); (46, Continue, "continue");
(46, Proc, "proc"); (47, Proc, "proc");
(47, Box, "box"); (48, Box, "box");
'reserved: 'reserved:
(48, Alignof, "alignof"); (49, Alignof, "alignof");
(49, Be, "be"); (50, Be, "be");
(50, Offsetof, "offsetof"); (51, Offsetof, "offsetof");
(51, Pure, "pure"); (52, Pure, "pure");
(52, Sizeof, "sizeof"); (53, Sizeof, "sizeof");
(53, Typeof, "typeof"); (54, Typeof, "typeof");
(54, Unsized, "unsized"); (55, Unsized, "unsized");
(55, Yield, "yield"); (56, Yield, "yield");
(56, Do, "do"); (57, Do, "do");
} }
} }

View File

@ -116,7 +116,7 @@ pub static default_columns: uint = 78u;
pub fn print_crate(cm: @CodeMap, pub fn print_crate(cm: @CodeMap,
intr: @IdentInterner, intr: @IdentInterner,
span_diagnostic: @diagnostic::SpanHandler, span_diagnostic: @diagnostic::SpanHandler,
crate: &ast::Crate, krate: &ast::Crate,
filename: ~str, filename: ~str,
input: &mut io::Reader, input: &mut io::Reader,
out: ~io::Writer, out: ~io::Writer,
@ -147,11 +147,11 @@ pub fn print_crate(cm: @CodeMap,
boxes: RefCell::new(~[]), boxes: RefCell::new(~[]),
ann: ann ann: ann
}; };
print_crate_(&mut s, crate) print_crate_(&mut s, krate)
} }
pub fn print_crate_(s: &mut State, crate: &ast::Crate) -> io::IoResult<()> { pub fn print_crate_(s: &mut State, krate: &ast::Crate) -> io::IoResult<()> {
if_ok!(print_mod(s, &crate.module, crate.attrs)); if_ok!(print_mod(s, &krate.module, krate.attrs));
if_ok!(print_remaining_comments(s)); if_ok!(print_remaining_comments(s));
if_ok!(eof(&mut s.s)); if_ok!(eof(&mut s.s));
Ok(()) Ok(())

View File

@ -132,8 +132,8 @@ pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
} }
pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) { pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, krate: &Crate, env: E) {
visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env) visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env)
} }
pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) { pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) {

View File

@ -0,0 +1,14 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Verifies that the expected token errors for `extern crate` are
// raised
extern "C" mod foo; //~ERROR expected `{` or `fn` but found `mod`

View File

@ -0,0 +1,14 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Verifies that the expected token errors for `extern crate` are
// raised
extern crate foo {} //~ERROR expected one of `=`, `;` but found `{`

View File

@ -8,11 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
extern mod obsolete_name {
//~^ ERROR obsolete syntax: named external module
fn bar();
}
trait A { trait A {
pub fn foo(); //~ ERROR: visibility not necessary pub fn foo(); //~ ERROR: visibility not necessary
pub fn bar(); //~ ERROR: visibility not necessary pub fn bar(); //~ ERROR: visibility not necessary

View File

@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate extra;
extern mod mystd = "std";
pub fn main() {}