Skip to content

Commit

Permalink
Switch crate_extern_paths to a query, and tweak wording.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 30, 2020
1 parent c225e5c commit 1b3ef66
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 27 deletions.
7 changes: 2 additions & 5 deletions src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use rustc_span::symbol::{Ident, Symbol};
use rustc_data_structures::sync::Lrc;
use smallvec::SmallVec;
use std::any::Any;
use std::path::PathBuf;

macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
Expand Down Expand Up @@ -240,6 +239,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,

syms
}

crate_extern_paths => { cdata.source().paths().cloned().collect() }
}

pub fn provide(providers: &mut Providers<'_>) {
Expand Down Expand Up @@ -514,8 +515,4 @@ impl CrateStore for CStore {
fn allocator_kind(&self) -> Option<AllocatorKind> {
self.allocator_kind()
}

fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> {
self.get_crate_data(cnum).source().paths().cloned().collect()
}
}
1 change: 0 additions & 1 deletion src/librustc_middle/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ pub trait CrateStore {
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
fn allocator_kind(&self) -> Option<AllocatorKind>;
fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf>;
}

pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,10 @@ rustc_queries! {
eval_always
desc { "looking up the extra filename for a crate" }
}
query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
eval_always
desc { "looking up the paths for extern crates" }
}
}

TypeChecking {
Expand Down
9 changes: 0 additions & 9 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ use std::hash::{Hash, Hasher};
use std::iter;
use std::mem;
use std::ops::{Bound, Deref};
use std::path::PathBuf;
use std::sync::Arc;

type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;
Expand Down Expand Up @@ -1253,14 +1252,6 @@ impl<'tcx> TyCtxt<'tcx> {
if cnum == LOCAL_CRATE { false } else { self.cstore.crate_is_private_dep_untracked(cnum) }
}

pub fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> {
if cnum == LOCAL_CRATE {
self.sess.local_crate_source_file.iter().cloned().collect()
} else {
self.cstore.crate_extern_paths(cnum)
}
}

#[inline]
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
if let Some(def_id) = def_id.as_local() {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_middle/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use rustc_span::{Span, DUMMY_SP};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;

#[macro_use]
Expand Down
19 changes: 10 additions & 9 deletions src/librustc_passes/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,24 @@ impl LanguageItemCollector<'tcx> {
}
}
let mut note_def = |which, def_id: DefId| {
let location = if def_id.is_local() {
"the local crate".to_string()
let crate_name = self.tcx.crate_name(def_id.krate);
let note = if def_id.is_local() {
format!("{} definition in the local crate (`{}`)", which, crate_name)
} else {
let paths: Vec<_> = self
.tcx
.crate_extern_paths(def_id.krate)
.iter()
.map(|p| p.display().to_string())
.collect();
paths.join(", ")
format!(
"{} definition in `{}` loaded from {}",
which,
crate_name,
paths.join(", ")
)
};
err.note(&format!(
"{} definition in `{}` loaded from {}",
which,
self.tcx.crate_name(def_id.krate),
location
));
err.note(&note);
};
note_def("first", original_def_id);
note_def("second", item_def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/duplicate_entry_error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | | }
|
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in `duplicate_entry_error` loaded from the local crate
= note: second definition in the local crate (`duplicate_entry_error`)

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0152.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | struct Foo;
|
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
= note: second definition in `E0152` loaded from the local crate
= note: second definition in the local crate (`E0152`)

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-handler/panic-handler-std.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | | }
|
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in `panic_handler_std` loaded from the local crate
= note: second definition in the local crate (`panic_handler_std`)

error: argument should be `&PanicInfo`
--> $DIR/panic-handler-std.rs:8:16
Expand Down

0 comments on commit 1b3ef66

Please sign in to comment.