Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc_metadata => 2018 #58255

Merged
merged 1 commit into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_metadata"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_metadata"
Expand All @@ -14,7 +15,7 @@ log = "0.4"
memmap = "0.6"
rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_target = { path = "../librustc_target" }
serialize = { path = "../libserialize" }
stable_deref_trait = "1.0.0"
Expand Down
19 changes: 10 additions & 9 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Validates all used crates and extern libraries and loads their metadata

use cstore::{self, CStore, CrateSource, MetadataBlob};
use locator::{self, CratePaths};
use decoder::proc_macro_def_path_table;
use schema::CrateRoot;
use crate::cstore::{self, CStore, CrateSource, MetadataBlob};
use crate::locator::{self, CratePaths};
use crate::decoder::proc_macro_def_path_table;
use crate::schema::CrateRoot;
use rustc_data_structures::sync::{Lrc, RwLock, Lock};

use rustc::hir::def_id::CrateNum;
Expand All @@ -29,8 +29,9 @@ use syntax::attr;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
use syntax::visit;
use syntax::{span_err, span_fatal};
use syntax_pos::{Span, DUMMY_SP};
use log;
use log::{debug, info, log_enabled};

pub struct Library {
pub dylib: Option<(PathBuf, PathKind)>,
Expand Down Expand Up @@ -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()?;

// In the case that we're loading a crate, but not matching
Expand Down Expand Up @@ -427,7 +428,7 @@ impl<'a> CrateLoader<'a> {
// 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"
// 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)
.map(|dep| {
info!("resolving dep crate {} hash: `{}` extra filename: `{}`", dep.name, dep.hash,
Expand Down Expand Up @@ -522,7 +523,7 @@ impl<'a> CrateLoader<'a> {
fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span)
-> Vec<(ast::Name, Lrc<SyntaxExtension>)> {
use std::{env, mem};
use dynamic_lib::DynamicLibrary;
use crate::dynamic_lib::DynamicLibrary;
use proc_macro::bridge::client::ProcMacro;
use syntax_ext::deriving::custom::ProcMacroDerive;
use syntax_ext::proc_macro_impl::{AttrProcMacro, BangProcMacro};
Expand Down Expand Up @@ -996,7 +997,7 @@ impl<'a> CrateLoader<'a> {
item.ident, orig_name);
let orig_name = match 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));
orig_name
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The crate store - a central repo for information collected about external
// crates and libraries

use schema;
use crate::schema;
use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
Expand All @@ -19,7 +19,7 @@ pub use rustc::middle::cstore::{NativeLibrary, NativeLibraryKind, LinkagePrefere
pub use rustc::middle::cstore::NativeLibraryKind::*;
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
// local crate numbers (as generated during this session). Each external
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cstore::{self, LoadedMacro};
use encoder;
use link_args;
use native_libs;
use foreign_modules;
use schema;
use crate::cstore::{self, LoadedMacro};
use crate::encoder;
use crate::link_args;
use crate::native_libs;
use crate::foreign_modules;
use crate::schema;

use rustc::ty::query::QueryConfig;
use rustc::middle::cstore::{CrateStore, DepKind,
Expand Down Expand Up @@ -51,7 +51,7 @@ macro_rules! provide {
index: CRATE_DEF_INDEX
});
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
// cached somewhere, so that we can use read_index().
$tcx.dep_graph.read(dep_node);
Expand Down Expand Up @@ -421,7 +421,7 @@ impl cstore::CStore {
use syntax::ext::base::SyntaxExtension;
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 {
expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: true,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Decoding metadata from a single crate's metadata

use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use schema::*;
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use crate::schema::*;

use rustc_data_structures::sync::{Lrc, ReadGuard};
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, Definitions};
Expand Down Expand Up @@ -34,6 +34,7 @@ use syntax::symbol::InternedString;
use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::hygiene::Mark;
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
use log::debug;

pub struct DecodeContext<'a, 'tcx: 'a> {
opaque: opaque::Decoder<'a>,
Expand Down Expand Up @@ -545,7 +546,7 @@ impl<'a, 'tcx> CrateMetadata {

fn get_variant(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item: &Entry,
item: &Entry<'_>,
index: DefIndex,
adt_kind: ty::AdtKind)
-> ty::VariantDef
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_metadata/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(non_snake_case)]

use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};

register_long_diagnostics! {
E0454: r##"
A link name was given with an empty name. Erroneous code example:
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_metadata/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl DynamicLibrary {
#[cfg(test)]
mod tests {
use super::*;
use libc;
use std::mem;

#[test]
Expand Down Expand Up @@ -127,7 +126,6 @@ mod tests {

#[cfg(unix)]
mod dl {
use libc;
use std::ffi::{CStr, OsStr, CString};
use std::os::unix::prelude::*;
use std::ptr;
Expand Down
11 changes: 6 additions & 5 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use index::Index;
use index_builder::{FromId, IndexBuilder, Untracked};
use isolated_encoder::IsolatedEncoder;
use schema::*;
use crate::index::Index;
use crate::index_builder::{FromId, IndexBuilder, Untracked};
use crate::isolated_encoder::IsolatedEncoder;
use crate::schema::*;

use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
EncodedMetadata, ForeignModule};
Expand Down Expand Up @@ -34,6 +34,7 @@ use syntax::attr;
use syntax::source_map::Spanned;
use syntax::symbol::keywords;
use syntax_pos::{self, hygiene, FileName, SourceFile, Span};
use log::{debug, trace};

use rustc::hir::{self, PatKind};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
Expand Down Expand Up @@ -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
// definition (as that's not defined in this crate).
fn encode_exported_symbols(&mut self,
exported_symbols: &[(ExportedSymbol, SymbolExportLevel)])
exported_symbols: &[(ExportedSymbol<'_>, SymbolExportLevel)])
-> EncodedExportedSymbols {
// The metadata symbol name is special. It should not show up in
// downstream crates.
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_metadata/index.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use schema::*;
use crate::schema::*;

use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
use rustc_serialize::opaque::Encoder;
use std::slice;
use std::u32;
use log::debug;

/// While we are generating the metadata, we also track the position
/// of each DefIndex. It is not required that all definitions appear
Expand All @@ -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());
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));
let position = entry.position as u32;
let space_index = item.address_space().index();
Expand Down
26 changes: 13 additions & 13 deletions src/librustc_metadata/index_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
//! give a callback fn, rather than taking a closure: it allows us to
//! easily control precisely what data is given to that fn.

use encoder::EncodeContext;
use index::Index;
use schema::*;
use isolated_encoder::IsolatedEncoder;
use crate::encoder::EncodeContext;
use crate::index::Index;
use crate::schema::*;
use crate::isolated_encoder::IsolatedEncoder;

use rustc::hir;
use rustc::hir::def_id::DefId;
Expand Down Expand Up @@ -133,21 +133,21 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
/// `DefId` index, or implement the `read` method so that it can add
/// a read of whatever dep-graph nodes are appropriate.
pub trait DepGraphRead {
fn read(&self, tcx: TyCtxt);
fn read(&self, tcx: TyCtxt<'_, '_, '_>);
}

impl DepGraphRead for DefId {
fn read(&self, _tcx: TyCtxt) {}
fn read(&self, _tcx: TyCtxt<'_, '_, '_>) {}
}

impl DepGraphRead for ast::NodeId {
fn read(&self, _tcx: TyCtxt) {}
fn read(&self, _tcx: TyCtxt<'_, '_, '_>) {}
}

impl<T> DepGraphRead for Option<T>
where T: DepGraphRead
{
fn read(&self, tcx: TyCtxt) {
fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
match *self {
Some(ref v) => v.read(tcx),
None => (),
Expand All @@ -158,7 +158,7 @@ impl<T> DepGraphRead for Option<T>
impl<T> DepGraphRead for [T]
where T: DepGraphRead
{
fn read(&self, tcx: TyCtxt) {
fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
for i in self {
i.read(tcx);
}
Expand All @@ -171,7 +171,7 @@ macro_rules! read_tuple {
where $($name: DepGraphRead),*
{
#[allow(non_snake_case)]
fn read(&self, tcx: TyCtxt) {
fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
let &($(ref $name),*) = self;
$($name.read(tcx);)*
}
Expand All @@ -184,7 +184,7 @@ read_tuple!(A, B, C);
macro_rules! read_hir {
($t:ty) => {
impl<'tcx> DepGraphRead for &'tcx $t {
fn read(&self, tcx: TyCtxt) {
fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
tcx.hir().read(self.id);
}
}
Expand All @@ -208,7 +208,7 @@ read_hir!(hir::MacroDef);
pub struct Untracked<T>(pub 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
Expand All @@ -218,7 +218,7 @@ impl<T> DepGraphRead for Untracked<T> {
pub struct FromId<T>(pub ast::NodeId, pub T);

impl<T> DepGraphRead for FromId<T> {
fn read(&self, tcx: TyCtxt) {
fn read(&self, tcx: TyCtxt<'_, '_, '_>) {
tcx.hir().read(self.0);
}
}
4 changes: 2 additions & 2 deletions src/librustc_metadata/isolated_encoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use encoder::EncodeContext;
use schema::{Lazy, LazySeq};
use crate::encoder::EncodeContext;
use crate::schema::{Lazy, LazySeq};
use rustc::ty::TyCtxt;
use rustc_serialize::Encodable;

Expand Down
14 changes: 3 additions & 11 deletions src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,15 @@

#![recursion_limit="256"]

#![deny(rust_2018_idioms)]

extern crate libc;
#[macro_use]
extern crate log;
extern crate memmap;
extern crate stable_deref_trait;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate flate2;
#[allow(unused_extern_crates)]
extern crate serialize as rustc_serialize; // used by deriving
extern crate rustc_errors as errors;
extern crate syntax_ext;
extern crate proc_macro;

#[macro_use]
extern crate rustc;
extern crate rustc_target;
#[macro_use]
extern crate rustc_data_structures;

Expand Down
Loading