Skip to content

Commit

Permalink
typeck: Use LocalDefIds for the unused trait import set
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 15, 2020
1 parent a4337cc commit fc13fd0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/librustc_middle/arena.rs
Expand Up @@ -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);
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/query/mod.rs
Expand Up @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/context.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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)`.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/mod.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 1 addition & 6 deletions src/librustc_typeck/check/writeback.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check_unused.rs
@@ -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);
Expand Down Expand Up @@ -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> {
Expand All @@ -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;
}

Expand Down

0 comments on commit fc13fd0

Please sign in to comment.