From 0a8bb4c509e513a87a1bc0c04e0b7b8e13b82d2f Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 25 Nov 2015 00:00:26 +0200 Subject: [PATCH] split the metadata code into rustc_metadata tests & rustdoc still broken --- mk/crates.mk | 11 +- src/librustc/diagnostics.rs | 60 --- src/librustc/front/map/definitions.rs | 2 +- src/librustc/front/map/mod.rs | 4 +- src/librustc/lib.rs | 5 +- src/librustc/metadata/csearch.rs | 408 ------------------ src/librustc/metadata/inline.rs | 60 --- src/librustc/metadata/mod.rs | 23 - src/librustc/middle/const_eval.rs | 12 +- src/librustc/middle/cstore.rs | 277 ++++++++++++ src/librustc/middle/def_id.rs | 2 +- src/librustc/middle/dependency_format.rs | 4 +- src/librustc/middle/infer/error_reporting.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/region.rs | 2 +- src/librustc/middle/stability.rs | 3 +- src/librustc/middle/traits/coherence.rs | 2 +- src/librustc/middle/ty/context.rs | 2 +- src/librustc/middle/ty/mod.rs | 3 +- src/librustc/middle/weak_lang_items.rs | 2 +- src/librustc/session/config.rs | 2 +- .../{metadata => session}/filesearch.rs | 0 src/librustc/session/mod.rs | 4 +- src/librustc_driver/driver.rs | 8 +- src/librustc_driver/lib.rs | 9 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/lib.rs | 1 - .../middle => librustc_metadata}/astencode.rs | 28 +- .../metadata => librustc_metadata}/common.rs | 8 - .../metadata => librustc_metadata}/creader.rs | 45 +- .../util.rs => librustc_metadata/csearch.rs} | 153 +------ .../metadata => librustc_metadata}/cstore.rs | 51 +-- .../metadata => librustc_metadata}/decoder.rs | 38 +- src/librustc_metadata/diagnostics.rs | 77 ++++ .../metadata => librustc_metadata}/encoder.rs | 26 +- .../metadata => librustc_metadata}/index.rs | 0 src/librustc_metadata/lib.rs | 61 +++ .../metadata => librustc_metadata}/loader.rs | 24 +- .../macro_import.rs | 7 +- src/librustc_metadata/macros.rs | 46 ++ .../tydecode.rs | 0 .../tyencode.rs | 2 +- src/librustc_plugin/lib.rs | 1 + src/librustc_plugin/load.rs | 4 +- src/librustc_resolve/build_reduced_graph.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_trans/back/archive.rs | 2 +- src/librustc_trans/back/link.rs | 9 +- src/librustc_trans/back/linker.rs | 2 +- src/librustc_trans/lib.rs | 1 - src/librustc_trans/save/recorder.rs | 2 +- src/librustc_trans/trans/base.rs | 2 +- src/librustc_trans/trans/callee.rs | 2 +- src/librustc_trans/trans/consts.rs | 2 +- src/librustc_trans/trans/context.rs | 2 +- src/librustc_trans/trans/inline.rs | 2 +- src/librustc_trans/trans/mod.rs | 2 +- src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 10 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/coherence/overlap.rs | 3 +- src/librustc_typeck/lib.rs | 1 - 64 files changed, 629 insertions(+), 908 deletions(-) delete mode 100644 src/librustc/metadata/csearch.rs delete mode 100644 src/librustc/metadata/inline.rs delete mode 100644 src/librustc/metadata/mod.rs create mode 100644 src/librustc/middle/cstore.rs rename src/librustc/{metadata => session}/filesearch.rs (100%) rename src/{librustc/middle => librustc_metadata}/astencode.rs (99%) rename src/{librustc/metadata => librustc_metadata}/common.rs (98%) rename src/{librustc/metadata => librustc_metadata}/creader.rs (97%) rename src/{librustc/metadata/util.rs => librustc_metadata/csearch.rs} (69%) rename src/{librustc/metadata => librustc_metadata}/cstore.rs (90%) rename src/{librustc/metadata => librustc_metadata}/decoder.rs (98%) create mode 100644 src/librustc_metadata/diagnostics.rs rename src/{librustc/metadata => librustc_metadata}/encoder.rs (99%) rename src/{librustc/metadata => librustc_metadata}/index.rs (100%) create mode 100644 src/librustc_metadata/lib.rs rename src/{librustc/metadata => librustc_metadata}/loader.rs (98%) rename src/{librustc/metadata => librustc_metadata}/macro_import.rs (98%) create mode 100644 src/librustc_metadata/macros.rs rename src/{librustc/metadata => librustc_metadata}/tydecode.rs (100%) rename src/{librustc/metadata => librustc_metadata}/tyencode.rs (99%) diff --git a/mk/crates.mk b/mk/crates.mk index 89769b850e31f..8ce0a41d9786c 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -57,7 +57,7 @@ TARGET_CRATES := libc std flate arena term \ RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \ rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \ rustc_data_structures rustc_front rustc_platform_intrinsics \ - rustc_plugin + rustc_plugin rustc_metadata HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros TOOLS := compiletest rustdoc rustc rustbook error-index-generator @@ -88,22 +88,23 @@ DEPS_test := std getopts serialize rbml term native:rust_test_helpers DEPS_syntax := std term serialize log fmt_macros arena libc rustc_bitflags -DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\ +DEPS_rustc := syntax flate arena serialize getopts rustc_front\ log graphviz rustc_llvm rustc_back rustc_data_structures DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax DEPS_rustc_data_structures := std log serialize DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \ rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \ - rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin - + rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin \ + rustc_metadata DEPS_rustc_front := std syntax log serialize DEPS_rustc_lint := rustc log syntax DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags +DEPS_rustc_metadata := rustc rustc_front syntax rbml DEPS_rustc_mir := rustc rustc_front syntax DEPS_rustc_resolve := rustc rustc_front log syntax DEPS_rustc_platform_intrinsics := rustc rustc_llvm -DEPS_rustc_plugin := rustc syntax +DEPS_rustc_plugin := rustc rustc_metadata syntax DEPS_rustc_privacy := rustc rustc_front log syntax DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \ log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index a088567b4190d..b4e188c498d74 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1899,51 +1899,6 @@ contain references (with a maximum lifetime of `'a`). [1]: https://github.com/rust-lang/rfcs/pull/1156 "##, -E0454: r##" -A link name was given with an empty name. Erroneous code example: - -``` -#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name -``` - -The rust compiler cannot link to an external library if you don't give it its -name. Example: - -``` -#[link(name = "some_lib")] extern {} // ok! -``` -"##, - -E0458: r##" -An unknown "kind" was specified for a link attribute. Erroneous code example: - -``` -#[link(kind = "wonderful_unicorn")] extern {} -// error: unknown kind: `wonderful_unicorn` -``` - -Please specify a valid "kind" value, from one of the following: - * static - * dylib - * framework -"##, - -E0459: r##" -A link was used without a name parameter. Erroneous code example: - -``` -#[link(kind = "dylib")] extern {} -// error: #[link(...)] specified without `name = "foo"` -``` - -Please add the name parameter to allow the rust compiler to find the library -you want. Example: - -``` -#[link(kind = "dylib", name = "some_lib")] extern {} // ok! -``` -"##, - E0493: r##" A type with a destructor was assigned to an invalid type of variable. Erroneous code example: @@ -2144,20 +2099,6 @@ register_diagnostics! { E0400, // overloaded derefs are not allowed in constants E0452, // malformed lint attribute E0453, // overruled by outer forbid - E0455, // native frameworks are only available on OSX targets - E0456, // plugin `..` is not available for triple `..` - E0457, // plugin `..` only found in rlib format, but must be available... - E0460, // found possibly newer version of crate `..` - E0461, // couldn't find crate `..` with expected target triple .. - E0462, // found staticlib `..` instead of rlib or dylib - E0463, // can't find crate for `..` - E0464, // multiple matching crates for `..` - E0465, // multiple .. candidates for `..` found - E0466, // bad macro import - E0467, // bad macro reexport - E0468, // an `extern crate` loading macros must be at the crate root - E0469, // imported macro not found - E0470, // reexported macro not found E0471, // constant evaluation error: .. E0472, // asm! is unsupported on this target E0473, // dereference of reference outside its lifetime @@ -2181,5 +2122,4 @@ register_diagnostics! { E0491, // in type `..`, reference has a longer lifetime than the data it... E0492, // cannot borrow a constant which contains interior mutability E0495, // cannot infer an appropriate lifetime due to conflicting requirements - E0514, // metadata version mismatch } diff --git a/src/librustc/front/map/definitions.rs b/src/librustc/front/map/definitions.rs index c1eb5f1f11845..0f0d59e70b0b8 100644 --- a/src/librustc/front/map/definitions.rs +++ b/src/librustc/front/map/definitions.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def_id::{DefId, DefIndex}; use rustc_data_structures::fnv::FnvHashMap; use rustc_front::hir; diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 6ee6b07059751..8c3da2cddd561 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -14,8 +14,8 @@ use self::MapEntry::*; use self::collector::NodeCollector; pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData, DisambiguatedDefPathData}; -use metadata::inline::InlinedItem; -use metadata::inline::InlinedItem as II; +use middle::cstore::InlinedItem; +use middle::cstore::InlinedItem as II; use middle::def_id::DefId; use syntax::abi; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 62646f6bc565e..6da4f174e3e09 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -67,7 +67,6 @@ extern crate rustc_back; extern crate rustc_front; extern crate rustc_data_structures; extern crate serialize; -extern crate rbml; extern crate collections; #[macro_use] extern crate log; #[macro_use] extern crate syntax; @@ -101,7 +100,6 @@ pub mod front { pub mod middle { pub mod astconv_util; pub mod expr_use_visitor; // STAGE0: increase glitch immunity - pub mod astencode; pub mod cfg; pub mod check_const; pub mod check_static_recursion; @@ -110,6 +108,7 @@ pub mod middle { pub mod check_no_asm; pub mod check_rvalues; pub mod const_eval; + pub mod cstore; pub mod dataflow; pub mod dead; pub mod def; @@ -137,8 +136,6 @@ pub mod middle { pub mod weak_lang_items; } -pub mod metadata; - pub mod session; pub mod lint; diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs deleted file mode 100644 index 40159b24fe71d..0000000000000 --- a/src/librustc/metadata/csearch.rs +++ /dev/null @@ -1,408 +0,0 @@ -// Copyright 2012-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. - -// Searching for information from the cstore - -use front::map as ast_map; -use metadata::cstore; -use metadata::decoder; -use metadata::inline::InlinedItem; -use middle::def_id::{DefId, DefIndex}; -use middle::lang_items; -use middle::ty; -use util::nodemap::FnvHashMap; - -use std::rc::Rc; -use syntax::ast; -use syntax::attr; -use rustc_front::hir; - -#[derive(Copy, Clone)] -pub struct MethodInfo { - pub name: ast::Name, - pub def_id: DefId, - pub vis: hir::Visibility, -} - -pub fn get_symbol(cstore: &cstore::CStore, def: DefId) -> String { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_symbol(&cdata, def.index) -} - -/// Iterates over all the language items in the given crate. -pub fn each_lang_item(cstore: &cstore::CStore, - cnum: ast::CrateNum, - f: F) - -> bool where - F: FnMut(DefIndex, usize) -> bool, -{ - let crate_data = cstore.get_crate_data(cnum); - decoder::each_lang_item(&*crate_data, f) -} - -/// Iterates over each child of the given item. -pub fn each_child_of_item(cstore: &cstore::CStore, - def_id: DefId, - callback: F) where - F: FnMut(decoder::DefLike, ast::Name, hir::Visibility), -{ - let crate_data = cstore.get_crate_data(def_id.krate); - let get_crate_data = |cnum| { - cstore.get_crate_data(cnum) - }; - decoder::each_child_of_item(cstore.intr.clone(), - &*crate_data, - def_id.index, - get_crate_data, - callback) -} - -/// Iterates over each top-level crate item. -pub fn each_top_level_item_of_crate(cstore: &cstore::CStore, - cnum: ast::CrateNum, - callback: F) where - F: FnMut(decoder::DefLike, ast::Name, hir::Visibility), -{ - let crate_data = cstore.get_crate_data(cnum); - let get_crate_data = |cnum| { - cstore.get_crate_data(cnum) - }; - decoder::each_top_level_item_of_crate(cstore.intr.clone(), - &*crate_data, - get_crate_data, - callback) -} - -pub fn get_item_path(tcx: &ty::ctxt, def: DefId) -> Vec { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - let path = decoder::get_item_path(&*cdata, def.index); - - cdata.with_local_path(|cpath| { - let mut r = Vec::with_capacity(cpath.len() + path.len()); - r.push_all(cpath); - r.push_all(&path); - r - }) -} - -pub fn get_item_name(tcx: &ty::ctxt, def: DefId) -> ast::Name { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_item_name(&cstore.intr, &cdata, def.index) -} - -pub enum FoundAst<'ast> { - Found(&'ast InlinedItem), - FoundParent(DefId, &'ast InlinedItem), - NotFound, -} - -// Finds the AST for this item in the crate metadata, if any. If the item was -// not marked for inlining, then the AST will not be present and hence none -// will be returned. -pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId, - decode_inlined_item: decoder::DecodeInlinedItem) - -> FoundAst<'tcx> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::maybe_get_item_ast(&*cdata, tcx, def.index, decode_inlined_item) -} - -/// Returns information about the given implementation. -pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: DefId) - -> Vec { - let cdata = cstore.get_crate_data(impl_def_id.krate); - decoder::get_impl_items(&*cdata, impl_def_id.index) -} - -pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::ImplOrTraitItem<'tcx> { - let cdata = tcx.sess.cstore.get_crate_data(def.krate); - decoder::get_impl_or_trait_item(tcx.sess.cstore.intr.clone(), - &*cdata, - def.index, - tcx) -} - -pub fn get_trait_name(cstore: &cstore::CStore, def: DefId) -> ast::Name { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_trait_name(cstore.intr.clone(), - &*cdata, - def.index) -} - -pub fn is_static_method(cstore: &cstore::CStore, def: DefId) -> bool { - let cdata = cstore.get_crate_data(def.krate); - decoder::is_static_method(&*cdata, def.index) -} - -pub fn get_trait_item_def_ids(cstore: &cstore::CStore, def: DefId) - -> Vec { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_trait_item_def_ids(&*cdata, def.index) -} - -pub fn get_item_variances(cstore: &cstore::CStore, - def: DefId) -> ty::ItemVariances { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_item_variances(&*cdata, def.index) -} - -pub fn get_provided_trait_methods<'tcx>(tcx: &ty::ctxt<'tcx>, - def: DefId) - -> Vec>> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_provided_trait_methods(cstore.intr.clone(), &*cdata, def.index, tcx) -} - -pub fn get_associated_consts<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) - -> Vec>> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_associated_consts(cstore.intr.clone(), &*cdata, def.index, tcx) -} - -pub fn get_methods_if_impl(cstore: &cstore::CStore, - def: DefId) - -> Option > { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.index) -} - -pub fn get_item_attrs(cstore: &cstore::CStore, - def_id: DefId) - -> Vec { - let cdata = cstore.get_crate_data(def_id.krate); - decoder::get_item_attrs(&*cdata, def_id.index) -} - -pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_struct_field_names(&cstore.intr, &*cdata, def.index) -} - -pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) - -> FnvHashMap> { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_struct_field_attrs(&*cdata) -} - -pub fn get_type<'tcx>(tcx: &ty::ctxt<'tcx>, - def: DefId) - -> ty::TypeScheme<'tcx> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_type(&*cdata, def.index, tcx) -} - -pub fn get_trait_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::TraitDef<'tcx> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_trait_def(&*cdata, def.index, tcx) -} - -pub fn get_adt_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_adt_def(&cstore.intr, &*cdata, def.index, tcx) -} - -pub fn get_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::GenericPredicates<'tcx> -{ - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_predicates(&*cdata, def.index, tcx) -} - -pub fn get_super_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::GenericPredicates<'tcx> -{ - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_super_predicates(&*cdata, def.index, tcx) -} - -pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>, - def: DefId) - -> Option -{ - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_impl_polarity(&*cdata, def.index) -} - -pub fn get_custom_coerce_unsized_kind<'tcx>( - tcx: &ty::ctxt<'tcx>, - def: DefId) - -> Option -{ - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_custom_coerce_unsized_kind(&*cdata, def.index) -} - -// Given a def_id for an impl, return the trait it implements, -// if there is one. -pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>, - def: DefId) - -> Option> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_impl_trait(&*cdata, def.index, tcx) -} - -pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum) - -> Vec<(cstore::NativeLibraryKind, String)> { - let cdata = cstore.get_crate_data(crate_num); - decoder::get_native_libraries(&*cdata) -} - -pub fn each_inherent_implementation_for_type(cstore: &cstore::CStore, - def_id: DefId, - callback: F) where - F: FnMut(DefId), -{ - let cdata = cstore.get_crate_data(def_id.krate); - decoder::each_inherent_implementation_for_type(&*cdata, def_id.index, callback) -} - -pub fn each_implementation_for_trait(cstore: &cstore::CStore, - def_id: DefId, - mut callback: F) where - F: FnMut(DefId), -{ - cstore.iter_crate_data(|_, cdata| { - decoder::each_implementation_for_trait(cdata, def_id, &mut callback) - }) -} - -/// If the given def ID describes an item belonging to a trait (either a -/// default method or an implementation of a trait method), returns the ID of -/// the trait that the method belongs to. Otherwise, returns `None`. -pub fn get_trait_of_item(cstore: &cstore::CStore, - def_id: DefId, - tcx: &ty::ctxt) - -> Option { - let cdata = cstore.get_crate_data(def_id.krate); - decoder::get_trait_of_item(&*cdata, def_id.index, tcx) -} - -pub fn get_tuple_struct_definition_if_ctor(cstore: &cstore::CStore, - def_id: DefId) - -> Option -{ - let cdata = cstore.get_crate_data(def_id.krate); - decoder::get_tuple_struct_definition_if_ctor(&*cdata, def_id.index) -} - -pub fn get_dylib_dependency_formats(cstore: &cstore::CStore, - cnum: ast::CrateNum) - -> Vec<(ast::CrateNum, cstore::LinkagePreference)> -{ - let cdata = cstore.get_crate_data(cnum); - decoder::get_dylib_dependency_formats(&*cdata) -} - -pub fn get_missing_lang_items(cstore: &cstore::CStore, cnum: ast::CrateNum) - -> Vec -{ - let cdata = cstore.get_crate_data(cnum); - decoder::get_missing_lang_items(&*cdata) -} - -pub fn get_method_arg_names(cstore: &cstore::CStore, did: DefId) - -> Vec -{ - let cdata = cstore.get_crate_data(did.krate); - decoder::get_method_arg_names(&*cdata, did.index) -} - -pub fn get_reachable_ids(cstore: &cstore::CStore, cnum: ast::CrateNum) - -> Vec -{ - let cdata = cstore.get_crate_data(cnum); - decoder::get_reachable_ids(&*cdata) -} - -pub fn is_typedef(cstore: &cstore::CStore, did: DefId) -> bool { - let cdata = cstore.get_crate_data(did.krate); - decoder::is_typedef(&*cdata, did.index) -} - -pub fn is_const_fn(cstore: &cstore::CStore, did: DefId) -> bool { - let cdata = cstore.get_crate_data(did.krate); - decoder::is_const_fn(&*cdata, did.index) -} - -pub fn is_static(cstore: &cstore::CStore, did: DefId) -> bool { - let cdata = cstore.get_crate_data(did.krate); - decoder::is_static(&*cdata, did.index) -} - -pub fn is_impl(cstore: &cstore::CStore, did: DefId) -> bool { - let cdata = cstore.get_crate_data(did.krate); - decoder::is_impl(&*cdata, did.index) -} - -pub fn get_stability(cstore: &cstore::CStore, - def: DefId) - -> Option { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_stability(&*cdata, def.index) -} - -pub fn is_staged_api(cstore: &cstore::CStore, krate: ast::CrateNum) -> bool { - cstore.get_crate_data(krate).staged_api -} - -pub fn get_repr_attrs(cstore: &cstore::CStore, def: DefId) - -> Vec { - let cdata = cstore.get_crate_data(def.krate); - decoder::get_repr_attrs(&*cdata, def.index) -} - -pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: DefId) -> bool { - let cdata = cstore.get_crate_data(trait_def_id.krate); - decoder::is_defaulted_trait(&*cdata, trait_def_id.index) -} - -pub fn is_default_impl(cstore: &cstore::CStore, impl_did: DefId) -> bool { - let cdata = cstore.get_crate_data(impl_did.krate); - decoder::is_default_impl(&*cdata, impl_did.index) -} - -pub fn is_extern_fn(cstore: &cstore::CStore, did: DefId, - tcx: &ty::ctxt) -> bool { - let cdata = cstore.get_crate_data(did.krate); - decoder::is_extern_fn(&*cdata, did.index, tcx) -} - -pub fn closure_kind<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureKind { - assert!(!def_id.is_local()); - let cdata = tcx.sess.cstore.get_crate_data(def_id.krate); - decoder::closure_kind(&*cdata, def_id.index) -} - -pub fn closure_ty<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx> { - assert!(!def_id.is_local()); - let cdata = tcx.sess.cstore.get_crate_data(def_id.krate); - decoder::closure_ty(&*cdata, def_id.index, tcx) -} - -pub fn def_path(tcx: &ty::ctxt, def: DefId) -> ast_map::DefPath { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - let path = decoder::def_path(&*cdata, def.index); - let local_path = cdata.local_def_path(); - local_path.into_iter().chain(path).collect() -} diff --git a/src/librustc/metadata/inline.rs b/src/librustc/metadata/inline.rs deleted file mode 100644 index e621a4166d719..0000000000000 --- a/src/librustc/metadata/inline.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2012-2015 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. - -use middle::def_id::DefId; -use rustc_front::hir; -use rustc_front::util::IdVisitor; -use syntax::ast_util::{IdRange, IdRangeComputingVisitor, IdVisitingOperation}; -use syntax::ptr::P; -use rustc_front::intravisit::Visitor; -use self::InlinedItem::*; - -/// The data we save and restore about an inlined item or method. This is not -/// part of the AST that we parse from a file, but it becomes part of the tree -/// that we trans. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum InlinedItem { - Item(P), - TraitItem(DefId /* impl id */, P), - ImplItem(DefId /* impl id */, P), - Foreign(P), -} - -/// A borrowed version of `hir::InlinedItem`. -pub enum InlinedItemRef<'a> { - Item(&'a hir::Item), - TraitItem(DefId, &'a hir::TraitItem), - ImplItem(DefId, &'a hir::ImplItem), - Foreign(&'a hir::ForeignItem) -} - -impl InlinedItem { - pub fn visit<'ast,V>(&'ast self, visitor: &mut V) - where V: Visitor<'ast> - { - match *self { - Item(ref i) => visitor.visit_item(&**i), - Foreign(ref i) => visitor.visit_foreign_item(&**i), - TraitItem(_, ref ti) => visitor.visit_trait_item(ti), - ImplItem(_, ref ii) => visitor.visit_impl_item(ii), - } - } - - pub fn visit_ids(&self, operation: &mut O) { - let mut id_visitor = IdVisitor::new(operation); - self.visit(&mut id_visitor); - } - - pub fn compute_id_range(&self) -> IdRange { - let mut visitor = IdRangeComputingVisitor::new(); - self.visit_ids(&mut visitor); - visitor.result() - } -} diff --git a/src/librustc/metadata/mod.rs b/src/librustc/metadata/mod.rs deleted file mode 100644 index 052ed81394b05..0000000000000 --- a/src/librustc/metadata/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 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. - -pub mod common; -pub mod tyencode; -pub mod tydecode; -pub mod encoder; -pub mod decoder; -pub mod creader; -pub mod cstore; -pub mod index; -pub mod loader; -pub mod filesearch; -pub mod macro_import; -pub mod inline; -pub mod util; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 63134a8766d96..21ece8f381ebf 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -16,7 +16,7 @@ use self::EvalHint::*; use front::map as ast_map; use front::map::blocks::FnLikeNode; -use metadata::util::{self as mdutil, CrateStore, InlinedItem}; +use middle::cstore::{self, CrateStore, InlinedItem}; use middle::{def, infer, subst, traits}; use middle::def_id::DefId; use middle::pat_util::def_to_path; @@ -145,11 +145,11 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, } let mut used_ref_id = false; let expr_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) { - mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node { + cstore::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node { hir::ItemConst(_, ref const_expr) => Some(const_expr.id), _ => None }, - mdutil::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node { + cstore::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node { hir::ConstTraitItem(_, _) => { used_ref_id = true; match maybe_ref_id { @@ -168,7 +168,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, } _ => None }, - mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node { + cstore::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node { hir::ImplItemKind::Const(_, ref expr) => Some(expr.id), _ => None }, @@ -200,8 +200,8 @@ fn inline_const_fn_from_external_crate(tcx: &ty::ctxt, def_id: DefId) } let fn_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) { - mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id), - mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id), + cstore::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id), + cstore::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id), _ => None }; tcx.extern_const_fns.borrow_mut().insert(def_id, diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs new file mode 100644 index 0000000000000..ee337f02ffc96 --- /dev/null +++ b/src/librustc/middle/cstore.rs @@ -0,0 +1,277 @@ +// Copyright 2015 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. + +// Copyright 2015 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. + +// the rustc crate store interface. This also includes types that +// are *mostly* used as a part of that interface, but these should +// probably get a better home if someone can find one. + +use back::svh::Svh; +use front::map as hir_map; +use middle::def; +use middle::lang_items; +use middle::ty::{self, Ty}; +use middle::def_id::{DefId, DefIndex}; +use session::Session; +use session::search_paths::PathKind; +use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; +use std::any::Any; +use std::cell::RefCell; +use std::rc::Rc; +use std::path::PathBuf; +use syntax::ast; +use syntax::ast_util::{IdVisitingOperation}; +use syntax::attr; +use syntax::codemap::Span; +use syntax::ptr::P; +use rustc_back::target::Target; +use rustc_front::hir; +use rustc_front::visit::Visitor; +use rustc_front::util::IdVisitor; + +pub use self::DefLike::{DlDef, DlField, DlImpl}; +pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown}; + +// lonely orphan structs and enums looking for a better home + +#[derive(Clone, Debug)] +pub struct LinkMeta { + pub crate_name: String, + pub crate_hash: Svh, +} + +// Where a crate came from on the local filesystem. One of these two options +// must be non-None. +#[derive(PartialEq, Clone, Debug)] +pub struct CrateSource { + pub dylib: Option<(PathBuf, PathKind)>, + pub rlib: Option<(PathBuf, PathKind)>, + pub cnum: ast::CrateNum, +} + +#[derive(Copy, Debug, PartialEq, Clone)] +pub enum LinkagePreference { + RequireDynamic, + RequireStatic, +} + +enum_from_u32! { + #[derive(Copy, Clone, PartialEq)] + pub enum NativeLibraryKind { + NativeStatic, // native static library (.a archive) + NativeFramework, // OSX-specific + NativeUnknown, // default way to specify a dynamic library + } +} + +// Something that a name can resolve to. +#[derive(Copy, Clone, Debug)] +pub enum DefLike { + DlDef(def::Def), + DlImpl(DefId), + DlField +} + +/// The data we save and restore about an inlined item or method. This is not +/// part of the AST that we parse from a file, but it becomes part of the tree +/// that we trans. +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum InlinedItem { + Item(P), + TraitItem(DefId /* impl id */, P), + ImplItem(DefId /* impl id */, P), + Foreign(P), +} + +/// A borrowed version of `hir::InlinedItem`. +pub enum InlinedItemRef<'a> { + Item(&'a hir::Item), + TraitItem(DefId, &'a hir::TraitItem), + ImplItem(DefId, &'a hir::ImplItem), + Foreign(&'a hir::ForeignItem) +} + +/// Item definitions in the currently-compiled crate would have the CrateNum +/// LOCAL_CRATE in their DefId. +pub const LOCAL_CRATE: ast::CrateNum = 0; + +pub struct ChildItem { + pub def: DefLike, + pub name: ast::Name, + pub vis: hir::Visibility +} + +pub enum FoundAst<'ast> { + Found(&'ast InlinedItem), + FoundParent(DefId, &'ast InlinedItem), + NotFound, +} + +pub trait CrateStore<'tcx> : Any { + // item info + fn stability(&self, def: DefId) -> Option; + fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) + -> ty::ClosureKind; + fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) + -> ty::ClosureTy<'tcx>; + fn item_variances(&self, def: DefId) -> ty::ItemVariances; + fn repr_attrs(&self, def: DefId) -> Vec; + fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> ty::TypeScheme<'tcx>; + fn item_path(&self, def: DefId) -> Vec; + fn item_name(&self, def: DefId) -> ast::Name; + fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> ty::GenericPredicates<'tcx>; + fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> ty::GenericPredicates<'tcx>; + fn item_attrs(&self, def_id: DefId) -> Vec; + fn item_symbol(&self, def: DefId) -> String; + fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>; + fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>; + fn method_arg_names(&self, did: DefId) -> Vec; + fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec; + + // trait info + fn implementations_of_trait(&self, def_id: DefId) -> Vec; + fn provided_trait_methods(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> Vec>>; + fn trait_item_def_ids(&self, def: DefId) + -> Vec; + + // impl info + fn impl_items(&self, impl_def_id: DefId) -> Vec; + fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> Option>; + fn impl_polarity(&self, def: DefId) -> Option; + fn custom_coerce_unsized_kind(&self, def: DefId) + -> Option; + fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> Vec>>; + + // trait/impl-item info + fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) + -> Option; + fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> ty::ImplOrTraitItem<'tcx>; + + // flags + fn is_const_fn(&self, did: DefId) -> bool; + fn is_defaulted_trait(&self, did: DefId) -> bool; + fn is_impl(&self, did: DefId) -> bool; + fn is_default_impl(&self, impl_did: DefId) -> bool; + fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool; + fn is_static(&self, did: DefId) -> bool; + fn is_static_method(&self, did: DefId) -> bool; + fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool; + fn is_typedef(&self, did: DefId) -> bool; + + // crate metadata + fn dylib_dependency_formats(&self, cnum: ast::CrateNum) + -> Vec<(ast::CrateNum, LinkagePreference)>; + fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>; + fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec; + fn is_staged_api(&self, cnum: ast::CrateNum) -> bool; + fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool; + fn is_allocator(&self, cnum: ast::CrateNum) -> bool; + fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec; + fn crate_name(&self, cnum: ast::CrateNum) -> String; + fn crate_hash(&self, cnum: ast::CrateNum) -> Svh; + fn crate_struct_field_attrs(&self, cnum: ast::CrateNum) + -> FnvHashMap>; + fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option; + fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>; + fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec; + + // resolve + fn def_path(&self, def: DefId) -> hir_map::DefPath; + fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option; + fn struct_field_names(&self, def: DefId) -> Vec; + fn item_children(&self, did: DefId) -> Vec; + fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec; + + // misc. metadata + fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId) + -> FoundAst<'tcx>; + // This is basically a 1-based range of ints, which is a little + // silly - I may fix that. + fn crates(&self) -> Vec; + fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)>; + fn used_link_args(&self) -> Vec; + + // utility functions + fn metadata_filename(&self) -> &str; + fn metadata_section_name(&self, target: &Target) -> &str; + fn encode_type(&self, tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Vec; + fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option)>; + fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource; + fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option; + fn encode_metadata(&self, + tcx: &ty::ctxt<'tcx>, + reexports: &def::ExportMap, + item_symbols: &RefCell>, + link_meta: &LinkMeta, + reachable: &NodeSet, + krate: &hir::Crate) -> Vec; + fn metadata_encoding_version(&self) -> &[u8]; +} + +impl InlinedItem { + pub fn visit<'ast,V>(&'ast self, visitor: &mut V) + where V: Visitor<'ast> + { + match *self { + InlinedItem::Item(ref i) => visitor.visit_item(&**i), + InlinedItem::Foreign(ref i) => visitor.visit_foreign_item(&**i), + InlinedItem::TraitItem(_, ref ti) => visitor.visit_trait_item(ti), + InlinedItem::ImplItem(_, ref ii) => visitor.visit_impl_item(ii), + } + } + + pub fn visit_ids(&self, operation: &mut O) { + let mut id_visitor = IdVisitor { + operation: operation, + pass_through_items: true, + visited_outermost: false, + }; + self.visit(&mut id_visitor); + } +} + +// FIXME: find a better place for this? +pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option) { + let say = |s: &str| { + match (sp, sess) { + (_, None) => panic!("{}", s), + (Some(sp), Some(sess)) => sess.span_err(sp, s), + (None, Some(sess)) => sess.err(s), + } + }; + if s.is_empty() { + say("crate name must not be empty"); + } + for c in s.chars() { + if c.is_alphanumeric() { continue } + if c == '_' { continue } + say(&format!("invalid character `{}` in crate name: `{}`", c, s)); + } + match sess { + Some(sess) => sess.abort_if_errors(), + None => {} + } +} diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs index 288eb01ebb470..4d0005f47c4f2 100644 --- a/src/librustc/middle/def_id.rs +++ b/src/librustc/middle/def_id.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::ty; use syntax::ast::CrateNum; use std::fmt; diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 229ed5984b06e..ab5153e1a61d4 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -65,8 +65,8 @@ use syntax::ast; use session; use session::config; -use metadata::util::CrateStore; -use metadata::util::LinkagePreference::{self, RequireStatic, RequireDynamic}; +use middle::cstore::CrateStore; +use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic}; use util::nodemap::FnvHashMap; /// A list of dependencies for a certain crate type. diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 5101e69204d10..5563cd8043819 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -76,7 +76,7 @@ use front::map as ast_map; use rustc_front::hir; use rustc_front::print::pprust; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use middle::def; use middle::def_id::DefId; use middle::infer::{self, TypeOrigin}; diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index c9be73892e40d..ec55daca9ecdf 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -23,7 +23,7 @@ pub use self::LangItem::*; use front::map as hir_map; use session::Session; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use middle::def_id::DefId; use middle::ty; use middle::weak_lang_items; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 45b8ac4a16dae..e3504b6a744dc 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -16,10 +16,10 @@ //! Most of the documentation on regions can be found in //! `middle/typeck/infer/region_inference.rs` -use metadata::inline::InlinedItem; use front::map as ast_map; use session::Session; use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; +use middle::cstore::InlinedItem; use middle::ty::{self, Ty}; use std::cell::RefCell; diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index f70dce90fed11..0d92c3da83c8b 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -15,8 +15,7 @@ pub use self::StabilityLevel::*; use session::Session; use lint; -use metadata::cstore::LOCAL_CRATE; -use metadata::util::CrateStore; +use middle::cstore::{CrateStore, LOCAL_CRATE}; use middle::def; use middle::def_id::{CRATE_DEF_INDEX, DefId}; use middle::ty; diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index 705cb97a898eb..56dc259b1c2f0 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -17,7 +17,7 @@ use super::PredicateObligation; use super::project; use super::util; -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def_id::DefId; use middle::subst::{Subst, Substs, TypeSpace}; use middle::ty::{self, Ty}; diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index 105abe155093f..4b61453992111 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -16,8 +16,8 @@ use front::map as ast_map; use session::Session; use lint; -use metadata::util::CrateStore; use middle; +use middle::cstore::CrateStore; use middle::def::DefMap; use middle::def_id::DefId; use middle::free_region::FreeRegionMap; diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index bedff8b9a8a9d..71ae8e40b45f0 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -21,9 +21,8 @@ pub use self::LvaluePreference::*; use front::map as ast_map; use front::map::LinkedPath; -use metadata::cstore::LOCAL_CRATE; -use metadata::util::CrateStore; use middle; +use middle::cstore::{CrateStore, LOCAL_CRATE}; use middle::def::{self, ExportMap}; use middle::def_id::DefId; use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index a6c2fd08e8705..78cdc99f047d7 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -12,7 +12,7 @@ use session::config; use session::Session; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use middle::lang_items; use syntax::ast; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 4781992b9875d..5d691af49dccb 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -22,7 +22,7 @@ use session::search_paths::SearchPaths; use rustc_back::target::Target; use lint; -use metadata::cstore; +use middle::cstore; use syntax::ast::{self, IntTy, UintTy}; use syntax::attr; diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/session/filesearch.rs similarity index 100% rename from src/librustc/metadata/filesearch.rs rename to src/librustc/session/filesearch.rs diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index bf9c4c8bca627..7bf96b41dce7f 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -9,8 +9,7 @@ // except according to those terms. use lint; -use metadata::filesearch; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use middle::dependency_format; use session::search_paths::PathKind; use util::nodemap::{NodeMap, FnvHashMap}; @@ -34,6 +33,7 @@ use std::env; use std::rc::Rc; pub mod config; +pub mod filesearch; pub mod search_paths; // Represents the data associated with a compilation diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index d00b08538d235..1429a6a54a668 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -16,9 +16,6 @@ use rustc::session::Session; use rustc::session::config::{self, Input, OutputFilenames, OutputType}; use rustc::session::search_paths::PathKind; use rustc::lint; -use rustc::metadata; -use rustc::metadata::creader::LocalCrateReader; -use rustc::metadata::cstore::CStore; use rustc::middle::{stability, ty, reachable}; use rustc::middle::dependency_format; use rustc::middle; @@ -26,6 +23,9 @@ use rustc::util::nodemap::NodeMap; use rustc::util::common::time; use rustc_borrowck as borrowck; use rustc_resolve as resolve; +use rustc_metadata::macro_import; +use rustc_metadata::creader::LocalCrateReader; +use rustc_metadata::cstore::CStore; use rustc_trans::back::link; use rustc_trans::back::write; use rustc_trans::trans; @@ -482,7 +482,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, let macros = time(time_passes, "macro loading", - || metadata::macro_import::read_macro_defs(sess, &cstore, &krate)); + || macro_import::read_macro_defs(sess, &cstore, &krate)); let mut addl_plugins = Some(addl_plugins); let registrars = time(time_passes, "plugin loading", || { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index fdbb093eab084..b77425e180929 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -47,6 +47,7 @@ extern crate rustc_front; extern crate rustc_lint; extern crate rustc_plugin; extern crate rustc_privacy; +extern crate rustc_metadata; extern crate rustc_mir; extern crate rustc_resolve; extern crate rustc_trans; @@ -68,11 +69,11 @@ use rustc_trans::back::link; use rustc_trans::save; use rustc::session::{config, Session, build_session}; use rustc::session::config::{Input, PrintRequest, OutputType}; +use rustc::middle::cstore::CrateStore; use rustc::lint::Lint; use rustc::lint; -use rustc::metadata; -use rustc::metadata::cstore::CStore; -use rustc::metadata::util::CrateStore; +use rustc_metadata::loader; +use rustc_metadata::cstore::CStore; use rustc::util::common::time; use std::cmp::Ordering::Equal; @@ -448,7 +449,7 @@ impl RustcDefaultCalls { &Input::File(ref ifile) => { let path = &(*ifile); let mut v = Vec::new(); - metadata::loader::list_file_metadata(&sess.target.target, path, &mut v) + loader::list_file_metadata(&sess.target.target, path, &mut v) .unwrap(); println!("{}", String::from_utf8(v).unwrap()); } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index ddd5f931a80e9..630c42db68c79 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -19,7 +19,6 @@ use rustc_trans::back::link; use driver; -use rustc::metadata::cstore::CStore; use rustc::middle::ty; use rustc::middle::cfg; use rustc::middle::cfg::graphviz::LabelledCFG; @@ -28,6 +27,7 @@ use rustc::session::config::Input; use rustc_borrowck as borrowck; use rustc_borrowck::graphviz as borrowck_dot; use rustc_resolve as resolve; +use rustc_metadata::cstore::CStore; use syntax::ast; use syntax::codemap; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 7327170c52bde..739c5f12ecb30 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -29,11 +29,11 @@ //! a `pub fn new()`. use middle::{cfg, def, infer, stability, traits}; +use middle::cstore::CrateStore; use middle::def_id::DefId; use middle::subst::Substs; use middle::ty::{self, Ty}; use middle::ty::adjustment; -use rustc::metadata::util::CrateStore; use rustc::front::map as hir_map; use util::nodemap::{NodeSet}; use lint::{Level, LateContext, LintContext, LintArray, Lint}; diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index d48dbdc5f5171..1d7431404f545 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -50,7 +50,6 @@ extern crate rustc_front; extern crate rustc_back; pub use rustc::lint as lint; -pub use rustc::metadata as metadata; pub use rustc::middle as middle; pub use rustc::session as session; pub use rustc::util as util; diff --git a/src/librustc/middle/astencode.rs b/src/librustc_metadata/astencode.rs similarity index 99% rename from src/librustc/middle/astencode.rs rename to src/librustc_metadata/astencode.rs index 752fdc2347411..2ecf715424b16 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc_metadata/astencode.rs @@ -12,19 +12,21 @@ // FIXME: remove this after snapshot, and Results are handled #![allow(unused_must_use)] -use front::map as ast_map; +use rustc::front::map as ast_map; +use rustc::session::Session; + use rustc_front::hir; use rustc_front::fold; use rustc_front::fold::Folder; -use metadata::common as c; -use metadata::cstore as cstore; -use session::Session; -use metadata::decoder; -use metadata::encoder as e; -use metadata::inline::{InlinedItem, InlinedItemRef}; -use metadata::tydecode; -use metadata::tyencode; +use common as c; +use cstore; +use decoder; +use encoder as e; +use tydecode; +use tyencode; + +use middle::cstore::{InlinedItem, InlinedItemRef}; use middle::ty::adjustment; use middle::ty::cast; use middle::check_const::ConstQualif; @@ -89,7 +91,7 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext, // Folding could be avoided with a smarter encoder. let ii = simplify_ast(ii); - let id_range = ii.compute_id_range(); + let id_range = inlined_item_id_range(&ii); rbml_w.start_tag(c::tag_ast as usize); id_range.encode(rbml_w); @@ -1326,6 +1328,12 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) { } } +fn inlined_item_id_range(v: &InlinedItem) -> ast_util::IdRange { + let mut visitor = ast_util::IdRangeComputingVisitor::new(); + v.visit_ids(&mut visitor); + visitor.result() +} + // ______________________________________________________________________ // Testing of astencode_gen diff --git a/src/librustc/metadata/common.rs b/src/librustc_metadata/common.rs similarity index 98% rename from src/librustc/metadata/common.rs rename to src/librustc_metadata/common.rs index a4fee5b7aa805..b6454a4c81a2f 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc_metadata/common.rs @@ -12,8 +12,6 @@ pub use self::astencode_tag::*; -use back::svh::Svh; - // RBML enum definitions and utils shared by the encoder and decoder // // 0x00..0x1f: reserved for RBML generic type tags @@ -191,12 +189,6 @@ pub const tag_items_data_item_stability: usize = 0x88; pub const tag_items_data_item_repr: usize = 0x89; -#[derive(Clone, Debug)] -pub struct LinkMeta { - pub crate_name: String, - pub crate_hash: Svh, -} - pub const tag_struct_fields: usize = 0x10d; // top-level only pub const tag_struct_field: usize = 0x8a; diff --git a/src/librustc/metadata/creader.rs b/src/librustc_metadata/creader.rs similarity index 97% rename from src/librustc/metadata/creader.rs rename to src/librustc_metadata/creader.rs index 191b1705371cc..89aa3bf86611a 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -12,17 +12,17 @@ //! Validates all used crates and extern libraries and loads their metadata -use back::svh::Svh; -use session::{config, Session}; -use session::search_paths::PathKind; -use metadata::common::rustc_version; -use metadata::cstore; -use metadata::cstore::{CStore, CrateSource, MetadataBlob}; -use metadata::decoder; -use metadata::loader; -use metadata::loader::CratePaths; -use util::nodemap::FnvHashMap; -use front::map as hir_map; +use common::rustc_version; +use cstore::{self, CStore, CrateSource, MetadataBlob}; +use decoder; +use loader::{self, CratePaths}; + +use rustc::back::svh::Svh; +use rustc::session::{config, Session}; +use rustc::session::search_paths::PathKind; +use rustc::middle::cstore::validate_crate_name; +use rustc::util::nodemap::FnvHashMap; +use rustc::front::map as hir_map; use std::cell::{RefCell, Cell}; use std::path::PathBuf; @@ -91,29 +91,6 @@ struct CrateInfo { should_link: bool, } -pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option) { - let say = |s: &str| { - match (sp, sess) { - (_, None) => panic!("{}", s), - (Some(sp), Some(sess)) => sess.span_err(sp, s), - (None, Some(sess)) => sess.err(s), - } - }; - if s.is_empty() { - say("crate name must not be empty"); - } - for c in s.chars() { - if c.is_alphanumeric() { continue } - if c == '_' { continue } - say(&format!("invalid character `{}` in crate name: `{}`", c, s)); - } - match sess { - Some(sess) => sess.abort_if_errors(), - None => {} - } -} - - fn register_native_lib(sess: &Session, cstore: &CStore, span: Option, diff --git a/src/librustc/metadata/util.rs b/src/librustc_metadata/csearch.rs similarity index 69% rename from src/librustc/metadata/util.rs rename to src/librustc_metadata/csearch.rs index f00dd3b852c6d..99fa18837ebe6 100644 --- a/src/librustc/metadata/util.rs +++ b/src/librustc_metadata/csearch.rs @@ -8,160 +8,31 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::svh::Svh; -use front::map as ast_map; -use metadata::cstore; -use metadata::decoder; -use metadata::encoder; -use metadata::loader; -use middle::astencode; +use astencode; +use cstore; +use decoder; +use encoder; +use loader; + +use middle::cstore::{CrateStore, CrateSource, ChildItem, FoundAst}; +use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference}; use middle::def; use middle::lang_items; use middle::ty::{self, Ty}; use middle::def_id::{DefId, DefIndex}; -use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; -use std::any::Any; +use rustc::front::map as ast_map; +use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet}; + use std::cell::RefCell; use std::rc::Rc; use std::path::PathBuf; use syntax::ast; use syntax::attr; +use rustc_back::svh::Svh; use rustc_back::target::Target; use rustc_front::hir; -pub use metadata::common::LinkMeta; -pub use metadata::creader::validate_crate_name; -pub use metadata::cstore::CrateSource; -pub use metadata::cstore::LinkagePreference; -pub use metadata::cstore::NativeLibraryKind; -pub use metadata::decoder::DecodeInlinedItem; -pub use metadata::decoder::DefLike; -pub use metadata::inline::InlinedItem; - -pub use self::DefLike::{DlDef, DlField, DlImpl}; -pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown}; - -pub struct ChildItem { - pub def: DefLike, - pub name: ast::Name, - pub vis: hir::Visibility -} - -pub enum FoundAst<'ast> { - Found(&'ast InlinedItem), - FoundParent(DefId, &'ast InlinedItem), - NotFound, -} - -pub trait CrateStore<'tcx> : Any { - // item info - fn stability(&self, def: DefId) -> Option; - fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) - -> ty::ClosureKind; - fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) - -> ty::ClosureTy<'tcx>; - fn item_variances(&self, def: DefId) -> ty::ItemVariances; - fn repr_attrs(&self, def: DefId) -> Vec; - fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::TypeScheme<'tcx>; - fn item_path(&self, def: DefId) -> Vec; - fn item_name(&self, def: DefId) -> ast::Name; - fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::GenericPredicates<'tcx>; - fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::GenericPredicates<'tcx>; - fn item_attrs(&self, def_id: DefId) -> Vec; - fn item_symbol(&self, def: DefId) -> String; - fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>; - fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>; - fn method_arg_names(&self, did: DefId) -> Vec; - fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec; - - // trait info - fn implementations_of_trait(&self, def_id: DefId) -> Vec; - fn provided_trait_methods(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> Vec>>; - fn trait_item_def_ids(&self, def: DefId) - -> Vec; - - // impl info - fn impl_items(&self, impl_def_id: DefId) -> Vec; - fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> Option>; - fn impl_polarity(&self, def: DefId) -> Option; - fn custom_coerce_unsized_kind(&self, def: DefId) - -> Option; - fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> Vec>>; - - // trait/impl-item info - fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) - -> Option; - fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> ty::ImplOrTraitItem<'tcx>; - - // flags - fn is_const_fn(&self, did: DefId) -> bool; - fn is_defaulted_trait(&self, did: DefId) -> bool; - fn is_impl(&self, did: DefId) -> bool; - fn is_default_impl(&self, impl_did: DefId) -> bool; - fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool; - fn is_static(&self, did: DefId) -> bool; - fn is_static_method(&self, did: DefId) -> bool; - fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool; - fn is_typedef(&self, did: DefId) -> bool; - - // crate metadata - fn dylib_dependency_formats(&self, cnum: ast::CrateNum) - -> Vec<(ast::CrateNum, LinkagePreference)>; - fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>; - fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec; - fn is_staged_api(&self, cnum: ast::CrateNum) -> bool; - fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool; - fn is_allocator(&self, cnum: ast::CrateNum) -> bool; - fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec; - fn crate_name(&self, cnum: ast::CrateNum) -> String; - fn crate_hash(&self, cnum: ast::CrateNum) -> Svh; - fn crate_struct_field_attrs(&self, cnum: ast::CrateNum) - -> FnvHashMap>; - fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option; - fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>; - fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec; - - // resolve - fn def_path(&self, def: DefId) -> ast_map::DefPath; - fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option; - fn struct_field_names(&self, def: DefId) -> Vec; - fn item_children(&self, did: DefId) -> Vec; - fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec; - - // misc. metadata - fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId) - -> FoundAst<'tcx>; - // This is basically a 1-based range of ints, which is a little - // silly - I may fix that. - fn crates(&self) -> Vec; - fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)>; - fn used_link_args(&self) -> Vec; - - // utility functions - fn metadata_filename(&self) -> &str; - fn metadata_section_name(&self, target: &Target) -> &str; - fn encode_type(&self, tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Vec; - fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option)>; - fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource; - fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option; - fn encode_metadata(&self, - tcx: &ty::ctxt<'tcx>, - reexports: &def::ExportMap, - item_symbols: &RefCell>, - link_meta: &LinkMeta, - reachable: &NodeSet, - krate: &hir::Crate) -> Vec; - fn metadata_encoding_version(&self) -> &[u8]; -} - impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn stability(&self, def: DefId) -> Option { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc_metadata/cstore.rs similarity index 90% rename from src/librustc/metadata/cstore.rs rename to src/librustc_metadata/cstore.rs index 706033f815c38..6a1f9d16fe7a4 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -14,13 +14,15 @@ // crates and libraries pub use self::MetadataBlob::*; -pub use self::LinkagePreference::*; -pub use self::NativeLibraryKind::*; -use back::svh::Svh; -use metadata::{creader, decoder, index, loader}; -use session::search_paths::PathKind; -use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; +use creader; +use decoder; +use index; +use loader; + +use rustc::back::svh::Svh; +use rustc::front::map as ast_map; +use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet}; use std::cell::{RefCell, Ref, Cell}; use std::rc::Rc; @@ -32,7 +34,10 @@ use syntax::codemap; use syntax::parse::token; use syntax::parse::token::IdentInterner; use syntax::util::small_vector::SmallVector; -use front::map as ast_map; + +pub use middle::cstore::{NativeLibraryKind, LinkagePreference}; +pub use middle::cstore::{NativeStatic, NativeFramework, NativeUnknown}; +pub use middle::cstore::{CrateSource, LinkMeta}; // A map from external crate numbers (as decoded from some crate file) to // local crate numbers (as generated during this session). Each external @@ -77,30 +82,6 @@ pub struct crate_metadata { pub explicitly_linked: Cell, } -#[derive(Copy, Debug, PartialEq, Clone)] -pub enum LinkagePreference { - RequireDynamic, - RequireStatic, -} - -enum_from_u32! { - #[derive(Copy, Clone, PartialEq)] - pub enum NativeLibraryKind { - NativeStatic, // native static library (.a archive) - NativeFramework, // OSX-specific - NativeUnknown, // default way to specify a dynamic library - } -} - -// Where a crate came from on the local filesystem. One of these two options -// must be non-None. -#[derive(PartialEq, Clone, Debug)] -pub struct CrateSource { - pub dylib: Option<(PathBuf, PathKind)>, - pub rlib: Option<(PathBuf, PathKind)>, - pub cnum: ast::CrateNum, -} - pub struct CStore { metas: RefCell>>, /// Map from NodeId's of local extern crate statements to crate numbers @@ -112,10 +93,6 @@ pub struct CStore { pub intr: Rc, } -/// Item definitions in the currently-compiled crate would have the CrateNum -/// LOCAL_CRATE in their DefId. -pub const LOCAL_CRATE: ast::CrateNum = 0; - impl CStore { pub fn new(intr: Rc) -> CStore { CStore { @@ -218,8 +195,8 @@ impl CStore { let mut libs = self.used_crate_sources.borrow() .iter() .map(|src| (src.cnum, match prefer { - RequireDynamic => src.dylib.clone().map(|p| p.0), - RequireStatic => src.rlib.clone().map(|p| p.0), + LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0), + LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0), })) .collect::>(); libs.sort_by(|&(a, _), &(b, _)| { diff --git a/src/librustc/metadata/decoder.rs b/src/librustc_metadata/decoder.rs similarity index 98% rename from src/librustc/metadata/decoder.rs rename to src/librustc_metadata/decoder.rs index 84a95f047951a..092f7849115c3 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -12,29 +12,27 @@ #![allow(non_camel_case_types)] -pub use self::DefLike::*; use self::Family::*; -use front::map as hir_map; +use cstore::{self, crate_metadata}; +use common::*; +use encoder::def_to_u64; +use index; +use tydecode::TyDecoder; + +use rustc::back::svh::Svh; +use rustc::front::map as hir_map; +use rustc::util::nodemap::FnvHashMap; use rustc_front::hir; -use back::svh::Svh; -use metadata::cstore::crate_metadata; -use metadata::cstore::LOCAL_CRATE; -use metadata::common::*; -use metadata::cstore; -use metadata::encoder::def_to_u64; -use metadata::index; -use metadata::inline::InlinedItem; -use metadata::tydecode::TyDecoder; -use metadata::util::FoundAst; +use middle::cstore::{LOCAL_CRATE, FoundAst, InlinedItem, LinkagePreference}; +use middle::cstore::{DefLike, DlDef, DlField, DlImpl}; use middle::def; use middle::def_id::{DefId, DefIndex}; use middle::lang_items; use middle::subst; use middle::ty::{ImplContainer, TraitContainer}; use middle::ty::{self, RegionEscape, Ty}; -use util::nodemap::FnvHashMap; use std::cell::{Cell, RefCell}; use std::io::prelude::*; @@ -590,14 +588,6 @@ pub fn get_symbol_from_buf(data: &[u8], id: DefIndex) -> String { item_symbol(doc) } -// Something that a name can resolve to. -#[derive(Copy, Clone, Debug)] -pub enum DefLike { - DlDef(def::Def), - DlImpl(DefId), - DlField -} - /// Iterates over the language items in the given crate. pub fn each_lang_item(cdata: Cmd, mut f: F) -> bool where F: FnMut(DefIndex, usize) -> bool, @@ -1315,7 +1305,7 @@ pub fn each_exported_macro(data: &[u8], intr: &IdentInterner, mut f: F) where } pub fn get_dylib_dependency_formats(cdata: Cmd) - -> Vec<(ast::CrateNum, cstore::LinkagePreference)> + -> Vec<(ast::CrateNum, LinkagePreference)> { let formats = reader::get_doc(rbml::Doc::new(cdata.data()), tag_dylib_dependency_formats); @@ -1332,9 +1322,9 @@ pub fn get_dylib_dependency_formats(cdata: Cmd) None => panic!("didn't find a crate in the cnum_map") }; result.push((cnum, if link == "d" { - cstore::RequireDynamic + LinkagePreference::RequireDynamic } else { - cstore::RequireStatic + LinkagePreference::RequireStatic })); } return result; diff --git a/src/librustc_metadata/diagnostics.rs b/src/librustc_metadata/diagnostics.rs new file mode 100644 index 0000000000000..2340efd2cae7a --- /dev/null +++ b/src/librustc_metadata/diagnostics.rs @@ -0,0 +1,77 @@ +// Copyright 2015 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. + +#![allow(non_snake_case)] + +register_long_diagnostics! { +E0454: r##" +A link name was given with an empty name. Erroneous code example: + +``` +#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name +``` + +The rust compiler cannot link to an external library if you don't give it its +name. Example: + +``` +#[link(name = "some_lib")] extern {} // ok! +``` +"##, + +E0458: r##" +An unknown "kind" was specified for a link attribute. Erroneous code example: + +``` +#[link(kind = "wonderful_unicorn")] extern {} +// error: unknown kind: `wonderful_unicorn` +``` + +Please specify a valid "kind" value, from one of the following: + * static + * dylib + * framework +"##, + +E0459: r##" +A link was used without a name parameter. Erroneous code example: + +``` +#[link(kind = "dylib")] extern {} +// error: #[link(...)] specified without `name = "foo"` +``` + +Please add the name parameter to allow the rust compiler to find the library +you want. Example: + +``` +#[link(kind = "dylib", name = "some_lib")] extern {} // ok! +``` +"##, + +} + +register_diagnostics! { + E0455, // native frameworks are only available on OSX targets + E0456, // plugin `..` is not available for triple `..` + E0457, // plugin `..` only found in rlib format, but must be available... + E0514, // metadata version mismatch + E0460, // found possibly newer version of crate `..` + E0461, // couldn't find crate `..` with expected target triple .. + E0462, // found staticlib `..` instead of rlib or dylib + E0463, // can't find crate for `..` + E0464, // multiple matching crates for `..` + E0465, // multiple .. candidates for `..` found + E0466, // bad macro import + E0467, // bad macro reexport + E0468, // an `extern crate` loading macros must be at the crate root + E0469, // imported macro not found + E0470, // reexported macro not found +} diff --git a/src/librustc/metadata/encoder.rs b/src/librustc_metadata/encoder.rs similarity index 99% rename from src/librustc/metadata/encoder.rs rename to src/librustc_metadata/encoder.rs index d86d6c25cce02..1d88fa4454bda 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -13,23 +13,25 @@ #![allow(unused_must_use)] // everything is just a MemWriter, can't fail #![allow(non_camel_case_types)] -use back::svh::Svh; -use session::config; -use metadata::common::*; -use metadata::cstore; -use metadata::cstore::LOCAL_CRATE; -use metadata::decoder; -use metadata::tyencode; -use metadata::index::{self, IndexData}; -use metadata::inline::InlinedItemRef; -use metadata::util::CrateStore; +use common::*; +use cstore; +use decoder; +use tyencode; +use index::{self, IndexData}; + +use middle::cstore::{LOCAL_CRATE, CrateStore, InlinedItemRef, LinkMeta}; use middle::def; use middle::def_id::{CRATE_DEF_INDEX, DefId}; use middle::dependency_format::Linkage; use middle::stability; use middle::subst; use middle::ty::{self, Ty}; -use util::nodemap::{FnvHashMap, NodeMap, NodeSet}; + +use rustc::back::svh::Svh; +use rustc::front::map::{LinkedPath, PathElem, PathElems}; +use rustc::front::map as ast_map; +use rustc::session::config; +use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet}; use serialize::Encodable; use std::cell::RefCell; @@ -49,8 +51,6 @@ use rbml::writer::Encoder; use rustc_front::hir; use rustc_front::intravisit::Visitor; use rustc_front::intravisit; -use front::map::{LinkedPath, PathElem, PathElems}; -use front::map as ast_map; pub type EncodeInlinedItem<'a> = Box; diff --git a/src/librustc/metadata/index.rs b/src/librustc_metadata/index.rs similarity index 100% rename from src/librustc/metadata/index.rs rename to src/librustc_metadata/index.rs diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs new file mode 100644 index 0000000000000..6affbd2b5936c --- /dev/null +++ b/src/librustc_metadata/lib.rs @@ -0,0 +1,61 @@ +// Copyright 2015 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. + +#![cfg_attr(stage0, feature(custom_attribute))] +#![crate_name = "rustc_metadata"] +#![unstable(feature = "rustc_private", issue = "27812")] +#![cfg_attr(stage0, staged_api)] +#![crate_type = "dylib"] +#![crate_type = "rlib"] +#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "https://doc.rust-lang.org/favicon.ico", + html_root_url = "https://doc.rust-lang.org/nightly/")] + +#![feature(box_patterns)] +#![feature(duration_span)] +#![feature(enumset)] +#![feature(quote)] +#![feature(staged_api)] +#![feature(vec_push_all)] +#![feature(rustc_diagnostic_macros)] +#![feature(rustc_private)] + +#[macro_use] extern crate log; +#[macro_use] extern crate syntax; +#[macro_use] #[no_link] extern crate rustc_bitflags; + +extern crate flate; +extern crate rbml; +extern crate serialize; + +extern crate rustc; +extern crate rustc_back; +extern crate rustc_front; +extern crate rustc_llvm; + +pub use rustc::middle; + +#[macro_use] +mod macros; + +pub mod diagnostics; + +pub mod astencode; +pub mod common; +pub mod tyencode; +pub mod tydecode; +pub mod encoder; +pub mod decoder; +pub mod creader; +pub mod csearch; +pub mod cstore; +pub mod index; +pub mod loader; +pub mod macro_import; diff --git a/src/librustc/metadata/loader.rs b/src/librustc_metadata/loader.rs similarity index 98% rename from src/librustc/metadata/loader.rs rename to src/librustc_metadata/loader.rs index ca1562683efe7..72938a7660a53 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc_metadata/loader.rs @@ -212,19 +212,21 @@ //! no means all of the necessary details. Take a look at the rest of //! metadata::loader or metadata::creader for all the juicy details! -use back::svh::Svh; -use session::Session; -use session::search_paths::PathKind; -use llvm; -use llvm::{False, ObjectFile, mk_section_iter}; -use llvm::archive_ro::ArchiveRO; -use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive}; -use metadata::decoder; -use metadata::encoder; -use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch}; +use cstore::{MetadataBlob, MetadataVec, MetadataArchive}; +use decoder; +use encoder; + +use rustc::back::svh::Svh; +use rustc::session::Session; +use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch}; +use rustc::session::search_paths::PathKind; +use rustc::util::common; + +use rustc_llvm as llvm; +use rustc_llvm::{False, ObjectFile, mk_section_iter}; +use rustc_llvm::archive_ro::ArchiveRO; use syntax::codemap::Span; use syntax::diagnostic::SpanHandler; -use util::common; use rustc_back::target::Target; use std::cmp; diff --git a/src/librustc/metadata/macro_import.rs b/src/librustc_metadata/macro_import.rs similarity index 98% rename from src/librustc/metadata/macro_import.rs rename to src/librustc_metadata/macro_import.rs index b08f5d0640eb3..d67fc3a0eaba5 100644 --- a/src/librustc/metadata/macro_import.rs +++ b/src/librustc_metadata/macro_import.rs @@ -10,9 +10,10 @@ //! Used by `rustc` when loading a crate with exported macros. -use session::Session; -use metadata::creader::CrateReader; -use metadata::cstore::CStore; +use creader::CrateReader; +use cstore::CStore; + +use rustc::session::Session; use std::collections::{HashSet, HashMap}; use syntax::codemap::Span; diff --git a/src/librustc_metadata/macros.rs b/src/librustc_metadata/macros.rs new file mode 100644 index 0000000000000..ed764ebd9f95d --- /dev/null +++ b/src/librustc_metadata/macros.rs @@ -0,0 +1,46 @@ +// Copyright 2015 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. + +macro_rules! enum_from_u32 { + ($(#[$attr:meta])* pub enum $name:ident { + $($variant:ident = $e:expr,)* + }) => { + $(#[$attr])* + pub enum $name { + $($variant = $e),* + } + + impl $name { + pub fn from_u32(u: u32) -> Option<$name> { + $(if u == $name::$variant as u32 { + return Some($name::$variant) + })* + None + } + } + }; + ($(#[$attr:meta])* pub enum $name:ident { + $($variant:ident,)* + }) => { + $(#[$attr])* + pub enum $name { + $($variant,)* + } + + impl $name { + pub fn from_u32(u: u32) -> Option<$name> { + $(if u == $name::$variant as u32 { + return Some($name::$variant) + })* + None + } + } + } +} diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc_metadata/tydecode.rs similarity index 100% rename from src/librustc/metadata/tydecode.rs rename to src/librustc_metadata/tydecode.rs diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc_metadata/tyencode.rs similarity index 99% rename from src/librustc/metadata/tyencode.rs rename to src/librustc_metadata/tyencode.rs index 1b993a00e2844..bc1edd5c76718 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc_metadata/tyencode.rs @@ -23,7 +23,7 @@ use middle::subst; use middle::subst::VecPerParamSpace; use middle::ty::ParamTy; use middle::ty::{self, Ty}; -use util::nodemap::FnvHashMap; +use rustc::util::nodemap::FnvHashMap; use rustc_front::hir; diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index 33d63d833c7fa..5dedef7ab6c79 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -71,6 +71,7 @@ extern crate rustc; extern crate rustc_front; +extern crate rustc_metadata; pub use self::registry::Registry; diff --git a/src/librustc_plugin/load.rs b/src/librustc_plugin/load.rs index d121a306c61c7..51eec07505a42 100644 --- a/src/librustc_plugin/load.rs +++ b/src/librustc_plugin/load.rs @@ -11,8 +11,8 @@ //! Used by `rustc` when loading a plugin. use rustc::session::Session; -use rustc::metadata::creader::CrateReader; -use rustc::metadata::cstore::CStore; +use rustc_metadata::creader::CrateReader; +use rustc_metadata::cstore::CStore; use registry::Registry; use std::borrow::ToOwned; diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 752e7e55f5505..13f7e3181631a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -28,7 +28,7 @@ use {resolve_error, ResolutionError}; use self::DuplicateCheckingMode::*; -use rustc::metadata::util::{CrateStore, ChildItem, DlDef, DlField, DlImpl}; +use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl}; use rustc::middle::def::*; use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId}; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6bfe9cd393e71..ef03ac520df46 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -54,7 +54,7 @@ use self::FallbackChecks::*; use rustc::front::map as hir_map; use rustc::session::Session; use rustc::lint; -use rustc::metadata::util::{CrateStore, DefLike, DlDef}; +use rustc::middle::cstore::{CrateStore, DefLike, DlDef}; use rustc::middle::def::*; use rustc::middle::def_id::DefId; use rustc::middle::pat_util::pat_bindings_hygienic; diff --git a/src/librustc_trans/back/archive.rs b/src/librustc_trans/back/archive.rs index d7f9002a4f456..f5431554a7564 100644 --- a/src/librustc_trans/back/archive.rs +++ b/src/librustc_trans/back/archive.rs @@ -21,7 +21,7 @@ use std::process::{Command, Output, Stdio}; use std::ptr; use std::str; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use libc; use llvm::archive_ro::{ArchiveRO, Child}; diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index cefe04f5e35eb..d7b4243afee21 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -17,12 +17,11 @@ use super::svh::Svh; use session::config; use session::config::NoDebugInfo; use session::config::{OutputFilenames, Input, OutputType}; +use session::filesearch; use session::search_paths::PathKind; use session::Session; -use metadata::{util as mdutil}; -use metadata::filesearch; -use metadata::util::{CrateStore, LinkMeta}; -use metadata::util::{LinkagePreference, NativeLibraryKind}; +use middle::cstore::{self, CrateStore, LinkMeta}; +use middle::cstore::{LinkagePreference, NativeLibraryKind}; use middle::dependency_format::Linkage; use middle::ty::{self, Ty}; use rustc::front::map::DefPath; @@ -138,7 +137,7 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input: &Input) -> String { let validate = |s: String, span: Option| { - mdutil::validate_crate_name(sess, &s[..], span); + cstore::validate_crate_name(sess, &s[..], span); s }; diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs index 8235df581c836..1ee1c9f1912c7 100644 --- a/src/librustc_trans/back/linker.rs +++ b/src/librustc_trans/back/linker.rs @@ -16,7 +16,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use back::archive; -use metadata::util::CrateStore; +use middle::cstore::CrateStore; use middle::dependency_format::Linkage; use session::Session; use session::config::CrateTypeDylib; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 67a7f3efb2771..b672c49bdca7e 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -62,7 +62,6 @@ extern crate serialize; #[macro_use] extern crate syntax; pub use rustc::session; -pub use rustc::metadata; pub use rustc::middle; pub use rustc::lint; pub use rustc::util; diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 34eb1d282636e..a95a4c052fa2e 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -13,7 +13,7 @@ pub use self::Row::*; use super::escape; use super::span_utils::SpanUtils; -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def_id::{CRATE_DEF_INDEX, DefId}; use middle::ty; diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 30ec1e662b028..d6b33672df0a7 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -35,6 +35,7 @@ use lint; use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param}; use llvm; use middle::cfg; +use middle::cstore::CrateStore; use middle::def_id::DefId; use middle::infer; use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem}; @@ -42,7 +43,6 @@ use middle::weak_lang_items; use middle::pat_util::simple_name; use middle::subst::Substs; use middle::ty::{self, Ty, HasTypeFlags}; -use metadata::util::CrateStore; use rustc::front::map as hir_map; use rustc_mir::mir_map::MirMap; use session::config::{self, NoDebugInfo, FullDebugInfo}; diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index a52c7f94c3a81..0c0bda45d8cd9 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -22,7 +22,7 @@ use arena::TypedArena; use back::link; use session; use llvm::{self, ValueRef, get_params}; -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def; use middle::def_id::DefId; use middle::infer; diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 91f17a50e2c41..6f40283064bd0 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -13,8 +13,8 @@ use back::abi; use llvm; use llvm::{ConstFCmp, ConstICmp, SetLinkage, SetUnnamedAddr}; use llvm::{InternalLinkage, ValueRef, Bool, True}; -use metadata::cstore::LOCAL_CRATE; use middle::{check_const, def}; +use middle::cstore::LOCAL_CRATE; use middle::const_eval::{self, ConstVal, ConstEvalErr}; use middle::const_eval::{const_int_checked_neg, const_uint_checked_neg}; use middle::const_eval::{const_int_checked_add, const_uint_checked_add}; diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index 1f1d43feeb38e..c6ca2e176aa58 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -10,7 +10,7 @@ use llvm; use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef}; -use metadata::common::LinkMeta; +use middle::cstore::LinkMeta; use middle::def::ExportMap; use middle::def_id::DefId; use middle::traits; diff --git a/src/librustc_trans/trans/inline.rs b/src/librustc_trans/trans/inline.rs index 5be4892484b53..29965755eac76 100644 --- a/src/librustc_trans/trans/inline.rs +++ b/src/librustc_trans/trans/inline.rs @@ -9,7 +9,7 @@ // except according to those terms. use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage}; -use metadata::util::{CrateStore, FoundAst, InlinedItem}; +use middle::cstore::{CrateStore, FoundAst, InlinedItem}; use middle::def_id::DefId; use middle::subst::Substs; use trans::base::{push_ctxt, trans_item, get_item_val, trans_fn}; diff --git a/src/librustc_trans/trans/mod.rs b/src/librustc_trans/trans/mod.rs index fa37b00553982..b102e96af20e2 100644 --- a/src/librustc_trans/trans/mod.rs +++ b/src/librustc_trans/trans/mod.rs @@ -9,7 +9,7 @@ // except according to those terms. use llvm::{ContextRef, ModuleRef}; -use metadata::common::LinkMeta; +use middle::cstore::LinkMeta; pub use self::base::trans_crate; pub use self::context::CrateContext; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 988d5537e5db7..6a23be682e9d3 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -25,7 +25,7 @@ use super::UnresolvedTypeAction; use super::write_call; use CrateCtxt; -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def_id::DefId; use middle::infer; use middle::ty::{self, LvaluePreference, Ty}; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index f4f4dc90feb9d..955bc92a8f31e 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -17,12 +17,12 @@ use astconv::AstConv; use check::{self, FnCtxt}; use front::map as hir_map; use middle::ty::{self, Ty, ToPolyTraitRef, ToPredicate, HasTypeFlags}; +use middle::cstore::{self, CrateStore, DefLike}; use middle::def; use middle::def_id::DefId; use middle::lang_items::FnOnceTraitLangItem; use middle::subst::Substs; use middle::traits::{Obligation, SelectionContext}; -use metadata::util::{self as mdutil, CrateStore, DefLike}; use util::nodemap::{FnvHashSet}; use syntax::ast; @@ -418,13 +418,13 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> { fn handle_external_def(traits: &mut AllTraitsVec, external_mods: &mut FnvHashSet, ccx: &CrateCtxt, - cstore: &for<'a> mdutil::CrateStore<'a>, - dl: mdutil::DefLike) { + cstore: &for<'a> cstore::CrateStore<'a>, + dl: cstore::DefLike) { match dl { - mdutil::DlDef(def::DefTrait(did)) => { + cstore::DlDef(def::DefTrait(did)) => { traits.push(TraitInfo::new(did)); } - mdutil::DlDef(def::DefMod(did)) => { + cstore::DlDef(def::DefMod(did)) => { if !external_mods.insert(did) { return; } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c375eb19a3733..be60d2f3dcf8e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -83,8 +83,8 @@ use self::TupleArgumentsFlag::*; use astconv::{self, ast_region_to_region, ast_ty_to_ty, AstConv, PathParamMode}; use check::_match::pat_ctxt; use fmt_macros::{Parser, Piece, Position}; -use metadata::cstore::LOCAL_CRATE; use middle::astconv_util::prohibit_type_params; +use middle::cstore::LOCAL_CRATE; use middle::def; use middle::def_id::DefId; use middle::infer; diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 8eeafb9b432a8..e6e31ba0819c5 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -11,7 +11,7 @@ //! Orphan checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. -use metadata::cstore::LOCAL_CRATE; +use middle::cstore::LOCAL_CRATE; use middle::def_id::DefId; use middle::traits; use middle::ty; diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index 6a50ceba2f033..693c8716ab58a 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -11,8 +11,7 @@ //! Overlap: No two impls for the same trait are implemented for the //! same type. -use metadata::cstore::LOCAL_CRATE; -use metadata::util::CrateStore; +use middle::cstore::{CrateStore, LOCAL_CRATE}; use middle::def_id::DefId; use middle::traits; use middle::ty; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 3d28a912179ae..4c09df418950b 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -99,7 +99,6 @@ extern crate rustc_back; pub use rustc::front; pub use rustc::lint; -pub use rustc::metadata; pub use rustc::middle; pub use rustc::session; pub use rustc::util;