From 968633b60ad7f2fd0c5663e92b06f2c9d21964a8 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Wed, 5 Feb 2014 22:15:24 +0100 Subject: [PATCH 1/3] Replace `crate` usage with `krate` This patch replaces all `crate` usage with `krate` before introducing the new keyword. This ensures that after introducing the keyword, there won't be any compilation errors. krate might not be the most expressive substitution for crate but it's a very close abbreviation for it. `module` was already used in several places already. --- src/librustc/driver/driver.rs | 110 +++++++++--------- src/librustc/driver/session.rs | 4 +- src/librustc/front/assign_node_ids_and_map.rs | 4 +- src/librustc/front/config.rs | 10 +- src/librustc/front/feature_gate.rs | 6 +- src/librustc/front/show_span.rs | 4 +- src/librustc/front/std_inject.rs | 56 ++++----- src/librustc/front/test.rs | 24 ++-- src/librustc/metadata/creader.rs | 12 +- src/librustc/metadata/csearch.rs | 54 ++++----- src/librustc/metadata/decoder.rs | 28 ++--- src/librustc/metadata/encoder.rs | 50 ++++---- src/librustc/metadata/tydecode.rs | 8 +- src/librustc/middle/astencode.rs | 8 +- src/librustc/middle/borrowck/mod.rs | 4 +- src/librustc/middle/check_const.rs | 4 +- src/librustc/middle/check_loop.rs | 4 +- src/librustc/middle/check_match.rs | 4 +- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/dead.rs | 14 +-- src/librustc/middle/effect.rs | 4 +- src/librustc/middle/entry.rs | 6 +- src/librustc/middle/freevars.rs | 4 +- src/librustc/middle/kind.rs | 4 +- src/librustc/middle/lang_items.rs | 14 +-- src/librustc/middle/lint.rs | 14 +-- src/librustc/middle/liveness.rs | 4 +- src/librustc/middle/moves.rs | 4 +- src/librustc/middle/privacy.rs | 10 +- src/librustc/middle/reachable.rs | 6 +- src/librustc/middle/region.rs | 4 +- src/librustc/middle/resolve.rs | 40 +++---- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/middle/trans/base.rs | 20 ++-- src/librustc/middle/trans/callee.rs | 12 +- src/librustc/middle/trans/debuginfo.rs | 10 +- src/librustc/middle/trans/expr.rs | 6 +- src/librustc/middle/trans/meth.rs | 2 +- src/librustc/middle/trans/type_of.rs | 4 +- src/librustc/middle/ty.rs | 26 ++--- src/librustc/middle/typeck/check/method.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 8 +- src/librustc/middle/typeck/check/regionck.rs | 2 +- src/librustc/middle/typeck/coherence.rs | 34 +++--- src/librustc/middle/typeck/collect.rs | 10 +- src/librustc/middle/typeck/infer/test.rs | 8 +- src/librustc/middle/typeck/mod.rs | 10 +- src/librustc/middle/typeck/rscope.rs | 2 +- src/librustc/middle/typeck/variance.rs | 24 ++-- src/librustc/util/ppaux.rs | 2 +- src/librustdoc/clean.rs | 4 +- src/librustdoc/core.rs | 18 +-- src/librustdoc/html/format.rs | 8 +- src/librustdoc/html/layout.rs | 14 +-- src/librustdoc/html/render.rs | 30 ++--- src/librustdoc/lib.rs | 20 ++-- src/librustdoc/passes.rs | 28 ++--- src/librustdoc/plugins.rs | 10 +- src/librustdoc/test.rs | 18 +-- src/librustdoc/visit_ast.rs | 8 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/expand.rs | 18 +-- src/libsyntax/ext/registrar.rs | 6 +- src/libsyntax/fold.rs | 4 +- src/libsyntax/print/pprust.rs | 8 +- src/libsyntax/visit.rs | 4 +- 69 files changed, 461 insertions(+), 461 deletions(-) diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index fb261eb7310..a7214b49bce 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -178,18 +178,18 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input) /// standard library and prelude. pub fn phase_2_configure_and_expand(sess: Session, loader: &mut CrateLoader, - mut crate: ast::Crate) + mut krate: ast::Crate) -> (ast::Crate, syntax::ast_map::Map) { let time_passes = sess.time_passes(); - sess.building_library.set(session::building_library(sess.opts, &crate)); - sess.crate_types.set(session::collect_crate_types(&sess, crate.attrs)); + sess.building_library.set(session::building_library(sess.opts, &krate)); + sess.crate_types.set(session::collect_crate_types(&sess, krate.attrs)); 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| - front::std_inject::maybe_inject_crates_ref(sess, crate)); + krate = time(time_passes, "crate injection", krate, |krate| + front::std_inject::maybe_inject_crates_ref(sess, krate)); // strip before expansion to allow macros to depend on // 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. - crate = time(time_passes, "configuration 1", crate, |crate| - front::config::strip_unconfigured_items(crate)); + krate = time(time_passes, "configuration 1", krate, |krate| + 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, loader, - crate) + krate) }); // dump the syntax-time crates sess.cstore.reset(); // strip again, in case expansion added anything with a #[cfg]. - crate = time(time_passes, "configuration 2", crate, |crate| - front::config::strip_unconfigured_items(crate)); + krate = time(time_passes, "configuration 2", krate, |krate| + front::config::strip_unconfigured_items(krate)); - crate = time(time_passes, "maybe building test harness", crate, |crate| - front::test::modify_for_testing(sess, crate)); + krate = time(time_passes, "maybe building test harness", krate, |krate| + front::test::modify_for_testing(sess, krate)); - crate = time(time_passes, "prelude injection", crate, |crate| - front::std_inject::maybe_inject_prelude(sess, crate)); + krate = time(time_passes, "prelude injection", krate, |krate| + front::std_inject::maybe_inject_prelude(sess, krate)); - time(time_passes, "assinging node ids and indexing ast", crate, |crate| - front::assign_node_ids_and_map::assign_node_ids_and_map(sess, crate)) + time(time_passes, "assinging node ids and indexing ast", krate, |krate| + front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate)) } pub struct CrateAnalysis { @@ -237,18 +237,18 @@ pub struct CrateAnalysis { /// miscellaneous analysis passes on the crate. Return various /// structures carrying the results of the analysis. pub fn phase_3_run_analysis_passes(sess: Session, - crate: &ast::Crate, + krate: &ast::Crate, ast_map: syntax::ast_map::Map) -> CrateAnalysis { let time_passes = sess.time_passes(); 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), token::get_ident_interner())); 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 { def_map: def_map, @@ -258,72 +258,72 @@ pub fn phase_3_run_analysis_passes(sess: Session, last_private_map: last_private_map } = 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", (), - |_| middle::resolve_lifetime::crate(sess, crate)); + |_| middle::resolve_lifetime::krate(sess, krate)); 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 = time(time_passes, "looking for macro registrar", (), |_| syntax::ext::registrar::find_macro_registrar( - sess.span_diagnostic, crate))); + sess.span_diagnostic, krate))); 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", (), |_| - 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, region_map, lang_items); // 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 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", (), |_| - 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)); let maps = (external_exports, last_private_map); let (exported_items, public_items) = time(time_passes, "privacy checking", maps, |(a, b)| middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, - a, b, crate)); + a, b, krate)); 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", (), |_| - 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, capture_map} = 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", (), |_| middle::check_match::check_crate(ty_cx, method_map, - moves_map, crate)); + moves_map, krate)); time(time_passes, "liveness checking", (), |_| middle::liveness::check_crate(ty_cx, method_map, - capture_map, crate)); + capture_map, krate)); let root_map = time(time_passes, "borrow checking", (), |_| middle::borrowck::check_crate(ty_cx, method_map, moves_map, moved_variables_set, - capture_map, crate)); + capture_map, krate)); time(time_passes, "kind checking", (), |_| - kind::check_crate(ty_cx, method_map, crate)); + kind::check_crate(ty_cx, method_map, krate)); let reachable_map = time(time_passes, "reachability checking", (), |_| @@ -336,12 +336,12 @@ pub fn phase_3_run_analysis_passes(sess: Session, method_map, &exported_items, reachable_map.get(), - crate) + krate) }); } 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 { exp_map2: exp_map2, @@ -370,11 +370,11 @@ pub struct CrateTranslation { /// Run the translation phase to LLVM, after which the AST and analysis can /// be discarded. pub fn phase_4_translate_to_llvm(sess: Session, - crate: ast::Crate, + krate: ast::Crate, analysis: &CrateAnalysis, outputs: &OutputFilenames) -> CrateTranslation { - time(sess.time_passes(), "translation", crate, |crate| - trans::base::trans_crate(sess, crate, analysis, outputs)) + time(sess.time_passes(), "translation", krate, |krate| + trans::base::trans_crate(sess, krate, analysis, outputs)) } /// 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, input: &Input, outputs: &OutputFilenames, - crate: &ast::Crate) -> io::IoResult<()> { - let lm = link::build_link_meta(crate.attrs, outputs, + krate: &ast::Crate) -> io::IoResult<()> { + let lm = link::build_link_meta(krate.attrs, outputs, &mut ::util::sha2::Sha256::new()); 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 let (outputs, trans) = { 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() { - front::show_span::run(sess, &crate); + front::show_span::run(sess, &krate); return; } if stop_after_phase_1(sess) { return; } 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, expanded_crate.attrs, sess); @@ -609,15 +609,15 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &Input, 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 => { let loader = &mut Loader::new(sess); - let (crate, ast_map) = phase_2_configure_and_expand(sess, loader, crate); - (crate, Some(ast_map), true) + let (krate, ast_map) = phase_2_configure_and_expand(sess, loader, krate); + (krate, Some(ast_map), true) } - _ => (crate, None, false) + _ => (krate, None, false) }; let annotation = match ppm { @@ -626,7 +626,7 @@ pub fn pretty_print_input(sess: Session, } PpmTyped => { 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 { analysis: analysis } as ~pprust::PpAnn: @@ -640,7 +640,7 @@ pub fn pretty_print_input(sess: Session, pprust::print_crate(sess.codemap, token::get_ident_interner(), sess.span_diagnostic, - &crate, + &krate, source_name(input), &mut rdr, ~stdout as ~io::Writer, diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index bea374fe107..336d9f55d37 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -456,7 +456,7 @@ pub fn expect(sess: Session, opt: Option, msg: || -> ~str) -> T { 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 } for output in options.crate_types.iter() { match *output { @@ -464,7 +464,7 @@ pub fn building_library(options: &Options, crate: &ast::Crate) -> bool { 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) => { s.equiv(&("lib")) || s.equiv(&("rlib")) || diff --git a/src/librustc/front/assign_node_ids_and_map.rs b/src/librustc/front/assign_node_ids_and_map.rs index d77ef1f3534..a6871e513a9 100644 --- a/src/librustc/front/assign_node_ids_and_map.rs +++ b/src/librustc/front/assign_node_ids_and_map.rs @@ -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) { - ast_map::map_crate(sess.diagnostic(), crate, NodeIdAssigner { sess: sess }) +pub fn assign_node_ids_and_map(sess: Session, krate: ast::Crate) -> (ast::Crate, ast_map::Map) { + ast_map::map_crate(sess.diagnostic(), krate, NodeIdAssigner { sess: sess }) } diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index 4fd72a4bbfc..f2130033eed 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -19,9 +19,9 @@ struct Context<'a> { // Support conditional compilation by transforming the AST, stripping out // any items that do not belong in the current configuration -pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate { - let config = crate.config.clone(); - strip_items(crate, |attrs| in_cfg(config, attrs)) +pub fn strip_unconfigured_items(krate: ast::Crate) -> ast::Crate { + let config = krate.config.clone(); + strip_items(krate, |attrs| in_cfg(config, attrs)) } 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) -> ast::Crate { let mut ctxt = Context { in_cfg: in_cfg, }; - ctxt.fold_crate(crate) + ctxt.fold_crate(krate) } fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem) diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs index f2e525932ad..e023003ff9f 100644 --- a/src/librustc/front/feature_gate.rs +++ b/src/librustc/front/feature_gate.rs @@ -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 { features: ~[], sess: sess, }; - for attr in crate.attrs.iter() { + for attr in krate.attrs.iter() { if !attr.name().equiv(&("feature")) { 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(); } diff --git a/src/librustc/front/show_span.rs b/src/librustc/front/show_span.rs index 2c076aac095..aa6fa321a31 100644 --- a/src/librustc/front/show_span.rs +++ b/src/librustc/front/show_span.rs @@ -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 }; - visit::walk_crate(&mut v, crate, ()); + visit::walk_crate(&mut v, krate, ()); } diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs index 4eb36b0f3fb..8171e78151e 100644 --- a/src/librustc/front/std_inject.rs +++ b/src/librustc/front/std_inject.rs @@ -25,29 +25,29 @@ use syntax::util::small_vector::SmallVector; 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 { - if use_std(&crate) { - inject_crates_ref(sess, crate) + if use_std(&krate) { + inject_crates_ref(sess, krate) } else { - crate + krate } } -pub fn maybe_inject_prelude(sess: Session, crate: ast::Crate) -> ast::Crate { - if use_std(&crate) { - inject_prelude(sess, crate) +pub fn maybe_inject_prelude(sess: Session, krate: ast::Crate) -> ast::Crate { + if use_std(&krate) { + inject_prelude(sess, krate) } else { - crate + krate } } -fn use_std(crate: &ast::Crate) -> bool { - !attr::contains_name(crate.attrs, "no_std") +fn use_std(krate: &ast::Crate) -> bool { + !attr::contains_name(krate.attrs, "no_std") } -fn use_uv(crate: &ast::Crate) -> bool { - !attr::contains_name(crate.attrs, "no_uv") +fn use_uv(krate: &ast::Crate) -> bool { + !attr::contains_name(krate.attrs, "no_uv") } fn no_prelude(attrs: &[ast::Attribute]) -> bool { @@ -58,12 +58,12 @@ struct StandardLibraryInjector { 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") { Some("1") => None, _ => { Some((token::intern_and_get_ident(format!("{}\\#{}", - crate, + krate, VERSION)), ast::CookedStr)) } @@ -71,7 +71,7 @@ pub fn with_version(crate: &str) -> Option<(InternedString, ast::StrStyle)> { } 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 { node: ast::ViewItemExternMod(self.sess.ident_of("std"), with_version("std"), @@ -88,7 +88,7 @@ impl fold::Folder for StandardLibraryInjector { 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 { node: ast::ViewItemExternMod(self.sess.ident_of("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 { view_items: vis, - ..crate.module.clone() + ..krate.module.clone() }; ast::Crate { 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 { sess: sess, }; - fold.fold_crate(crate) + fold.fold_crate(krate) } struct PreludeInjector { @@ -133,16 +133,16 @@ struct PreludeInjector { impl fold::Folder for PreludeInjector { - fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate { - if !no_prelude(crate.attrs) { + fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate { + if !no_prelude(krate.attrs) { // only add `use std::prelude::*;` if there wasn't a // `#[no_implicit_prelude];` at the crate level. ast::Crate { - module: self.fold_mod(&crate.module), - ..crate + module: self.fold_mod(&krate.module), + ..krate } } 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 { sess: sess, }; - fold.fold_crate(crate) + fold.fold_crate(krate) } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 2704e828ea4..c28fec12323 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -53,16 +53,16 @@ struct TestCtxt<'a> { // Traverse the crate, collecting all the test functions, eliding any // existing main functions, and synthesizing a main test harness 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' // configuration, either with the '--test' or '--cfg test' // command line options. - let should_test = attr::contains_name(crate.config, "test"); + let should_test = attr::contains_name(krate.config, "test"); if should_test { - generate_test_harness(sess, crate) + generate_test_harness(sess, krate) } 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 { let loader = &mut Loader::new(sess); 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), path: RefCell::new(~[]), testfns: RefCell::new(~[]), - is_extra: is_extra(&crate), - config: crate.config.clone(), + is_extra: is_extra(&krate), + config: krate.config.clone(), }; cx.ext_cx.bt_push(ExpnInfo { @@ -180,15 +180,15 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate) let mut fold = TestHarnessGenerator { cx: cx }; - let res = fold.fold_crate(crate); + let res = fold.fold_crate(krate); fold.cx.ext_cx.bt_pop(); 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 // #[test] functions - config::strip_items(crate, |attrs| { + config::strip_items(krate, |attrs| { !attr::contains_name(attrs, "test") && !attr::contains_name(attrs, "bench") }) @@ -390,8 +390,8 @@ fn mk_tests(cx: &TestCtxt) -> @ast::Item { )).unwrap() } -fn is_extra(crate: &ast::Crate) -> bool { - match attr::find_crateid(crate.attrs) { +fn is_extra(krate: &ast::Crate) -> bool { + match attr::find_crateid(krate.attrs) { Some(ref s) if "extra" == s.name => true, _ => false } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 9c2c5a57458..e62ae091daf 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -35,7 +35,7 @@ use syntax::visit; // Traverses an AST, reading all the information about use'd crates and extern // libraries necessary for later resolving, typechecking, linking, etc. pub fn read_crates(sess: Session, - crate: &ast::Crate, + krate: &ast::Crate, os: loader::Os, intr: @IdentInterner) { let mut e = Env { @@ -45,12 +45,12 @@ pub fn read_crates(sess: Session, next_crate_num: 1, intr: intr }; - visit_crate(&e, crate); + visit_crate(&e, krate); { let mut v = ReadCrateVisitor { e: &mut e }; - visit::walk_crate(&mut v, crate, ()); + visit::walk_crate(&mut v, krate, ()); } let crate_cache = e.crate_cache.borrow(); dump_crates(*crate_cache.get()); @@ -424,14 +424,14 @@ impl Loader { } impl CrateLoader for Loader { - fn load_crate(&mut self, crate: &ast::ViewItem) -> MacroCrate { - let info = extract_crate_info(crate).unwrap(); + fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate { + let info = extract_crate_info(krate).unwrap(); let cnum = resolve_crate(&mut self.env, info.ident.clone(), info.name.clone(), info.version.clone(), ~"", - crate.span); + krate.span); let library = self.env.sess.cstore.get_used_crate_source(cnum).unwrap(); MacroCrate { lib: library.dylib, diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 8a6ba824dcb..43694415d8d 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -32,13 +32,13 @@ pub struct StaticMethodInfo { } 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); } pub fn get_type_param_count(cstore: @cstore::CStore, def: ast::DefId) -> 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); } @@ -57,7 +57,7 @@ pub fn each_child_of_item(cstore: @cstore::CStore, callback: |decoder::DefLike, ast::Ident, 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| { 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 { 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); // 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) -> found_ast { 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, 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) -> ~[@ty::VariantInfo] { 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) } /// Returns information about the given implementation. pub fn get_impl(tcx: ty::ctxt, impl_def_id: ast::DefId) -> 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) } 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) } @@ -136,19 +136,19 @@ pub fn get_method_name_and_explicit_self(cstore: @cstore::CStore, def: ast::DefId) -> (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) } pub fn get_trait_method_def_ids(cstore: @cstore::CStore, 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) } pub fn get_item_variances(cstore: @cstore::CStore, 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) } @@ -156,40 +156,40 @@ pub fn get_provided_trait_methods(tcx: ty::ctxt, def: ast::DefId) -> ~[@ty::Method] { 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) } pub fn get_supertraits(tcx: ty::ctxt, def: ast::DefId) -> ~[@ty::TraitRef] { 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) } pub fn get_type_name_if_impl(cstore: @cstore::CStore, def: ast::DefId) -> Option { - 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) } pub fn get_static_methods_if_impl(cstore: @cstore::CStore, def: ast::DefId) -> 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) } pub fn get_item_attrs(cstore: @cstore::CStore, def_id: ast::DefId, 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) } pub fn get_struct_fields(cstore: @cstore::CStore, def: ast::DefId) -> ~[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) } @@ -197,20 +197,20 @@ pub fn get_type(tcx: ty::ctxt, def: ast::DefId) -> ty::ty_param_bounds_and_ty { 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) } pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef { 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) } pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId, def: ast::DefId) -> ty::ty_param_bounds_and_ty { 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 class_doc = expect(tcx.diag, 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, def: ast::DefId) -> Option<@ty::TraitRef> { 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) } @@ -241,7 +241,7 @@ pub fn get_impl_trait(tcx: ty::ctxt, pub fn get_impl_vtables(tcx: ty::ctxt, def: ast::DefId) -> typeck::impl_res { 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) } @@ -249,14 +249,14 @@ pub fn get_impl_method(cstore: @cstore::CStore, def: ast::DefId, mname: ast::Ident) -> Option { - 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) } pub fn get_item_visibility(cstore: @cstore::CStore, def_id: ast::DefId) -> 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) } @@ -277,14 +277,14 @@ pub fn each_impl(cstore: @cstore::CStore, pub fn each_implementation_for_type(cstore: @cstore::CStore, def_id: 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) } pub fn each_implementation_for_trait(cstore: @cstore::CStore, def_id: 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) } @@ -295,7 +295,7 @@ pub fn get_trait_of_method(cstore: @cstore::CStore, def_id: ast::DefId, tcx: ty::ctxt) -> Option { - 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) } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 029682d9315..cfc2bb502dc 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -191,7 +191,7 @@ fn item_parent_item(d: ebml::Doc) -> Option { fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum, d: ebml::Doc) -> ast::DefId { 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 { @@ -290,7 +290,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] { let v = tag_items_data_item_variant; reader::tagged_docs(item, v, |p| { 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 }); 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) -> ast::Def { 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. 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 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); 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 // 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) } 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) }; @@ -617,10 +617,10 @@ fn each_child_of_item_or_crate(intr: @IdentInterner, let name = name_doc.as_str_slice(); // 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) } 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) }; @@ -730,7 +730,7 @@ pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId, let mut disr_val = 0; for did in variant_ids.iter() { 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); let name = item_name(intr, item); 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); ty::Impl { did: ast::DefId { - crate: cdata.cnum, + krate: cdata.cnum, node: impl_id, }, 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 // crate to the correct local crate number. pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { - if did.crate == ast::LOCAL_CRATE { - return ast::DefId { crate: cdata.cnum, node: did.node }; + if did.krate == ast::LOCAL_CRATE { + return ast::DefId { krate: cdata.cnum, node: did.node }; } let cnum_map = cdata.cnum_map.borrow(); - match cnum_map.get().find(&did.crate) { + match cnum_map.get().find(&did.krate) { Some(&n) => { ast::DefId { - crate: n, + krate: n, node: did.node, } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index ea4d6d3b252..b5fef36607f 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -167,7 +167,7 @@ fn encode_family(ebml_w: &mut writer::Encoder, c: char) { } 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, @@ -344,7 +344,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, let mut disr_val = 0; let mut i = 0; 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() { let def_id = local_def(variant.node.id); { @@ -568,7 +568,7 @@ fn encode_reexports(ecx: &EncodeContext, debug!("(encoding info for module) reexport '{}' ({}/{}) for \ {}", exp.name, - exp.def_id.crate, + exp.def_id.krate, exp.def_id.node, id); 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. let r = ty::trait_method_def_ids(tcx, def_id); 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); @@ -1409,7 +1409,7 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> { fn encode_info_for_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, - crate: &Crate) + krate: &Crate) -> ~[entry] { let index = @RefCell::new(~[]); ebml_w.start_tag(tag_items_data); @@ -1422,7 +1422,7 @@ fn encode_info_for_items(ecx: &EncodeContext, } encode_info_for_mod(ecx, ebml_w, - &crate.module, + &krate.module, CRATE_NODE_ID, [], 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, }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } 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 // provide it we will throw it in anyway with a default value. fn synthesize_crate_attrs(ecx: &EncodeContext, - crate: &Crate) -> ~[Attribute] { + krate: &Crate) -> ~[Attribute] { fn synthesize_crateid_attr(ecx: &EncodeContext) -> Attribute { assert!(!ecx.link_meta.crateid.name.is_empty()); @@ -1571,7 +1571,7 @@ fn synthesize_crate_attrs(ecx: &EncodeContext, } let mut attrs = ~[]; - for attr in crate.attrs.iter() { + for attr in krate.attrs.iter() { if !attr.name().equiv(&("crate_id")) { 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 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_id); @@ -1714,7 +1714,7 @@ impl<'a, 'b> Visitor<()> for MacroDefVisitor<'a, 'b> { } fn encode_macro_defs(ecx: &EncodeContext, - crate: &Crate, + krate: &Crate, ebml_w: &mut writer::Encoder) { ebml_w.start_tag(tag_exported_macros); { @@ -1722,7 +1722,7 @@ fn encode_macro_defs(ecx: &EncodeContext, ecx: ecx, ebml_w: ebml_w, }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } 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 // or if the trait is not defined in this crate. 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); encode_def_id(self.ebml_w, local_def(item.id)); 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. fn encode_impls(ecx: &EncodeContext, - crate: &Crate, + krate: &Crate, ebml_w: &mut writer::Encoder) { ebml_w.start_tag(tag_impls); @@ -1776,18 +1776,18 @@ fn encode_impls(ecx: &EncodeContext, ecx: ecx, ebml_w: ebml_w, }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } ebml_w.end_tag(); } fn encode_misc_info(ecx: &EncodeContext, - crate: &Crate, + krate: &Crate, ebml_w: &mut writer::Encoder) { ebml_w.start_tag(tag_misc_info); 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.wr_str(def_to_str(local_def(item.id))); ebml_w.end_tag(); @@ -1838,13 +1838,13 @@ pub static metadata_encoding_version : &'static [u8] = 0x74, //'t' as u8, 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(); - encode_metadata_inner(&mut wr, parms, crate); + encode_metadata_inner(&mut wr, parms, krate); 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 { inline_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); 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); 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 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); // Encode the def IDs of impls, for coherence checking. 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); // Encode miscellaneous info. 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); // Encode and index the items. ebml_w.start_tag(tag_items); 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); i = ebml_w.writer.tell().unwrap(); diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index c1f2a459666..5c3fb8bebb0 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -57,7 +57,7 @@ type conv_did<'a> = pub struct PState<'a> { data: &'a [u8], - crate: ast::CrateNum, + krate: ast::CrateNum, pos: uint, 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> { PState { data: data, - crate: crate_num, + krate: crate_num, pos: pos, tcx: tcx } @@ -377,7 +377,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { assert_eq!(next(st), ':'); let len = parse_hex(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, 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 {:?}", 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, diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index d59ec370e07..6bbac6cc4ca 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -236,8 +236,8 @@ impl ExtendedDecodeContext { * refer to the current crate and to the new, inlined node-id. */ - assert_eq!(did.crate, ast::LOCAL_CRATE); - ast::DefId { crate: ast::LOCAL_CRATE, node: self.tr_id(did.node) } + assert_eq!(did.krate, ast::LOCAL_CRATE); + ast::DefId { krate: ast::LOCAL_CRATE, node: self.tr_id(did.node) } } pub fn tr_span(&self, _span: Span) -> Span { 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 r = tcache.get().find(&lid); @@ -1350,7 +1350,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, } c::tag_table_tcache => { 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(); tcache.get().insert(lid, tpbt); } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index acc8ece85f8..99b0fa1b1f5 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -73,7 +73,7 @@ pub fn check_crate(tcx: ty::ctxt, moves_map: moves::MovesMap, moved_variables_set: moves::MovedVariablesSet, capture_map: moves::CaptureMap, - crate: &ast::Crate) + krate: &ast::Crate) -> root_map { let mut bccx = BorrowckCtxt { tcx: tcx, @@ -91,7 +91,7 @@ pub fn check_crate(tcx: ty::ctxt, }; let bccx = &mut bccx; - visit::walk_crate(bccx, crate, ()); + visit::walk_crate(bccx, krate, ()); if tcx.sess.borrowck_stats() { println!("--- borrowck stats ---"); diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index d52ae81328f..385224c2073 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -42,7 +42,7 @@ impl Visitor for CheckCrateVisitor { } pub fn check_crate(sess: Session, - crate: &Crate, + krate: &Crate, ast_map: ast_map::Map, def_map: resolve::DefMap, method_map: typeck::method_map, @@ -54,7 +54,7 @@ pub fn check_crate(sess: Session, method_map: method_map, tcx: tcx, }; - visit::walk_crate(&mut v, crate, false); + visit::walk_crate(&mut v, krate, false); sess.abort_if_errors(); } diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index c1be9ea69ea..2c3d4a3e22f 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -24,8 +24,8 @@ struct CheckLoopVisitor { tcx: ty::ctxt, } -pub fn check_crate(tcx: ty::ctxt, crate: &ast::Crate) { - visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx }, crate, Normal) +pub fn check_crate(tcx: ty::ctxt, krate: &ast::Crate) { + visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx }, krate, Normal) } impl Visitor for CheckLoopVisitor { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index ab9eff3a372..a1e1b1b2549 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -52,13 +52,13 @@ impl Visitor<()> for CheckMatchVisitor { pub fn check_crate(tcx: ty::ctxt, method_map: method_map, moves_map: moves::MovesMap, - crate: &Crate) { + krate: &Crate) { let cx = @MatchCheckCtxt {tcx: tcx, method_map: method_map, moves_map: moves_map}; let mut v = CheckMatchVisitor { cx: cx }; - visit::walk_crate(&mut v, crate, ()); + visit::walk_crate(&mut v, krate, ()); tcx.sess.abort_if_errors(); } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 75874339f3a..52ea5f0a89f 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -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) { let mut v = ConstEvalVisitor { tcx: tcx, ccache: HashMap::new(), }; - visit::walk_crate(&mut v, crate, ()); + visit::walk_crate(&mut v, krate, ()); tcx.sess.abort_if_errors(); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 08ab8edf750..b11f385bdfd 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -254,7 +254,7 @@ impl Visitor<()> for LifeSeeder { fn create_and_seed_worklist(tcx: ty::ctxt, exported_items: &privacy::ExportedItems, reachable_symbols: &HashSet, - crate: &ast::Crate) -> ~[ast::NodeId] { + krate: &ast::Crate) -> ~[ast::NodeId] { let mut worklist = ~[]; // 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 { worklist: worklist }; - visit::walk_crate(&mut life_seeder, crate, ()); + visit::walk_crate(&mut life_seeder, krate, ()); return life_seeder.worklist; } @@ -288,10 +288,10 @@ fn find_live(tcx: ty::ctxt, method_map: typeck::method_map, exported_items: &privacy::ExportedItems, reachable_symbols: &HashSet, - crate: &ast::Crate) + krate: &ast::Crate) -> ~HashSet { 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); symbol_visitor.mark_live_symbols(); symbol_visitor.live_symbols @@ -412,9 +412,9 @@ pub fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map, exported_items: &privacy::ExportedItems, reachable_symbols: &HashSet, - crate: &ast::Crate) { + krate: &ast::Crate) { 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 }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 36dd46388c6..1445d5734ad 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -175,12 +175,12 @@ impl Visitor<()> for EffectCheckVisitor { pub fn check_crate(tcx: ty::ctxt, method_map: method_map, - crate: &ast::Crate) { + krate: &ast::Crate) { let mut visitor = EffectCheckVisitor { tcx: tcx, method_map: method_map, unsafe_context: SafeContext, }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 3938a786a39..a8f746429ba 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -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() { // No need to find a main function return; } // 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)); return } @@ -65,7 +65,7 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::Map) non_main_fns: ~[], }; - visit::walk_crate(&mut ctxt, crate, ()); + visit::walk_crate(&mut ctxt, krate, ()); configure_main(&mut ctxt); } diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 635fbf7eea8..4dea61ab5de 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -124,13 +124,13 @@ impl Visitor<()> for AnnotateFreevarsVisitor { // efficient as it fully recomputes the free variables at every // node of interest rather than building up the free variables in // 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 { let mut visitor = AnnotateFreevarsVisitor { def_map: def_map, freevars: HashMap::new(), }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); let AnnotateFreevarsVisitor { freevars, diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 0d6dc6572c3..3700833bfb5 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -77,12 +77,12 @@ impl Visitor<()> for Context { pub fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map, - crate: &Crate) { + krate: &Crate) { let mut ctx = Context { tcx: tcx, method_map: method_map, }; - visit::walk_crate(&mut ctx, crate, ()); + visit::walk_crate(&mut ctx, krate, ()); tcx.sess.abort_if_errors(); } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 2b100ffa4c9..290e901d1a3 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -161,24 +161,24 @@ impl LanguageItemCollector { 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 }; - visit::walk_crate(&mut v, crate, ()); + visit::walk_crate(&mut v, krate, ()); } pub fn collect_external_language_items(&mut self) { let crate_store = self.session.cstore; crate_store.iter_crate_data(|crate_number, _crate_metadata| { 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); true }); }) } - pub fn collect(&mut self, crate: &ast::Crate) { - self.collect_local_language_items(crate); + pub fn collect(&mut self, krate: &ast::Crate) { + self.collect_local_language_items(krate); self.collect_external_language_items(); } } @@ -196,10 +196,10 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option { return None; } -pub fn collect_language_items(crate: &ast::Crate, +pub fn collect_language_items(krate: &ast::Crate, session: Session) -> @LanguageItems { let mut collector = LanguageItemCollector::new(session); - collector.collect(crate); + collector.collect(krate); let LanguageItemCollector { items, .. } = collector; session.abort_if_errors(); @items diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 0ebfa8c393c..c2bdef021fe 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -1341,7 +1341,7 @@ fn check_missing_doc_item(cx: &Context, it: &ast::Item) { fn check_missing_doc_method(cx: &Context, m: &ast::Method) { let did = ast::DefId { - crate: ast::LOCAL_CRATE, + krate: ast::LOCAL_CRATE, node: m.id }; @@ -1643,7 +1643,7 @@ impl<'a> IdVisitingOperation for Context<'a> { pub fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map, exported_items: &privacy::ExportedItems, - crate: &ast::Crate) { + krate: &ast::Crate) { let mut cx = Context { dict: @get_lint_dict(), cur: SmallIntMap::new(), @@ -1664,19 +1664,19 @@ pub fn check_crate(tcx: ty::ctxt, for &(lint, level) in tcx.sess.opts.lint_opts.iter() { 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_ids(|v| { 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 // 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 diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 546d6f27204..e06866e77dd 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -176,11 +176,11 @@ impl Visitor<@IrMaps> for LivenessVisitor { pub fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map, capture_map: moves::CaptureMap, - crate: &Crate) { + krate: &Crate) { let mut visitor = LivenessVisitor; 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(); } diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index d73d7f3d6f1..a0dc8634792 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -209,7 +209,7 @@ impl visit::Visitor<()> for VisitContext { pub fn compute_moves(tcx: ty::ctxt, method_map: method_map, - crate: &Crate) -> MoveMaps + krate: &Crate) -> MoveMaps { let mut visit_cx = VisitContext { tcx: tcx, @@ -221,7 +221,7 @@ pub fn compute_moves(tcx: ty::ctxt, } }; let visit_cx = &mut visit_cx; - visit::walk_crate(visit_cx, crate, ()); + visit::walk_crate(visit_cx, krate, ()); return visit_cx.move_maps; } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index bcf79063b1a..d855ad97029 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -1091,13 +1091,13 @@ pub fn check_crate(tcx: ty::ctxt, exp_map2: &resolve::ExportMap2, external_exports: resolve::ExternalExports, last_private_map: resolve::LastPrivateMap, - crate: &ast::Crate) -> (ExportedItems, PublicItems) { + krate: &ast::Crate) -> (ExportedItems, PublicItems) { // Figure out who everyone's parent is let mut visitor = ParentVisitor { parents: HashMap::new(), 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 let mut visitor = PrivacyVisitor { @@ -1110,7 +1110,7 @@ pub fn check_crate(tcx: ty::ctxt, external_exports: external_exports, 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 // reasonable. @@ -1118,7 +1118,7 @@ pub fn check_crate(tcx: ty::ctxt, in_fn: false, tcx: tcx, }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); tcx.sess.abort_if_errors(); @@ -1135,7 +1135,7 @@ pub fn check_crate(tcx: ty::ctxt, }; loop { let before = visitor.exported_items.len(); - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); if before == visitor.exported_items.len() { break } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 071371c6b61..cd295eb016d 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -207,7 +207,7 @@ impl ReachableContext { // eligible for inlining and false otherwise. fn def_id_represents_local_inlined_item(tcx: ty::ctxt, def_id: ast::DefId) -> bool { - if def_id.crate != ast::LOCAL_CRATE { + if def_id.krate != ast::LOCAL_CRATE { return false } @@ -232,7 +232,7 @@ impl ReachableContext { } else { // Check the impl. If the generics on the self type of the // 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) { Some(ast_map::NodeItem(item, _)) => { match item.node { @@ -410,7 +410,7 @@ impl ReachableContext { fn mark_destructors_reachable(&self) { let destructor_for_type = self.tcx.destructor_for_type.borrow(); 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 .borrow_mut(); reachable_symbols.get().insert(destructor_def_id.node); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index fcda7cd79e4..9b1473cbd8e 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -908,7 +908,7 @@ impl<'a> Visitor 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 { scope_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 }; let cx = Context { parent: None, var_parent: None }; - visit::walk_crate(&mut visitor, crate, cx); + visit::walk_crate(&mut visitor, krate, cx); } return maps; } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 9623f6f0cbc..62496f6c7a6 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -769,7 +769,7 @@ fn Resolver(session: Session, let graph_root = @NameBindings(); graph_root.define_module(NoParentLink, - Some(DefId { crate: 0, node: 0 }), + Some(DefId { krate: 0, node: 0 }), NormalModuleKind, false, true, @@ -918,8 +918,8 @@ impl<'a> Visitor<()> for UnusedImportCheckVisitor<'a> { impl Resolver { /// The main name resolution procedure. - fn resolve(&mut self, crate: &ast::Crate) { - self.build_reduced_graph(crate); + fn resolve(&mut self, krate: &ast::Crate) { + self.build_reduced_graph(krate); self.session.abort_if_errors(); self.resolve_imports(); @@ -928,10 +928,10 @@ impl Resolver { self.record_exports(); self.session.abort_if_errors(); - self.resolve_crate(crate); + self.resolve_crate(krate); 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. - fn build_reduced_graph(&mut self, crate: &ast::Crate) { + fn build_reduced_graph(&mut self, krate: &ast::Crate) { let initial_parent = ModuleReducedGraphParent(self.graph_root.get_module()); 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. @@ -1138,7 +1138,7 @@ impl Resolver { self.add_child(ident, parent, ForbidDuplicateModules, sp); 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, Some(def_id), NormalModuleKind, @@ -1500,7 +1500,7 @@ impl Resolver { // 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) { 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); let parent_link = ModuleParentLink (self.get_module_from_parent(parent), name); @@ -1921,7 +1921,7 @@ impl Resolver { root.def_id .get() .unwrap() - .crate, + .krate, |def_like, ident, visibility| { self.build_reduced_graph_for_external_crate_def(root, def_like, @@ -3298,11 +3298,11 @@ impl Resolver { fn record_exports_for_module_subtree(&mut self, 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. 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. debug!("(recording exports for module subtree) recording \ exports for local module `{}`", @@ -3610,10 +3610,10 @@ impl Resolver { return None; } - fn resolve_crate(&mut self, crate: &ast::Crate) { + fn resolve_crate(&mut self, krate: &ast::Crate) { debug!("(resolving crate) starting"); - visit::walk_crate(self, crate, ()); + visit::walk_crate(self, krate, ()); } fn resolve_item(&mut self, item: &Item) { @@ -5401,7 +5401,7 @@ impl Resolver { trait_def_id: DefId, name: Ident) { debug!("(adding trait info) found trait {}:{} for method '{}'", - trait_def_id.crate, + trait_def_id.krate, trait_def_id.node, self.session.str_of(name)); found_traits.push(trait_def_id); @@ -5456,9 +5456,9 @@ impl Resolver { // 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 }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } fn check_for_item_unused_imports(&self, vi: &ViewItem) { @@ -5579,10 +5579,10 @@ pub struct CrateMap { /// Entry point to crate resolution. pub fn resolve_crate(session: Session, lang_items: @LanguageItems, - crate: &Crate) + krate: &Crate) -> CrateMap { - let mut resolver = Resolver(session, lang_items, crate.span); - resolver.resolve(crate); + let mut resolver = Resolver(session, lang_items, krate.span); + resolver.resolve(krate); let Resolver { def_map, export_map2, trait_map, last_private, external_exports, .. } = resolver; CrateMap { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index ab730c1b2e5..2256bbc4686 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -44,13 +44,13 @@ enum ScopeChain<'a> { RootScope } -pub fn crate(sess: session::Session, crate: &ast::Crate) +pub fn krate(sess: session::Session, krate: &ast::Crate) -> @RefCell { let mut ctxt = LifetimeContext { sess: sess, 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(); ctxt.named_region_map } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0aa62799495..438c0f7c698 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -522,13 +522,13 @@ pub fn get_res_dtor(ccx: @CrateContext, substs: &[ty::t]) -> ValueRef { 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) } else { did }; 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, self_ty: None, tps: /*bad*/ substs.to_owned() }; @@ -547,7 +547,7 @@ pub fn get_res_dtor(ccx: @CrateContext, None); val - } else if did.crate == ast::LOCAL_CRATE { + } else if did.krate == ast::LOCAL_CRATE { get_item_val(ccx, did.node) } else { let tcx = ccx.tcx; @@ -1895,7 +1895,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext, Ok(id) => id, 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) } else { 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; 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); 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 + flate::deflate_bytes(metadata); 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, - crate: ast::Crate, + krate: ast::Crate, analysis: &CrateAnalysis, output: &OutputFilenames) -> CrateTranslation { // 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 link_meta = link::build_link_meta(crate.attrs, output, + let link_meta = link::build_link_meta(krate.attrs, output, &mut symbol_hasher); // Append ".rs" to crate name as LLVM module identifier. @@ -2689,7 +2689,7 @@ pub fn trans_crate(sess: session::Session, analysis.reachable); { let _icx = push_ctxt("text"); - trans_mod(ccx, &crate.module); + trans_mod(ccx, &krate.module); } decl_gc_metadata(ccx, llmod_id); @@ -2719,7 +2719,7 @@ pub fn trans_crate(sess: session::Session, } // Translate the metadata. - let metadata = write_metadata(ccx, &crate); + let metadata = write_metadata(ccx, &krate); if ccx.sess.trans_stats() { println!("--- trans stats ---"); println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs.get()); diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 77fe847f5f2..53409358f53 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -346,7 +346,7 @@ pub fn trans_fn_ref_with_vtables( // Check whether this fn has an inlined copy and, if so, redirect // def_id to the local id of the inlined copy. let def_id = { - if def_id.crate != ast::LOCAL_CRATE { + if def_id.krate != ast::LOCAL_CRATE { inline::maybe_instantiate_inline(ccx, def_id) } else { def_id @@ -360,7 +360,7 @@ pub fn trans_fn_ref_with_vtables( let must_monomorphise; if type_params.len() > 0 || is_default { must_monomorphise = true; - } else if def_id.crate == ast::LOCAL_CRATE { + } else if def_id.krate == ast::LOCAL_CRATE { { let map_node = session::expect( ccx.sess, @@ -383,7 +383,7 @@ pub fn trans_fn_ref_with_vtables( // Create a monomorphic verison of generic functions if must_monomorphise { // 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) = monomorphize::monomorphic_fn(ccx, def_id, &substs, @@ -403,7 +403,7 @@ pub fn trans_fn_ref_with_vtables( // Find the actual function pointer. let mut val = { - if def_id.crate == ast::LOCAL_CRATE { + if def_id.krate == ast::LOCAL_CRATE { // Internal reference. get_item_val(ccx, def_id.node) } else { @@ -512,7 +512,7 @@ pub fn trans_lang_call<'a>( args: &[ValueRef], dest: Option) -> 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) } else { csearch::get_type(bcx.ccx().tcx, did).ty @@ -541,7 +541,7 @@ pub fn trans_lang_call_with_type_params<'a>( dest: expr::Dest) -> &'a Block<'a> { let fty; - if did.crate == ast::LOCAL_CRATE { + if did.krate == ast::LOCAL_CRATE { fty = ty::node_id_to_type(bcx.tcx(), did.node); } else { fty = csearch::get_type(bcx.tcx(), did).ty; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index db8f83b41af..790ad02a0dd 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -1398,7 +1398,7 @@ fn describe_enum_variant(cx: &CrateContext, // Could some consistency checks here: size, align, field count, discr type // 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) { Some(ast_map::NodeVariant(ref variant, _, _)) => variant.span, @@ -2261,7 +2261,7 @@ fn get_namespace_and_span_for_item(cx: &CrateContext, warning_span: Span) -> (DIScope, Span) { 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) { Some(ast_map::NodeItem(item, _)) => item.span, @@ -2782,8 +2782,8 @@ fn namespace_for_item(cx: &CrateContext, let namespace_path = { let mut item_path = ty::item_path(cx.tcx, def_id); - if (def_id.crate == ast::LOCAL_CRATE && item_path.len() < 1) || - (def_id.crate != ast::LOCAL_CRATE && item_path.len() < 2) { + if (def_id.krate == ast::LOCAL_CRATE && item_path.len() < 1) || + (def_id.krate != ast::LOCAL_CRATE && item_path.len() < 2) { cx.sess.bug(format!("debuginfo::namespace_for_item() - Item path too short: {}", 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 item_path.pop(); - if def_id.crate == ast::LOCAL_CRATE { + if def_id.krate == ast::LOCAL_CRATE { // prepend crate name if not already present let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name); item_path.insert(0, ast_map::PathMod(crate_namespace_ident)); diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 8f0101efb16..7ac91704cef 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -582,7 +582,7 @@ fn trans_def<'a>(bcx: &'a Block<'a>, fn get_did(ccx: @CrateContext, did: ast::DefId) -> ast::DefId { - if did.crate != ast::LOCAL_CRATE { + if did.krate != ast::LOCAL_CRATE { inline::maybe_instantiate_inline(ccx, did) } else { 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) -> ValueRef { // 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, // which may not be equal to the enum's type for // non-C-like enums. @@ -1710,7 +1710,7 @@ fn trans_log_level<'a>(bcx: &'a Block<'a>) let external_srcs = ccx.external_srcs.borrow(); srccrate = match external_srcs.get().find(&bcx.fcx.id) { 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(), }; diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 4a1ba7b22ac..4e8ca21dca5 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -184,7 +184,7 @@ pub fn trans_static_method_callee(bcx: &Block, let bound_index = ty::lookup_trait_def(bcx.tcx(), trait_id). 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) { ast_map::NodeTraitMethod(trait_method, _, _) => { diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 3afd4903230..f379b6227d9 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -321,10 +321,10 @@ pub fn llvm_type_name(cx: &CrateContext, let tstr = ppaux::parameterized(cx.tcx, ty::item_path_str(cx.tcx, did), &ty::NonerasedRegions(opt_vec::Empty), tps, did, false); - if did.crate == 0 { + if did.krate == 0 { format!("{}.{}", name, tstr) } else { - format!("{}.{}[\\#{}]", name, tstr, did.crate) + format!("{}.{}[\\#{}]", name, tstr, did.krate) } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 21124a9f741..a736fb61ab2 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2187,7 +2187,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { // If this assertion failures, it is likely because of a // failure in the cross-crate inlining code to translate a // 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 tp_def = ty_param_defs.get().get(&p.def_id.node); @@ -3842,8 +3842,8 @@ fn lookup_locally_or_in_crate_store( None => { } } - if def_id.crate == ast::LOCAL_CRATE { - fail!("no def'n found for {:?} in tcx.{}", def_id, descr); + if def_id.krate == ast::LOCAL_CRATE { + fail!("No def'n found for {:?} in tcx.{}", def_id, descr); } let v = load_external(); 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); { 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 { - if id.crate != ast::LOCAL_CRATE { + if id.krate != ast::LOCAL_CRATE { 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) } else { /* @@ -4274,7 +4274,7 @@ pub fn lookup_trait_def(cx: ctxt, did: ast::DefId) -> @ty::TraitDef { return trait_def; } None => { - assert!(did.crate != ast::LOCAL_CRATE); + assert!(did.krate != ast::LOCAL_CRATE); let trait_def = @csearch::get_trait_def(cx, did); trait_defs.get().insert(did, trait_def); return trait_def; @@ -4348,7 +4348,7 @@ pub fn lookup_field_type(tcx: ctxt, id: DefId, substs: &substs) -> 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) } 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 // Fails if the id is not bound to a struct. 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) { Some(ast_map::NodeItem(i,_)) => { @@ -4799,7 +4799,7 @@ fn record_trait_implementation(tcx: ctxt, /// if necessary. pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, type_id: ast::DefId) { - if type_id.crate == LOCAL_CRATE { + if type_id.krate == LOCAL_CRATE { return } { @@ -4867,7 +4867,7 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt, pub fn populate_implementations_for_trait_if_necessary( tcx: ctxt, trait_id: ast::DefId) { - if trait_id.crate == LOCAL_CRATE { + if trait_id.krate == LOCAL_CRATE { return } { @@ -4931,7 +4931,7 @@ pub fn trait_id_of_impl(tcx: ctxt, /// the trait that the method belongs to. Otherwise, return `None`. pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId) -> Option { - if def_id.crate != LOCAL_CRATE { + if def_id.krate != LOCAL_CRATE { return csearch::get_trait_of_method(tcx.cstore, def_id, tcx); } 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) { local_hash.clone() } else { - tcx.sess.cstore.get_crate_hash(did.crate) + tcx.sess.cstore.get_crate_hash(did.krate) }; hash.input(h.as_bytes()); iter(hash, &did.node); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index bdcb418b9f8..27fb78db201 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -1297,7 +1297,7 @@ impl<'a> LookupContext<'a> { } 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) { Some(ast_map::NodeMethod(m, _, _)) => m.span, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 9eec804dd2e..54d3ce66f43 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -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 }; - visit::walk_crate(&mut visit, crate, ()); + visit::walk_crate(&mut visit, krate, ()); } fn check_bare_fn(ccx: @CrateCtxt, @@ -2648,7 +2648,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, Err(msg) => { tcx.sess.span_err(expr.span, msg); ast::DefId { - crate: ast::CRATE_NODE_ID, + krate: ast::CRATE_NODE_ID, node: ast::DUMMY_NODE_ID, } } @@ -3624,7 +3624,7 @@ pub fn check_enum_variants(ccx: @CrateCtxt, 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 { ccx.tcx.sess.span_err(sp, format!("unsupported representation for {}variant enum", if vs.len() == 1 { "uni" } else { "zero-" })) diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index d3a0da4bbfd..a015f43b230 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -631,7 +631,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, // Identify the variable being closed over and its node-id. let def = freevar.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, closure_expr_id: expr.id }; diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 3a5f9900e3c..0d0aa72470f 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -107,7 +107,7 @@ fn type_is_defined_in_local_crate(original_type: t) -> bool { ty_enum(def_id, _) | ty_trait(def_id, _, _, _, _) | ty_struct(def_id, _) => { - if def_id.crate == ast::LOCAL_CRATE { + if def_id.krate == ast::LOCAL_CRATE { found_nominal = true; } } @@ -209,7 +209,7 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> { let trait_def_id = 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; session.span_err(item.span, "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 // containing the inherent methods and extension methods. It also // builds up the trait inheritance table. 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 self.check_implementation_coherence(); // 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 // coherence checks, because we ensure by construction that no errors @@ -453,12 +453,12 @@ impl CoherenceChecker { format!("conflicting implementations for trait `{}`", ty::item_path_str(self.crate_context.tcx, 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), "note conflicting implementation here"); } else { 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( "conflicting implementation in crate `" + cdata.name + "`"); } @@ -471,7 +471,7 @@ impl CoherenceChecker { fn iter_impls_of_trait(&self, trait_def_id: DefId, f: |@Impl|) { 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; } @@ -556,9 +556,9 @@ impl CoherenceChecker { } // Privileged scope checking - fn check_privileged_scopes(&self, crate: &Crate) { - let mut visitor = PrivilegedScopeVisitor { cc: self }; - visit::walk_crate(&mut visitor, crate, ()); + fn check_privileged_scopes(&self, krate: &Crate) { + let mut visitor = PrivilegedScopeVisitor{ cc: self }; + visit::walk_crate(&mut visitor, krate, ()); } 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(); match def_map.get().get_copy(&path_id) { DefTy(def_id) | DefStruct(def_id) => { - if def_id.crate != LOCAL_CRATE { + if def_id.krate != LOCAL_CRATE { return false; } @@ -640,7 +640,7 @@ impl CoherenceChecker { } 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) { Some(NodeItem(item, _)) => { return item.span; @@ -700,7 +700,7 @@ impl CoherenceChecker { let crate_store = self.crate_context.tcx.sess.cstore; crate_store.iter_crate_data(|crate_number, _crate_metadata| { 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) }) }) @@ -744,7 +744,7 @@ impl CoherenceChecker { } _ => { // 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) { 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) { - CoherenceChecker::new(crate_context).check(crate); +pub fn check_coherence(crate_context: @CrateCtxt, krate: &Crate) { + CoherenceChecker::new(crate_context).check(krate); } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 5e46daad7ee..abc9376053e 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -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, lang_item: ast::DefId) { 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 }; - visit::walk_crate(&mut visitor, crate, ()); + visit::walk_crate(&mut visitor, krate, ()); } pub trait ToTy { @@ -107,7 +107,7 @@ impl AstConv for CrateCtxt { fn tcx(&self) -> ty::ctxt { self.tcx } 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) } @@ -283,7 +283,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) { 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'] 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 { - if trait_id.crate != ast::LOCAL_CRATE { + if trait_id.krate != ast::LOCAL_CRATE { return ty::lookup_trait_def(ccx.tcx, trait_id) } diff --git a/src/librustc/middle/typeck/infer/test.rs b/src/librustc/middle/typeck/infer/test.rs index 517fe232b03..0a447a5f8e6 100644 --- a/src/librustc/middle/typeck/infer/test.rs +++ b/src/librustc/middle/typeck/infer/test.rs @@ -31,7 +31,7 @@ use syntax::parse::parse_crate_from_source_str; use syntax::{ast, attr, parse}; struct Env { - crate: @ast::Crate, + krate: @ast::Crate, tcx: ty::ctxt, infcx: infer::infer_ctxt, err_messages: @DVec<~str> @@ -59,7 +59,7 @@ fn setup_env(test_name: &str, source_string: &str) -> Env { let lang_items = LanguageItems::new(); 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(), cfg, parse_sess); @@ -68,7 +68,7 @@ fn setup_env(test_name: &str, source_string: &str) -> Env { let infcx = infer::new_infer_ctxt(tcx); - return Env {crate: crate, + return Env {krate: krate, tcx: tcx, infcx: infcx, err_messages: messages}; @@ -94,7 +94,7 @@ impl Env { } 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, None => { fail!("no item found: `%s`", names.connect("::")); diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index b6ad8cc6c43..aa98477f14b 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -441,7 +441,7 @@ fn check_for_entry_fn(ccx: &CrateCtxt) { pub fn check_crate(tcx: ty::ctxt, trait_map: resolve::TraitMap, - crate: &ast::Crate) + krate: &ast::Crate) -> (method_map, vtable_map) { let time_passes = tcx.sess.time_passes(); let ccx = @CrateCtxt { @@ -452,20 +452,20 @@ pub fn check_crate(tcx: ty::ctxt, }; 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 // have valid types and not error tcx.sess.abort_if_errors(); time(time_passes, "variance inference", (), |_| - variance::infer_variance(tcx, crate)); + variance::infer_variance(tcx, krate)); time(time_passes, "coherence checking", (), |_| - coherence::check_coherence(ccx, crate)); + coherence::check_coherence(ccx, krate)); time(time_passes, "type checking", (), |_| - check::check_item_types(ccx, crate)); + check::check_item_types(ccx, krate)); check_for_entry_fn(ccx); tcx.sess.abort_if_errors(); diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index bb74c3b9551..b20312c2241 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -76,7 +76,7 @@ impl RegionScope for BindingRscope { pub fn bound_type_regions(defs: &[ty::RegionParameterDef]) -> OptVec { - 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( |(i, def)| ty::ReEarlyBound(def.def_id.node, i, def.ident)).collect() } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index d0420aba45f..5848c9bdf02 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -207,10 +207,10 @@ use syntax::visit::Visitor; use util::ppaux::Repr; pub fn infer_variance(tcx: ty::ctxt, - crate: &ast::Crate) { + krate: &ast::Crate) { let mut arena = arena::Arena::new(); - let terms_cx = determine_parameters_to_be_inferred(tcx, &mut arena, crate); - let constraints_cx = add_constraints_from_crate(terms_cx, crate); + let terms_cx = determine_parameters_to_be_inferred(tcx, &mut arena, krate); + let constraints_cx = add_constraints_from_crate(terms_cx, krate); solve_constraints(constraints_cx); } @@ -278,7 +278,7 @@ struct InferredInfo<'a> { fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt, arena: &'a mut Arena, - crate: &ast::Crate) + krate: &ast::Crate) -> TermsContext<'a> { let mut terms_cx = TermsContext { tcx: tcx, @@ -293,7 +293,7 @@ fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt, region_params: opt_vec::Empty } }; - visit::walk_crate(&mut terms_cx, crate, ()); + visit::walk_crate(&mut terms_cx, krate, ()); terms_cx } @@ -423,7 +423,7 @@ struct Constraint<'a> { } fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>, - crate: &ast::Crate) + krate: &ast::Crate) -> ConstraintContext<'a> { let mut invariant_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, constraints: ~[], }; - visit::walk_crate(&mut constraint_cx, crate, ()); + visit::walk_crate(&mut constraint_cx, krate, ()); constraint_cx } @@ -496,7 +496,7 @@ impl<'a> Visitor<()> for ConstraintContext<'a> { ast::ItemStruct(..) => { let struct_fields = ty::lookup_struct_fields(tcx, did); 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); 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. */ - 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) { self.invariant @@ -560,7 +560,7 @@ impl<'a> ConstraintContext<'a> { self.covariant } else if self.contravariant_lang_items[kind as uint] == Some(item_def_id) { 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: // variance not yet inferred, so return a symbolic // variance. @@ -686,7 +686,7 @@ impl<'a> ConstraintContext<'a> { } 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) { Some(&index) => { self.add_constraint(index, variance); @@ -700,7 +700,7 @@ impl<'a> ConstraintContext<'a> { } 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); self.add_constraint(index, variance); } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index f536e231e15..cced7dc6a26 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -781,7 +781,7 @@ impl Repr for ast::DefId { // 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 // 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) { Some(ast_map::NodeItem(..)) | diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index ca7f502a2e8..a9819f8008f 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -604,7 +604,7 @@ pub enum Type { typarams: Option<~[TyParamBound]>, fqn: ~[~str], kind: TypeKind, - crate: ast::CrateNum, + krate: ast::CrateNum, }, // I have no idea how to usefully use this. TyParamBinder(ast::NodeId), @@ -1239,7 +1239,7 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>, } }).to_owned_vec(); ExternalPath{ path: path, typarams: tpbs, fqn: fqn, kind: kind, - crate: def_id.crate } + krate: def_id.krate } } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 108286fdb5c..585b18a8821 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -28,7 +28,7 @@ use clean; use clean::Clean; pub struct DocContext { - crate: ast::Crate, + krate: ast::Crate, tycx: Option, sess: driver::session::Session } @@ -73,15 +73,15 @@ fn get_ast_and_resolve(cpath: &Path, 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 (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 { 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); - return (DocContext { crate: crate, tycx: Some(ty_cx), sess: sess }, + debug!("crate: {:?}", krate); + return (DocContext { krate: krate, tycx: Some(ty_cx), sess: sess }, CrateAnalysis { exported_items: exported_items, public_items: public_items, @@ -93,11 +93,11 @@ pub fn run_core (libs: HashSet, cfgs: ~[~str], path: &Path) -> (clean::Cra let ctxt = @ctxt; local_data::set(super::ctxtkey, ctxt); - let crate = { + let krate = { let mut v = RustdocVisitor::new(ctxt, Some(&analysis)); - v.visit(&ctxt.crate); + v.visit(&ctxt.krate); v.clean() }; - (crate, analysis) + (krate, analysis) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 024d010f0b9..443c7df68f8 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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. fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool, fqn: &[~str], kind: clean::TypeKind, - crate: ast::CrateNum) -> fmt::Result { + krate: ast::CrateNum) -> fmt::Result { path(w, p, print_all, |cache, loc| { - match *cache.extern_locations.get(&crate) { + match *cache.extern_locations.get(&krate) { render::Remote(ref s) => Some(s.clone()), render::Local => Some("../".repeat(loc.len())), render::Unknown => None, @@ -310,9 +310,9 @@ impl fmt::Show for clean::Type { typarams(f.buf, 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, - crate)) + krate)) typarams(f.buf, tp) } clean::Self(..) => f.buf.write("Self".as_bytes()), diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index db7c882ab42..708d3590517 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -15,7 +15,7 @@ use std::io; pub struct Layout { logo: ~str, favicon: ~str, - crate: ~str, + krate: ~str, } pub struct Page<'a> { @@ -37,7 +37,7 @@ pub fn render( - + {favicon, select, none{} other{}} @@ -51,7 +51,7 @@ pub fn render(
{logo, select, none{} other{ - + }} {sidebar} @@ -77,9 +77,9 @@ pub fn render( - - - + + +
@@ -121,7 +121,7 @@ pub fn render( title = page.title, favicon = nonestr(layout.favicon), sidebar = *sidebar, - crate = layout.crate, + krate = layout.krate, ) } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 606cb445262..29773c60a87 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -195,7 +195,7 @@ local_data_key!(pub cache_key: Arc) local_data_key!(pub current_location_key: ~[~str]) /// 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 { dst: dst, current: ~[], @@ -204,13 +204,13 @@ pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> { layout: layout::Layout { logo: ~"", favicon: ~"", - crate: crate.name.clone(), + krate: krate.name.clone(), }, include_sources: true, }; 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) => { for attr in attrs.iter() { match *attr { @@ -243,11 +243,11 @@ pub fn run(mut crate: clean::Crate, dst: Path) -> io::IoResult<()> { extern_locations: HashMap::new(), privmod: false, }; - cache.stack.push(crate.name.clone()); - crate = cache.fold_crate(crate); + cache.stack.push(krate.name.clone()); + krate = cache.fold_crate(krate); // 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!(write(dst.join("jquery.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"); let dst = cx.dst.join("src"); if_ok!(mkdir(&dst)); - let dst = dst.join(crate.name.as_slice()); + let dst = dst.join(krate.name.as_slice()); if_ok!(mkdir(&dst)); let mut folder = SourceCollector { dst: dst, seen: HashSet::new(), 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)); } // 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 @@ -677,12 +677,12 @@ impl Context { /// /// This currently isn't parallelized, but it'd be pretty easy to add /// parallelization to this function. - fn crate(self, mut crate: clean::Crate, cache: Cache) -> io::IoResult<()> { - let mut item = match crate.module.take() { + fn krate(self, mut krate: clean::Crate, cache: Cache) -> io::IoResult<()> { + let mut item = match krate.module.take() { Some(i) => i, None => return Ok(()) }; - item.name = Some(crate.name); + item.name = Some(krate.name); // using a rwarc makes this parallelizable in the future local_data::set(cache_key, Arc::new(cache)); @@ -827,10 +827,10 @@ impl<'a> fmt::Show for Item<'a> { }; if_ok!(write!(fmt.buf, "\ + href='{root}src/{krate}/{path}.html\\#{href}'>\ [src]", root = self.cx.root_path, - crate = self.cx.layout.crate, + krate = self.cx.layout.krate, path = path.connect("/"), href = href)); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3dbf4726ae4..f30e6309f38 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -151,7 +151,7 @@ pub fn main_args(args: &[~str]) -> int { return 0; } - let (crate, res) = match acquire_input(input, &matches) { + let (krate, res) = match acquire_input(input, &matches) { Ok(pair) => pair, Err(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)); match matches.opt_str("w") { 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(()) => {} Err(e) => fail!("failed to generate documentation: {}", e), } } 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(()) => {} 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 cr = Path::new(cratefile); info!("starting to run rustc"); - let (crate, analysis) = std::task::try(proc() { + let (krate, analysis) = std::task::try(proc() { let cr = cr; core::run_core(libs.move_iter().collect(), cfgs, &cr) }).unwrap(); @@ -228,7 +228,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { // Process all of the crate attributes, extracting plugin metadata along // 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) => { for inner in nested.iter() { match *inner { @@ -277,7 +277,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { // Run everything! 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 @@ -302,7 +302,7 @@ fn json_input(input: &str) -> Result { Some(..) => return Err(~"malformed json"), None => return Err(~"expected a schema version"), } - let crate = match obj.pop(&~"crate") { + let krate = match obj.pop(&~"crate") { Some(json) => { let mut d = json::Decoder::new(json); Decodable::decode(&mut d) @@ -312,7 +312,7 @@ fn json_input(input: &str) -> Result { // FIXME: this should read from the "plugins" field, but currently // Json doesn't implement decodable... let plugin_output = ~[]; - Ok((crate, plugin_output)) + Ok((krate, plugin_output)) } Ok(..) => Err(~"malformed json input: expected an object at the top"), } @@ -320,7 +320,7 @@ fn json_input(input: &str) -> Result { /// Outputs the crate/plugin json as a giant json blob at the specified /// destination. -fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], +fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) -> io::IoResult<()> { // { // "schema": version, @@ -337,7 +337,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], let mut w = MemWriter::new(); { 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() }; diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 53b42baf402..8dd88c5b530 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -21,7 +21,7 @@ use fold; use fold::DocFolder; /// 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; impl fold::DocFolder for Stripper { fn fold_item(&mut self, i: Item) -> Option { @@ -45,19 +45,19 @@ pub fn strip_hidden(crate: clean::Crate) -> plugins::PluginResult { } } let mut stripper = Stripper; - let crate = stripper.fold_crate(crate); - (crate, None) + let krate = stripper.fold_crate(krate); + (krate, None) } /// Strip private items from the point of view of a crate or externally from a /// 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. let mut retained = HashSet::new(); let exported_items = local_data::get(super::analysiskey, |analysis| { analysis.unwrap().exported_items.clone() }); - let mut crate = crate; + let mut krate = krate; // strip all private items { @@ -65,15 +65,15 @@ pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult { retained: &mut retained, exported_items: &exported_items, }; - crate = stripper.fold_crate(crate); + krate = stripper.fold_crate(krate); } // strip all private implementations of traits { let mut stripper = ImplStripper(&retained); - crate = stripper.fold_crate(crate); + krate = stripper.fold_crate(krate); } - (crate, None) + (krate, None) } 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; impl fold::DocFolder for CommentCleaner { fn fold_item(&mut self, i: Item) -> Option { @@ -192,11 +192,11 @@ pub fn unindent_comments(crate: clean::Crate) -> plugins::PluginResult { } } let mut cleaner = CommentCleaner; - let crate = cleaner.fold_crate(crate); - (crate, None) + let krate = cleaner.fold_crate(krate); + (krate, None) } -pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult { +pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { struct Collapser; impl fold::DocFolder for Collapser { fn fold_item(&mut self, i: Item) -> Option { @@ -223,8 +223,8 @@ pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult { } } let mut collapser = Collapser; - let crate = collapser.fold_crate(crate); - (crate, None) + let krate = collapser.fold_crate(krate); + (krate, None) } pub fn unindent(s: &str) -> ~str { diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 4efc68a2655..2fcf5527a34 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -57,15 +57,15 @@ impl PluginManager { self.callbacks.push(plugin); } /// 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 crate = crate; + let mut krate = krate; for &callback in self.callbacks.iter() { - let (c, res) = callback(crate); - crate = c; + let (c, res) = callback(krate); + krate = c; out_json.push(res); } - (crate, out_json) + (krate, out_json) } } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 5da5f62e10c..9f8261b4449 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -58,31 +58,31 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int { span_diagnostic_handler); 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 (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 { - crate: crate, + krate: krate, tycx: None, sess: sess, }; local_data::set(super::ctxtkey, ctx); let mut v = RustdocVisitor::new(ctx, None); - v.visit(&ctx.crate); - let crate = v.clean(); - let (crate, _) = passes::unindent_comments(crate); - let (crate, _) = passes::collapse_docs(crate); + v.visit(&ctx.krate); + let krate = v.clean(); + let (krate, _) = passes::unindent_comments(krate); + let (krate, _) = passes::collapse_docs(krate); let mut collector = Collector { tests: ~[], names: ~[], cnt: 0, 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 mut args = args.iter().flat_map(|s| s.words()).map(|s| s.to_owned()); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 171ec13a6e6..69b740f969d 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -38,12 +38,12 @@ impl<'a> RustdocVisitor<'a> { } } - pub fn visit(&mut self, crate: &ast::Crate) { - self.attrs = crate.attrs.clone(); + pub fn visit(&mut self, krate: &ast::Crate) { + 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, - &crate.module, None); + &krate.module, None); } pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ca876054fa8..a5a49b78906 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -181,7 +181,7 @@ pub type NodeId = u32; #[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, IterBytes, ToStr)] pub struct DefId { - crate: CrateNum, + krate: CrateNum, node: NodeId, } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 817668f2232..9d3fe4f0c4d 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -406,7 +406,7 @@ pub fn map_crate(diag: @SpanHandler, c: Crate, diag: diag, fold_ops: fold_ops }; - let crate = cx.fold_crate(c); + let krate = cx.fold_crate(c); if log_enabled!(logging::DEBUG) { let map = cx.map.map.borrow(); @@ -421,7 +421,7 @@ pub fn map_crate(diag: @SpanHandler, c: Crate, 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 diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index afedb62105b..5f72a255d71 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -38,10 +38,10 @@ pub fn path_to_ident(path: &Path) -> Ident { } 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 { match s.node { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index d22a1d697fc..5e3cd2d5016 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -268,7 +268,7 @@ pub struct MacroCrate { } 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_registrar_symbol(&mut self, crate_num: ast::CrateNum) -> Option<~str>; } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d146cd4dae3..7e327dd520c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -413,10 +413,10 @@ pub fn expand_view_item(vi: &ast::ViewItem, noop_fold_view_item(vi, fld) } -fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) { - let MacroCrate { lib, cnum } = fld.cx.loader.load_crate(crate); +fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) { + 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, _, _) => { let string = token::get_ident(name.name); string.get().to_str() @@ -452,19 +452,19 @@ fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) { // this is fatal: there are almost certainly macros we need // inside this crate, so continue would spew "macro undefined" // errors - Err(err) => fld.cx.span_fatal(crate.span, err) + Err(err) => fld.cx.span_fatal(krate.span, err) }; unsafe { let registrar: MacroCrateRegistrationFun = match lib.symbol(registrar) { Ok(registrar) => registrar, // 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| { let extension = match extension { - NormalTT(ext, _) => NormalTT(ext, Some(crate.span)), - IdentTT(ext, _) => IdentTT(ext, Some(crate.span)), + NormalTT(ext, _) => NormalTT(ext, Some(krate.span)), + IdentTT(ext, _) => IdentTT(ext, Some(krate.span)), ItemDecorator(ext) => ItemDecorator(ext), }; fld.extsbox.insert(name, extension); @@ -1032,10 +1032,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 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 { diff --git a/src/libsyntax/ext/registrar.rs b/src/libsyntax/ext/registrar.rs index e831e8fbb10..f0bad1b40eb 100644 --- a/src/libsyntax/ext/registrar.rs +++ b/src/libsyntax/ext/registrar.rs @@ -35,16 +35,16 @@ impl Visitor<()> for MacroRegistrarContext { } pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler, - crate: &ast::Crate) -> Option { + krate: &ast::Crate) -> Option { let mut ctx = MacroRegistrarContext { registrars: ~[] }; - visit::walk_crate(&mut ctx, crate, ()); + visit::walk_crate(&mut ctx, krate, ()); match ctx.registrars.len() { 0 => None, 1 => { let (node_id, _) = ctx.registrars.pop().unwrap(); Some(ast::DefId { - crate: ast::LOCAL_CRATE, + krate: ast::LOCAL_CRATE, node: node_id }) }, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 52ff3798f1b..1b14bd72382 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -859,8 +859,8 @@ mod test { // this version doesn't care about getting comments or docstrings in. fn fake_print_crate(s: &mut pprust::State, - crate: &ast::Crate) -> io::IoResult<()> { - pprust::print_mod(s, &crate.module, crate.attrs) + krate: &ast::Crate) -> io::IoResult<()> { + pprust::print_mod(s, &krate.module, krate.attrs) } // change every identifier to "zz" diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7f7f57b13a9..24aa30cb36b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -116,7 +116,7 @@ pub static default_columns: uint = 78u; pub fn print_crate(cm: @CodeMap, intr: @IdentInterner, span_diagnostic: @diagnostic::SpanHandler, - crate: &ast::Crate, + krate: &ast::Crate, filename: ~str, input: &mut io::Reader, out: ~io::Writer, @@ -147,11 +147,11 @@ pub fn print_crate(cm: @CodeMap, boxes: RefCell::new(~[]), ann: ann }; - print_crate_(&mut s, crate) + print_crate_(&mut s, krate) } -pub fn print_crate_(s: &mut State, crate: &ast::Crate) -> io::IoResult<()> { - if_ok!(print_mod(s, &crate.module, crate.attrs)); +pub fn print_crate_(s: &mut State, krate: &ast::Crate) -> io::IoResult<()> { + if_ok!(print_mod(s, &krate.module, krate.attrs)); if_ok!(print_remaining_comments(s)); if_ok!(eof(&mut s.s)); Ok(()) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 0c6ecf73f6a..e1fe43b8e04 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -132,8 +132,8 @@ pub fn walk_inlined_item>(visitor: &mut V, } -pub fn walk_crate>(visitor: &mut V, crate: &Crate, env: E) { - visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env) +pub fn walk_crate>(visitor: &mut V, krate: &Crate, env: E) { + visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env) } pub fn walk_mod>(visitor: &mut V, module: &Mod, env: E) { From 9a6d92c1d706af14da336892e8d5148c3d3859ee Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Sun, 2 Feb 2014 23:52:06 +0100 Subject: [PATCH 2/3] Replace `extern mod` with `extern crate` This patch adds a new keyword `crate` which is intended to replace mod in the context of `extern mod` as part of the issue #9880. The patch doesn't replace all `extern mod` cases since it is necessary to first push a new snapshot 0. The implementation could've been less invasive than this. However I preferred to take this chance to split the `parse_item_foreign_mod` method and pull the `extern crate` part out of there, hence the new method `parse_item_foreign_crate`. --- src/libsyntax/parse/parser.rs | 174 +++++++++--------- src/libsyntax/parse/token.rs | 53 +++--- .../extern-expected-fn-or-brace.rs | 14 ++ src/test/compile-fail/extern-foreign-crate.rs | 14 ++ src/test/run-pass/extern-foreign-crate.rs | 14 ++ 5 files changed, 157 insertions(+), 112 deletions(-) create mode 100644 src/test/compile-fail/extern-expected-fn-or-brace.rs create mode 100644 src/test/compile-fail/extern-foreign-crate.rs create mode 100644 src/test/run-pass/extern-foreign-crate.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4bef7dc5bb5..15608a0f28e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 purity = self.parse_unsafety(); 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, lo: BytePos, opt_abis: Option, visibility: Visibility, - attrs: ~[Attribute], - items_allowed: bool) + attrs: ~[Attribute]) -> 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 { - 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)) - } + self.expect(&token::LBRACE); - (false, None, - special_idents::clownshoes_foreign_mod) - } - }; + let abis = opt_abis.unwrap_or(AbiSet::C()); - // extern mod foo { ... } or extern { ... } - if items_allowed && self.eat(&token::LBRACE) { - // `extern mod foo { ... }` is obsolete. - if named { - self.obsolete(self.last_span, ObsoleteNamedExternModule); - } + let (inner, next) = self.parse_inner_attrs_and_next(); + let m = self.parse_foreign_mod_items(abis, next); + self.expect(&token::RBRACE); - let abis = opt_abis.unwrap_or(AbiSet::C()); - - let (inner, next) = self.parse_inner_attrs_and_next(); - let m = self.parse_foreign_mod_items(abis, next); - self.expect(&token::RBRACE); - - let item = self.mk_item(lo, - 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) - }) + let item = self.mk_item(lo, + self.last_span.hi, + special_idents::clownshoes_foreign_mod, + ItemForeignMod(m), + visibility, + maybe_append(attrs, Some(inner))); + return IoviItem(item); } // parse type Foo = Bar; @@ -4504,10 +4494,6 @@ impl Parser { // Parses a string as an ABI spec on an extern type or module. Consumes // the `extern` keyword, if one is found. fn parse_opt_abis(&mut self) -> Option { - if !self.eat_keyword(keywords::Extern) { - return None - } - match self.token { token::LIT_STR(s) | token::LIT_STR_RAW(s, _) => { @@ -4585,7 +4571,20 @@ impl Parser { }); } // 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(); if self.eat_keyword(keywords::Fn) { @@ -4600,12 +4599,15 @@ impl Parser { visibility, maybe_append(attrs, extra_attrs)); return IoviItem(item); - } else { - // EXTERN MODULE ITEM (IoviViewItem) - return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs, - true); + } else if self.token == token::LBRACE { + return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs); } + + 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: if self.is_keyword(keywords::Static) { // STATIC ITEM diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 1e9eab1573b..423ddb82808 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -462,37 +462,38 @@ declare_special_idents_and_keywords! { (28, Loop, "loop"); (29, Match, "match"); (30, Mod, "mod"); - (31, Mut, "mut"); - (32, Once, "once"); - (33, Priv, "priv"); - (34, Pub, "pub"); - (35, Ref, "ref"); - (36, Return, "return"); + (31, Crate, "crate"); + (32, Mut, "mut"); + (33, Once, "once"); + (34, Priv, "priv"); + (35, Pub, "pub"); + (36, Ref, "ref"); + (37, Return, "return"); // Static and Self are also special idents (prefill de-dupes) (super::STATIC_KEYWORD_NAME, Static, "static"); (super::SELF_KEYWORD_NAME, Self, "self"); - (37, Struct, "struct"); - (38, Super, "super"); - (39, True, "true"); - (40, Trait, "trait"); - (41, Type, "type"); - (42, Unsafe, "unsafe"); - (43, Use, "use"); - (44, While, "while"); - (45, Continue, "continue"); - (46, Proc, "proc"); - (47, Box, "box"); + (38, Struct, "struct"); + (39, Super, "super"); + (40, True, "true"); + (41, Trait, "trait"); + (42, Type, "type"); + (43, Unsafe, "unsafe"); + (44, Use, "use"); + (45, While, "while"); + (46, Continue, "continue"); + (47, Proc, "proc"); + (48, Box, "box"); 'reserved: - (48, Alignof, "alignof"); - (49, Be, "be"); - (50, Offsetof, "offsetof"); - (51, Pure, "pure"); - (52, Sizeof, "sizeof"); - (53, Typeof, "typeof"); - (54, Unsized, "unsized"); - (55, Yield, "yield"); - (56, Do, "do"); + (49, Alignof, "alignof"); + (50, Be, "be"); + (51, Offsetof, "offsetof"); + (52, Pure, "pure"); + (53, Sizeof, "sizeof"); + (54, Typeof, "typeof"); + (55, Unsized, "unsized"); + (56, Yield, "yield"); + (57, Do, "do"); } } diff --git a/src/test/compile-fail/extern-expected-fn-or-brace.rs b/src/test/compile-fail/extern-expected-fn-or-brace.rs new file mode 100644 index 00000000000..638253f816a --- /dev/null +++ b/src/test/compile-fail/extern-expected-fn-or-brace.rs @@ -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 or the MIT license +// , 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` diff --git a/src/test/compile-fail/extern-foreign-crate.rs b/src/test/compile-fail/extern-foreign-crate.rs new file mode 100644 index 00000000000..ffa6ffb042f --- /dev/null +++ b/src/test/compile-fail/extern-foreign-crate.rs @@ -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 or the MIT license +// , 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 `{` diff --git a/src/test/run-pass/extern-foreign-crate.rs b/src/test/run-pass/extern-foreign-crate.rs new file mode 100644 index 00000000000..8949734b80e --- /dev/null +++ b/src/test/run-pass/extern-foreign-crate.rs @@ -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 or the MIT license +// , 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() {} From 5deb3c9ca06509ce261f69fd01426825e32d61c1 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Mon, 3 Feb 2014 22:49:14 +0100 Subject: [PATCH 3/3] Remove obsolete warnings for `extern mod` This patch gets rid of ObsoleteExternModAttributesInParens and ObsoleteNamedExternModule since the replacement of `extern mod` with `extern crate` avoids those cases and raises different errors. Both have been around for at least a version which makes this a good moment to get rid of them. --- src/libsyntax/parse/obsolete.rs | 12 ------------ src/test/compile-fail/obsolete-syntax.rs | 5 ----- 2 files changed, 17 deletions(-) diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 6f6f8d7d563..24227dea531 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -30,7 +30,6 @@ pub enum ObsoleteSyntax { ObsoleteSwap, ObsoleteUnsafeBlock, ObsoleteBareFnType, - ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl, ObsoleteUnsafeExternFn, ObsoleteTraitFuncVisibility, @@ -42,7 +41,6 @@ pub enum ObsoleteSyntax { ObsoleteBoxedClosure, ObsoleteClosureType, ObsoleteMultipleImport, - ObsoleteExternModAttributesInParens, ObsoleteManagedPattern, ObsoleteManagedString, ObsoleteManagedVec, @@ -86,11 +84,6 @@ impl ParserObsoleteMethods for Parser { "bare function type", "use `|A| -> B` or `extern fn(A) -> B` instead" ), - ObsoleteNamedExternModule => ( - "named external module", - "instead of `extern mod foo { ... }`, write `mod foo { \ - extern { ... } }`" - ), ObsoleteMultipleLocalDecl => ( "declaration of multiple locals at once", "instead of e.g. `let a = 1, b = 2`, write \ @@ -141,11 +134,6 @@ impl ParserObsoleteMethods for Parser { "multiple imports", "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 => ( "managed pointer pattern", "use a nested `match` expression instead of a managed box \ diff --git a/src/test/compile-fail/obsolete-syntax.rs b/src/test/compile-fail/obsolete-syntax.rs index 07fa5077d9b..9fe5e2031bb 100644 --- a/src/test/compile-fail/obsolete-syntax.rs +++ b/src/test/compile-fail/obsolete-syntax.rs @@ -8,11 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod obsolete_name { - //~^ ERROR obsolete syntax: named external module - fn bar(); -} - trait A { pub fn foo(); //~ ERROR: visibility not necessary pub fn bar(); //~ ERROR: visibility not necessary