1
Fork 0

Rollup merge of #58255 - taiki-e:librustc_metadata-2018, r=Centril

librustc_metadata => 2018

Transitions `librustc_metadata` to Rust 2018; cc #58099

r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2019-02-09 00:15:55 +01:00 committed by GitHub
commit 8cbee1c68e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 67 additions and 66 deletions

View file

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"] authors = ["The Rust Project Developers"]
name = "rustc_metadata" name = "rustc_metadata"
version = "0.0.0" version = "0.0.0"
edition = "2018"
[lib] [lib]
name = "rustc_metadata" name = "rustc_metadata"
@ -14,7 +15,7 @@ log = "0.4"
memmap = "0.6" memmap = "0.6"
rustc = { path = "../librustc" } rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" } rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" } errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_target = { path = "../librustc_target" } rustc_target = { path = "../librustc_target" }
serialize = { path = "../libserialize" } serialize = { path = "../libserialize" }
stable_deref_trait = "1.0.0" stable_deref_trait = "1.0.0"

View file

@ -1,9 +1,9 @@
//! Validates all used crates and extern libraries and loads their metadata //! Validates all used crates and extern libraries and loads their metadata
use cstore::{self, CStore, CrateSource, MetadataBlob}; use crate::cstore::{self, CStore, CrateSource, MetadataBlob};
use locator::{self, CratePaths}; use crate::locator::{self, CratePaths};
use decoder::proc_macro_def_path_table; use crate::decoder::proc_macro_def_path_table;
use schema::CrateRoot; use crate::schema::CrateRoot;
use rustc_data_structures::sync::{Lrc, RwLock, Lock}; use rustc_data_structures::sync::{Lrc, RwLock, Lock};
use rustc::hir::def_id::CrateNum; use rustc::hir::def_id::CrateNum;
@ -29,8 +29,9 @@ use syntax::attr;
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::visit; use syntax::visit;
use syntax::{span_err, span_fatal};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
use log; use log::{debug, info, log_enabled};
pub struct Library { pub struct Library {
pub dylib: Option<(PathBuf, PathKind)>, pub dylib: Option<(PathBuf, PathKind)>,
@ -342,7 +343,7 @@ impl<'a> CrateLoader<'a> {
} }
} }
fn load(&mut self, locate_ctxt: &mut locator::Context) -> Option<LoadResult> { fn load(&mut self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
let library = locate_ctxt.maybe_load_library_crate()?; let library = locate_ctxt.maybe_load_library_crate()?;
// In the case that we're loading a crate, but not matching // In the case that we're loading a crate, but not matching
@ -427,7 +428,7 @@ impl<'a> CrateLoader<'a> {
// The map from crate numbers in the crate we're resolving to local crate numbers. // The map from crate numbers in the crate we're resolving to local crate numbers.
// We map 0 and all other holes in the map to our parent crate. The "additional" // We map 0 and all other holes in the map to our parent crate. The "additional"
// self-dependencies should be harmless. // self-dependencies should be harmless.
::std::iter::once(krate).chain(crate_root.crate_deps std::iter::once(krate).chain(crate_root.crate_deps
.decode(metadata) .decode(metadata)
.map(|dep| { .map(|dep| {
info!("resolving dep crate {} hash: `{}` extra filename: `{}`", dep.name, dep.hash, info!("resolving dep crate {} hash: `{}` extra filename: `{}`", dep.name, dep.hash,
@ -522,7 +523,7 @@ impl<'a> CrateLoader<'a> {
fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span) fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span)
-> Vec<(ast::Name, Lrc<SyntaxExtension>)> { -> Vec<(ast::Name, Lrc<SyntaxExtension>)> {
use std::{env, mem}; use std::{env, mem};
use dynamic_lib::DynamicLibrary; use crate::dynamic_lib::DynamicLibrary;
use proc_macro::bridge::client::ProcMacro; use proc_macro::bridge::client::ProcMacro;
use syntax_ext::deriving::custom::ProcMacroDerive; use syntax_ext::deriving::custom::ProcMacroDerive;
use syntax_ext::proc_macro_impl::{AttrProcMacro, BangProcMacro}; use syntax_ext::proc_macro_impl::{AttrProcMacro, BangProcMacro};
@ -996,7 +997,7 @@ impl<'a> CrateLoader<'a> {
item.ident, orig_name); item.ident, orig_name);
let orig_name = match orig_name { let orig_name = match orig_name {
Some(orig_name) => { Some(orig_name) => {
::validate_crate_name(Some(self.sess), &orig_name.as_str(), crate::validate_crate_name(Some(self.sess), &orig_name.as_str(),
Some(item.span)); Some(item.span));
orig_name orig_name
} }

View file

@ -1,7 +1,7 @@
// The crate store - a central repo for information collected about external // The crate store - a central repo for information collected about external
// crates and libraries // crates and libraries
use schema; use crate::schema;
use rustc::hir::def_id::{CrateNum, DefIndex}; use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable; use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader}; use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
@ -19,7 +19,7 @@ pub use rustc::middle::cstore::{NativeLibrary, NativeLibraryKind, LinkagePrefere
pub use rustc::middle::cstore::NativeLibraryKind::*; pub use rustc::middle::cstore::NativeLibraryKind::*;
pub use rustc::middle::cstore::{CrateSource, LibSource, ForeignModule}; pub use rustc::middle::cstore::{CrateSource, LibSource, ForeignModule};
pub use cstore_impl::{provide, provide_extern}; pub use crate::cstore_impl::{provide, provide_extern};
// A map from external crate numbers (as decoded from some crate file) to // A map from external crate numbers (as decoded from some crate file) to
// local crate numbers (as generated during this session). Each external // local crate numbers (as generated during this session). Each external

View file

@ -1,9 +1,9 @@
use cstore::{self, LoadedMacro}; use crate::cstore::{self, LoadedMacro};
use encoder; use crate::encoder;
use link_args; use crate::link_args;
use native_libs; use crate::native_libs;
use foreign_modules; use crate::foreign_modules;
use schema; use crate::schema;
use rustc::ty::query::QueryConfig; use rustc::ty::query::QueryConfig;
use rustc::middle::cstore::{CrateStore, DepKind, use rustc::middle::cstore::{CrateStore, DepKind,
@ -51,7 +51,7 @@ macro_rules! provide {
index: CRATE_DEF_INDEX index: CRATE_DEF_INDEX
}); });
let dep_node = def_path_hash let dep_node = def_path_hash
.to_dep_node(::rustc::dep_graph::DepKind::CrateMetadata); .to_dep_node(rustc::dep_graph::DepKind::CrateMetadata);
// The DepNodeIndex of the DepNode::CrateMetadata should be // The DepNodeIndex of the DepNode::CrateMetadata should be
// cached somewhere, so that we can use read_index(). // cached somewhere, so that we can use read_index().
$tcx.dep_graph.read(dep_node); $tcx.dep_graph.read(dep_node);
@ -421,7 +421,7 @@ impl cstore::CStore {
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax_ext::proc_macro_impl::BangProcMacro; use syntax_ext::proc_macro_impl::BangProcMacro;
let client = ::proc_macro::bridge::client::Client::expand1(::proc_macro::quote); let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let ext = SyntaxExtension::ProcMacro { let ext = SyntaxExtension::ProcMacro {
expander: Box::new(BangProcMacro { client }), expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: true, allow_internal_unstable: true,

View file

@ -1,7 +1,7 @@
// Decoding metadata from a single crate's metadata // Decoding metadata from a single crate's metadata
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule}; use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use schema::*; use crate::schema::*;
use rustc_data_structures::sync::{Lrc, ReadGuard}; use rustc_data_structures::sync::{Lrc, ReadGuard};
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, Definitions}; use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, Definitions};
@ -34,6 +34,7 @@ use syntax::symbol::InternedString;
use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::hygiene::Mark; use syntax::ext::hygiene::Mark;
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION}; use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
use log::debug;
pub struct DecodeContext<'a, 'tcx: 'a> { pub struct DecodeContext<'a, 'tcx: 'a> {
opaque: opaque::Decoder<'a>, opaque: opaque::Decoder<'a>,
@ -545,7 +546,7 @@ impl<'a, 'tcx> CrateMetadata {
fn get_variant(&self, fn get_variant(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
item: &Entry, item: &Entry<'_>,
index: DefIndex, index: DefIndex,
adt_kind: ty::AdtKind) adt_kind: ty::AdtKind)
-> ty::VariantDef -> ty::VariantDef

View file

@ -1,5 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
register_long_diagnostics! { register_long_diagnostics! {
E0454: r##" E0454: r##"
A link name was given with an empty name. Erroneous code example: A link name was given with an empty name. Erroneous code example:

View file

@ -76,7 +76,6 @@ impl DynamicLibrary {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use libc;
use std::mem; use std::mem;
#[test] #[test]
@ -127,7 +126,6 @@ mod tests {
#[cfg(unix)] #[cfg(unix)]
mod dl { mod dl {
use libc;
use std::ffi::{CStr, OsStr, CString}; use std::ffi::{CStr, OsStr, CString};
use std::os::unix::prelude::*; use std::os::unix::prelude::*;
use std::ptr; use std::ptr;

View file

@ -1,7 +1,7 @@
use index::Index; use crate::index::Index;
use index_builder::{FromId, IndexBuilder, Untracked}; use crate::index_builder::{FromId, IndexBuilder, Untracked};
use isolated_encoder::IsolatedEncoder; use crate::isolated_encoder::IsolatedEncoder;
use schema::*; use crate::schema::*;
use rustc::middle::cstore::{LinkagePreference, NativeLibrary, use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
EncodedMetadata, ForeignModule}; EncodedMetadata, ForeignModule};
@ -34,6 +34,7 @@ use syntax::attr;
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
use syntax::symbol::keywords; use syntax::symbol::keywords;
use syntax_pos::{self, hygiene, FileName, SourceFile, Span}; use syntax_pos::{self, hygiene, FileName, SourceFile, Span};
use log::{debug, trace};
use rustc::hir::{self, PatKind}; use rustc::hir::{self, PatKind};
use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::itemlikevisit::ItemLikeVisitor;
@ -1521,7 +1522,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
// symbol associated with them (they weren't translated) or if they're an FFI // symbol associated with them (they weren't translated) or if they're an FFI
// definition (as that's not defined in this crate). // definition (as that's not defined in this crate).
fn encode_exported_symbols(&mut self, fn encode_exported_symbols(&mut self,
exported_symbols: &[(ExportedSymbol, SymbolExportLevel)]) exported_symbols: &[(ExportedSymbol<'_>, SymbolExportLevel)])
-> EncodedExportedSymbols { -> EncodedExportedSymbols {
// The metadata symbol name is special. It should not show up in // The metadata symbol name is special. It should not show up in
// downstream crates. // downstream crates.

View file

@ -1,9 +1,10 @@
use schema::*; use crate::schema::*;
use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace}; use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
use rustc_serialize::opaque::Encoder; use rustc_serialize::opaque::Encoder;
use std::slice; use std::slice;
use std::u32; use std::u32;
use log::debug;
/// While we are generating the metadata, we also track the position /// While we are generating the metadata, we also track the position
/// of each DefIndex. It is not required that all definitions appear /// of each DefIndex. It is not required that all definitions appear
@ -24,12 +25,12 @@ impl Index {
} }
} }
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry>) { pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'_>>) {
assert!(def_id.is_local()); assert!(def_id.is_local());
self.record_index(def_id.index, entry); self.record_index(def_id.index, entry);
} }
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry>) { pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
assert!(entry.position < (u32::MAX as usize)); assert!(entry.position < (u32::MAX as usize));
let position = entry.position as u32; let position = entry.position as u32;
let space_index = item.address_space().index(); let space_index = item.address_space().index();

View file

@ -45,10 +45,10 @@
//! give a callback fn, rather than taking a closure: it allows us to //! give a callback fn, rather than taking a closure: it allows us to
//! easily control precisely what data is given to that fn. //! easily control precisely what data is given to that fn.
use encoder::EncodeContext; use crate::encoder::EncodeContext;
use index::Index; use crate::index::Index;
use schema::*; use crate::schema::*;
use isolated_encoder::IsolatedEncoder; use crate::isolated_encoder::IsolatedEncoder;
use rustc::hir; use rustc::hir;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
@ -133,21 +133,21 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
/// `DefId` index, or implement the `read` method so that it can add /// `DefId` index, or implement the `read` method so that it can add
/// a read of whatever dep-graph nodes are appropriate. /// a read of whatever dep-graph nodes are appropriate.
pub trait DepGraphRead { pub trait DepGraphRead {
fn read(&self, tcx: TyCtxt); fn read(&self, tcx: TyCtxt<'_, '_, '_>);
} }
impl DepGraphRead for DefId { impl DepGraphRead for DefId {
fn read(&self, _tcx: TyCtxt) {} fn read(&self, _tcx: TyCtxt<'_, '_, '_>) {}
} }
impl DepGraphRead for ast::NodeId { impl DepGraphRead for ast::NodeId {
fn read(&self, _tcx: TyCtxt) {} fn read(&self, _tcx: TyCtxt<'_, '_, '_>) {}
} }
impl<T> DepGraphRead for Option<T> impl<T> DepGraphRead for Option<T>
where T: DepGraphRead where T: DepGraphRead
{ {
fn read(&self, tcx: TyCtxt) { fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
match *self { match *self {
Some(ref v) => v.read(tcx), Some(ref v) => v.read(tcx),
None => (), None => (),
@ -158,7 +158,7 @@ impl<T> DepGraphRead for Option<T>
impl<T> DepGraphRead for [T] impl<T> DepGraphRead for [T]
where T: DepGraphRead where T: DepGraphRead
{ {
fn read(&self, tcx: TyCtxt) { fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
for i in self { for i in self {
i.read(tcx); i.read(tcx);
} }
@ -171,7 +171,7 @@ macro_rules! read_tuple {
where $($name: DepGraphRead),* where $($name: DepGraphRead),*
{ {
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn read(&self, tcx: TyCtxt) { fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
let &($(ref $name),*) = self; let &($(ref $name),*) = self;
$($name.read(tcx);)* $($name.read(tcx);)*
} }
@ -184,7 +184,7 @@ read_tuple!(A, B, C);
macro_rules! read_hir { macro_rules! read_hir {
($t:ty) => { ($t:ty) => {
impl<'tcx> DepGraphRead for &'tcx $t { impl<'tcx> DepGraphRead for &'tcx $t {
fn read(&self, tcx: TyCtxt) { fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
tcx.hir().read(self.id); tcx.hir().read(self.id);
} }
} }
@ -208,7 +208,7 @@ read_hir!(hir::MacroDef);
pub struct Untracked<T>(pub T); pub struct Untracked<T>(pub T);
impl<T> DepGraphRead for Untracked<T> { impl<T> DepGraphRead for Untracked<T> {
fn read(&self, _tcx: TyCtxt) {} fn read(&self, _tcx: TyCtxt<'_, '_, '_>) {}
} }
/// Newtype that can be used to package up misc data extracted from a /// Newtype that can be used to package up misc data extracted from a
@ -218,7 +218,7 @@ impl<T> DepGraphRead for Untracked<T> {
pub struct FromId<T>(pub ast::NodeId, pub T); pub struct FromId<T>(pub ast::NodeId, pub T);
impl<T> DepGraphRead for FromId<T> { impl<T> DepGraphRead for FromId<T> {
fn read(&self, tcx: TyCtxt) { fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
tcx.hir().read(self.0); tcx.hir().read(self.0);
} }
} }

View file

@ -1,5 +1,5 @@
use encoder::EncodeContext; use crate::encoder::EncodeContext;
use schema::{Lazy, LazySeq}; use crate::schema::{Lazy, LazySeq};
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use rustc_serialize::Encodable; use rustc_serialize::Encodable;

View file

@ -13,23 +13,15 @@
#![recursion_limit="256"] #![recursion_limit="256"]
#![deny(rust_2018_idioms)]
extern crate libc; extern crate libc;
#[macro_use] #[allow(unused_extern_crates)]
extern crate log;
extern crate memmap;
extern crate stable_deref_trait;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate flate2;
extern crate serialize as rustc_serialize; // used by deriving extern crate serialize as rustc_serialize; // used by deriving
extern crate rustc_errors as errors;
extern crate syntax_ext;
extern crate proc_macro; extern crate proc_macro;
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
extern crate rustc_target;
#[macro_use] #[macro_use]
extern crate rustc_data_structures; extern crate rustc_data_structures;

View file

@ -212,9 +212,9 @@
//! no means all of the necessary details. Take a look at the rest of //! no means all of the necessary details. Take a look at the rest of
//! metadata::locator or metadata::creader for all the juicy details! //! metadata::locator or metadata::creader for all the juicy details!
use cstore::{MetadataRef, MetadataBlob}; use crate::cstore::{MetadataRef, MetadataBlob};
use creader::Library; use crate::creader::Library;
use schema::{METADATA_HEADER, rustc_version}; use crate::schema::{METADATA_HEADER, rustc_version};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
@ -226,6 +226,7 @@ use rustc::util::nodemap::FxHashMap;
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::struct_span_err;
use syntax_pos::Span; use syntax_pos::Span;
use rustc_target::spec::{Target, TargetTriple}; use rustc_target::spec::{Target, TargetTriple};
@ -241,6 +242,8 @@ use flate2::read::DeflateDecoder;
use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::owning_ref::OwningRef;
use log::{debug, info, warn};
pub struct CrateMismatch { pub struct CrateMismatch {
path: PathBuf, path: PathBuf,
got: String, got: String,
@ -283,7 +286,7 @@ enum CrateFlavor {
} }
impl fmt::Display for CrateFlavor { impl fmt::Display for CrateFlavor {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match *self { f.write_str(match *self {
CrateFlavor::Rlib => "rlib", CrateFlavor::Rlib => "rlib",
CrateFlavor::Rmeta => "rmeta", CrateFlavor::Rmeta => "rmeta",
@ -600,7 +603,7 @@ impl<'a> Context<'a> {
} }
} }
let mut err: Option<DiagnosticBuilder> = None; let mut err: Option<DiagnosticBuilder<'_>> = None;
for (lib, kind) in m { for (lib, kind) in m {
info!("{} reading metadata from: {}", flavor, lib.display()); info!("{} reading metadata from: {}", flavor, lib.display());
let (hash, metadata) = let (hash, metadata) =

View file

@ -9,6 +9,7 @@ use syntax::attr;
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax::feature_gate::{self, GateIssue}; use syntax::feature_gate::{self, GateIssue};
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::{span_err, struct_span_err};
pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<NativeLibrary> { pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<NativeLibrary> {
let mut collector = Collector { let mut collector = Collector {

View file

@ -1,4 +1,4 @@
use index; use crate::index;
use rustc::hir; use rustc::hir;
use rustc::hir::def::{self, CtorKind}; use rustc::hir::def::{self, CtorKind};
@ -518,7 +518,7 @@ pub enum AssociatedContainer {
ImplFinal, ImplFinal,
} }
impl_stable_hash_for!(enum ::schema::AssociatedContainer { impl_stable_hash_for!(enum crate::schema::AssociatedContainer {
TraitRequired, TraitRequired,
TraitWithDefault, TraitWithDefault,
ImplDefault, ImplDefault,