Use cnum for extern crate data

This commit is contained in:
Michael Goulet 2024-08-17 12:50:12 -04:00
parent c6f81a452e
commit b2dd943d4b
5 changed files with 8 additions and 10 deletions

View File

@ -1520,7 +1520,7 @@ rustc_queries! {
separate_provide_extern
}
query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
query extern_crate(def_id: CrateNum) -> Option<&'tcx ExternCrate> {
eval_always
desc { "getting crate's ExternCrateData" }
separate_provide_extern

View File

@ -451,7 +451,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
// 2. For an extern inferred from a path or an indirect crate,
// where there is no explicit `extern crate`, we just prepend
// the crate name.
match self.tcx().extern_crate(def_id) {
match self.tcx().extern_crate(cnum) {
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
// NOTE(eddyb) the only reason `span` might be dummy,
@ -3247,10 +3247,8 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
let mut seen_defs: DefIdSet = Default::default();
for &cnum in tcx.crates(()).iter() {
let def_id = cnum.as_def_id();
// Ignore crates that are not direct dependencies.
match tcx.extern_crate(def_id) {
match tcx.extern_crate(cnum) {
None => continue,
Some(extern_crate) => {
if !extern_crate.is_direct() {
@ -3259,7 +3257,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
}
}
queue.push(def_id);
queue.push(cnum.as_def_id());
}
// Iterate external crate defs but be mindful about visibility

View File

@ -859,7 +859,7 @@ impl<'tcx> TyCtxt<'tcx> {
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
// Treat that kind of crate as "indirect", since it's an implementation detail of
// the language.
|| self.extern_crate(key.as_def_id()).is_some_and(|e| e.is_direct())
|| self.extern_crate(key).is_some_and(|e| e.is_direct())
}
/// Whether the item has a host effect param. This is different from `TyCtxt::is_const`,

View File

@ -130,7 +130,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
if first_defined_span.is_none() {
orig_crate_name = self.tcx.crate_name(original_def_id.krate);
if let Some(ExternCrate { dependency_of: inner_dependency_of, .. }) =
self.tcx.extern_crate(original_def_id)
self.tcx.extern_crate(original_def_id.krate)
{
orig_dependency_of = self.tcx.crate_name(*inner_dependency_of);
}
@ -139,7 +139,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
let duplicate = if item_span.is_some() {
Duplicate::Plain
} else {
match self.tcx.extern_crate(item_def_id) {
match self.tcx.extern_crate(item_def_id.krate) {
Some(ExternCrate { dependency_of: inner_dependency_of, .. }) => {
dependency_of = self.tcx.crate_name(*inner_dependency_of);
Duplicate::CrateDepends

View File

@ -1668,7 +1668,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let name = self.tcx.crate_name(trait_def_id.krate);
let spans: Vec<_> = [trait_def_id, found_type]
.into_iter()
.filter_map(|def_id| self.tcx.extern_crate(def_id))
.filter_map(|def_id| self.tcx.extern_crate(def_id.krate))
.map(|data| {
let dependency = if data.dependency_of == LOCAL_CRATE {
"direct dependency of the current crate".to_string()