typeck: Use LocalDefId
s for the unused trait import set
This commit is contained in:
parent
a4337ccc10
commit
fc13fd03ba
@ -114,6 +114,7 @@ macro_rules! arena_types {
|
|||||||
|
|
||||||
// This is used to decode the &'tcx [Span] for InlineAsm's line_spans.
|
// This is used to decode the &'tcx [Span] for InlineAsm's line_spans.
|
||||||
[decode] span: rustc_span::Span, rustc_span::Span;
|
[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);
|
], $tcx);
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ rustc_queries! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Other {
|
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()) }
|
desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
|
||||||
cache_on_disk_if { true }
|
cache_on_disk_if { true }
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
|
|||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
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::definitions::{DefPathHash, Definitions};
|
||||||
use rustc_hir::lang_items::{self, PanicLocationLangItem};
|
use rustc_hir::lang_items::{self, PanicLocationLangItem};
|
||||||
use rustc_hir::{HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate};
|
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
|
/// This is used for warning unused imports. During type
|
||||||
/// checking, this `Lrc` should not be cloned: it must have a ref-count
|
/// 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.
|
/// 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,
|
/// If any errors occurred while type-checking this body,
|
||||||
/// this field will be set to `Some(ErrorReported)`.
|
/// this field will be set to `Some(ErrorReported)`.
|
||||||
|
@ -197,7 +197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
debug!("used_trait_import: {:?}", import_id);
|
debug!("used_trait_import: {:?}", import_id);
|
||||||
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
|
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(import_id.to_def_id());
|
.insert(*import_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span);
|
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();
|
let used_trait_imports = Lrc::get_mut(&mut tables.used_trait_imports).unwrap();
|
||||||
for import_id in pick.import_ids {
|
for import_id in pick.import_ids {
|
||||||
debug!("resolve_ufcs: used_trait_import: {:?}", import_id);
|
debug!("resolve_ufcs: used_trait_import: {:?}", import_id);
|
||||||
used_trait_imports.insert(import_id.to_def_id());
|
used_trait_imports.insert(import_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ use rustc_errors::ErrorReported;
|
|||||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
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::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc_hir::lang_items::{
|
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
|
&*tcx.typeck_tables_of(def_id).used_trait_imports
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,10 +4,8 @@
|
|||||||
|
|
||||||
use crate::check::FnCtxt;
|
use crate::check::FnCtxt;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
|
||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefIdSet;
|
|
||||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
@ -67,10 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
wbcx.visit_user_provided_sigs();
|
wbcx.visit_user_provided_sigs();
|
||||||
wbcx.visit_generator_interior_types();
|
wbcx.visit_generator_interior_types();
|
||||||
|
|
||||||
let used_trait_imports = mem::replace(
|
let used_trait_imports = mem::take(&mut self.tables.borrow_mut().used_trait_imports);
|
||||||
&mut self.tables.borrow_mut().used_trait_imports,
|
|
||||||
Lrc::new(DefIdSet::default()),
|
|
||||||
);
|
|
||||||
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
|
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
|
||||||
wbcx.tables.used_trait_imports = used_trait_imports;
|
wbcx.tables.used_trait_imports = used_trait_imports;
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
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_hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
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() {
|
for &body_id in tcx.hir().krate().bodies.keys() {
|
||||||
let item_def_id = tcx.hir().body_owner_def_id(body_id);
|
let item_def_id = tcx.hir().body_owner_def_id(body_id);
|
||||||
let imports = tcx.used_trait_imports(item_def_id);
|
let imports = tcx.used_trait_imports(item_def_id);
|
||||||
@ -39,7 +39,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> {
|
|||||||
|
|
||||||
struct CheckVisitor<'tcx> {
|
struct CheckVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
used_trait_imports: DefIdSet,
|
used_trait_imports: FxHashSet<LocalDefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckVisitor<'tcx> {
|
impl CheckVisitor<'tcx> {
|
||||||
@ -49,7 +49,7 @@ impl CheckVisitor<'tcx> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.used_trait_imports.contains(&def_id.to_def_id()) {
|
if self.used_trait_imports.contains(&def_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user