Skip to content

Commit 1b3ef66

Browse files
committed
Switch crate_extern_paths to a query, and tweak wording.
1 parent c225e5c commit 1b3ef66

File tree

9 files changed

+20
-27
lines changed

9 files changed

+20
-27
lines changed

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_span::symbol::{Ident, Symbol};
2727
use rustc_data_structures::sync::Lrc;
2828
use smallvec::SmallVec;
2929
use std::any::Any;
30-
use std::path::PathBuf;
3130

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

241240
syms
242241
}
242+
243+
crate_extern_paths => { cdata.source().paths().cloned().collect() }
243244
}
244245

245246
pub fn provide(providers: &mut Providers<'_>) {
@@ -514,8 +515,4 @@ impl CrateStore for CStore {
514515
fn allocator_kind(&self) -> Option<AllocatorKind> {
515516
self.allocator_kind()
516517
}
517-
518-
fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> {
519-
self.get_crate_data(cnum).source().paths().cloned().collect()
520-
}
521518
}

src/librustc_middle/middle/cstore.rs

-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ pub trait CrateStore {
203203
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
204204
fn metadata_encoding_version(&self) -> &[u8];
205205
fn allocator_kind(&self) -> Option<AllocatorKind>;
206-
fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf>;
207206
}
208207

209208
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

src/librustc_middle/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ rustc_queries! {
10421042
eval_always
10431043
desc { "looking up the extra filename for a crate" }
10441044
}
1045+
query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1046+
eval_always
1047+
desc { "looking up the paths for extern crates" }
1048+
}
10451049
}
10461050

10471051
TypeChecking {

src/librustc_middle/ty/context.rs

-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use std::hash::{Hash, Hasher};
6262
use std::iter;
6363
use std::mem;
6464
use std::ops::{Bound, Deref};
65-
use std::path::PathBuf;
6665
use std::sync::Arc;
6766

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

1256-
pub fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> {
1257-
if cnum == LOCAL_CRATE {
1258-
self.sess.local_crate_source_file.iter().cloned().collect()
1259-
} else {
1260-
self.cstore.crate_extern_paths(cnum)
1261-
}
1262-
}
1263-
12641255
#[inline]
12651256
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
12661257
if let Some(def_id) = def_id.as_local() {

src/librustc_middle/ty/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use rustc_span::{Span, DUMMY_SP};
5757
use std::borrow::Cow;
5858
use std::collections::BTreeMap;
5959
use std::ops::Deref;
60+
use std::path::PathBuf;
6061
use std::sync::Arc;
6162

6263
#[macro_use]

src/librustc_passes/lang_items.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,24 @@ impl LanguageItemCollector<'tcx> {
147147
}
148148
}
149149
let mut note_def = |which, def_id: DefId| {
150-
let location = if def_id.is_local() {
151-
"the local crate".to_string()
150+
let crate_name = self.tcx.crate_name(def_id.krate);
151+
let note = if def_id.is_local() {
152+
format!("{} definition in the local crate (`{}`)", which, crate_name)
152153
} else {
153154
let paths: Vec<_> = self
154155
.tcx
155156
.crate_extern_paths(def_id.krate)
156157
.iter()
157158
.map(|p| p.display().to_string())
158159
.collect();
159-
paths.join(", ")
160+
format!(
161+
"{} definition in `{}` loaded from {}",
162+
which,
163+
crate_name,
164+
paths.join(", ")
165+
)
160166
};
161-
err.note(&format!(
162-
"{} definition in `{}` loaded from {}",
163-
which,
164-
self.tcx.crate_name(def_id.krate),
165-
location
166-
));
167+
err.note(&note);
167168
};
168169
note_def("first", original_def_id);
169170
note_def("second", item_def_id);

src/test/ui/duplicate_entry_error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | | }
99
|
1010
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
1111
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
12-
= note: second definition in `duplicate_entry_error` loaded from the local crate
12+
= note: second definition in the local crate (`duplicate_entry_error`)
1313

1414
error: aborting due to previous error
1515

src/test/ui/error-codes/E0152.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | struct Foo;
66
|
77
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
88
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
9-
= note: second definition in `E0152` loaded from the local crate
9+
= note: second definition in the local crate (`E0152`)
1010

1111
error: aborting due to previous error
1212

src/test/ui/panic-handler/panic-handler-std.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | }
88
|
99
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
1010
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
11-
= note: second definition in `panic_handler_std` loaded from the local crate
11+
= note: second definition in the local crate (`panic_handler_std`)
1212

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

0 commit comments

Comments
 (0)