Skip to content

Commit

Permalink
Accept LocalDefId as keyt for names_imported_by_glob_use
Browse files Browse the repository at this point in the history
and `maybe_unused_trait_import` queries
  • Loading branch information
marmeladema committed Apr 27, 2020
1 parent da975c3 commit 82cc530
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82cc530

Please sign in to comment.