Accept LocalDefId as keyt for names_imported_by_glob_use

and `maybe_unused_trait_import` queries
This commit is contained in:
marmeladema 2020-04-18 01:10:15 +01:00
parent da975c318d
commit 82cc530431
3 changed files with 11 additions and 11 deletions

View File

@ -1030,17 +1030,19 @@ rustc_queries! {
query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
eval_always
}
query maybe_unused_trait_import(_: DefId) -> bool {
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
eval_always
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
}
query maybe_unused_extern_crates(_: CrateNum)
-> &'tcx [(DefId, Span)] {
eval_always
desc { "looking up all possibly unused extern crates" }
}
query names_imported_by_glob_use(_: DefId)
query names_imported_by_glob_use(def_id: LocalDefId)
-> &'tcx FxHashSet<ast::Name> {
eval_always
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
}
query stability_index(_: CrateNum) -> &'tcx stability::Index<'tcx> {

View File

@ -945,11 +945,11 @@ pub struct GlobalCtxt<'tcx> {
pub queries: query::Queries<'tcx>,
maybe_unused_trait_imports: FxHashSet<DefId>,
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
maybe_unused_extern_crates: Vec<(DefId, Span)>,
/// A map of glob use to a set of names it actually imports. Currently only
/// used in save-analysis.
glob_map: FxHashMap<DefId, FxHashSet<ast::Name>>,
glob_map: FxHashMap<LocalDefId, FxHashSet<ast::Name>>,
/// Extern prelude entries. The value is `true` if the entry was introduced
/// via `extern crate` item and not `--extern` option or compiler built-in.
pub extern_prelude: FxHashMap<ast::Name, bool>,
@ -1165,7 +1165,7 @@ impl<'tcx> TyCtxt<'tcx> {
maybe_unused_trait_imports: resolutions
.maybe_unused_trait_imports
.into_iter()
.map(|id| definitions.local_def_id(id).to_def_id())
.map(|id| definitions.local_def_id(id))
.collect(),
maybe_unused_extern_crates: resolutions
.maybe_unused_extern_crates
@ -1175,7 +1175,7 @@ impl<'tcx> TyCtxt<'tcx> {
glob_map: resolutions
.glob_map
.into_iter()
.map(|(id, names)| (definitions.local_def_id(id).to_def_id(), names))
.map(|(id, names)| (definitions.local_def_id(id), names))
.collect(),
extern_prelude: resolutions.extern_prelude,
untracked_crate: krate,
@ -2716,10 +2716,8 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE);
&tcx.maybe_unused_extern_crates[..]
};
providers.names_imported_by_glob_use = |tcx, id| {
assert_eq!(id.krate, LOCAL_CRATE);
tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default())
};
providers.names_imported_by_glob_use =
|tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default());
providers.lookup_stability = |tcx, id| {
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());

View File

@ -1183,7 +1183,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
// Make a comma-separated list of names of imported modules.
let def_id = self.tcx.hir().local_def_id_from_node_id(id);
let names = self.tcx.names_imported_by_glob_use(def_id.to_def_id());
let names = self.tcx.names_imported_by_glob_use(def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
// Otherwise it's a span with wrong macro expansion info, which