typeck: Use LocalDefIds for the unused trait import set

This commit is contained in:
Vadim Petrochenkov 2020-06-15 11:21:10 +03:00
parent a4337ccc10
commit fc13fd03ba
7 changed files with 14 additions and 18 deletions

View File

@ -114,6 +114,7 @@ macro_rules! arena_types {
// This is used to decode the &'tcx [Span] for InlineAsm's line_spans.
[decode] span: rustc_span::Span, rustc_span::Span;
[decode] used_trait_imports: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>, rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>;
], $tcx);
)
}

View File

@ -526,7 +526,7 @@ rustc_queries! {
}
Other {
query used_trait_imports(key: LocalDefId) -> &'tcx DefIdSet {
query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { true }
}

View File

@ -35,7 +35,7 @@ use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::{DefPathHash, Definitions};
use rustc_hir::lang_items::{self, PanicLocationLangItem};
use rustc_hir::{HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate};
@ -392,7 +392,7 @@ pub struct TypeckTables<'tcx> {
/// This is used for warning unused imports. During type
/// checking, this `Lrc` should not be cloned: it must have a ref-count
/// of 1 so that we can insert things into the set mutably.
pub used_trait_imports: Lrc<DefIdSet>,
pub used_trait_imports: Lrc<FxHashSet<LocalDefId>>,
/// If any errors occurred while type-checking this body,
/// this field will be set to `Some(ErrorReported)`.

View File

@ -197,7 +197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("used_trait_import: {:?}", import_id);
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
.unwrap()
.insert(import_id.to_def_id());
.insert(*import_id);
}
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span);
@ -461,7 +461,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let used_trait_imports = Lrc::get_mut(&mut tables.used_trait_imports).unwrap();
for import_id in pick.import_ids {
debug!("resolve_ufcs: used_trait_import: {:?}", import_id);
used_trait_imports.insert(import_id.to_def_id());
used_trait_imports.insert(import_id);
}
}

View File

@ -96,7 +96,7 @@ use rustc_errors::ErrorReported;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::lang_items::{
@ -839,7 +839,7 @@ fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}
}
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &DefIdSet {
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &FxHashSet<LocalDefId> {
&*tcx.typeck_tables_of(def_id).used_trait_imports
}

View File

@ -4,10 +4,8 @@
use crate::check::FnCtxt;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
use rustc_infer::infer::InferCtxt;
@ -67,10 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
wbcx.visit_user_provided_sigs();
wbcx.visit_generator_interior_types();
let used_trait_imports = mem::replace(
&mut self.tables.borrow_mut().used_trait_imports,
Lrc::new(DefIdSet::default()),
);
let used_trait_imports = mem::take(&mut self.tables.borrow_mut().used_trait_imports);
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
wbcx.tables.used_trait_imports = used_trait_imports;

View File

@ -1,14 +1,14 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint;
use rustc_span::{Span, Symbol};
pub fn check_crate(tcx: TyCtxt<'_>) {
let mut used_trait_imports = DefIdSet::default();
let mut used_trait_imports = FxHashSet::default();
for &body_id in tcx.hir().krate().bodies.keys() {
let item_def_id = tcx.hir().body_owner_def_id(body_id);
let imports = tcx.used_trait_imports(item_def_id);
@ -39,7 +39,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> {
struct CheckVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
used_trait_imports: DefIdSet,
used_trait_imports: FxHashSet<LocalDefId>,
}
impl CheckVisitor<'tcx> {
@ -49,7 +49,7 @@ impl CheckVisitor<'tcx> {
return;
}
if self.used_trait_imports.contains(&def_id.to_def_id()) {
if self.used_trait_imports.contains(&def_id) {
return;
}