mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-30 09:24:35 +00:00
Initial work to remove typeck_tables call from check_unused
This commit is contained in:
parent
f6d7514545
commit
ada809917d
@ -388,7 +388,7 @@ pub struct TypeckTables<'tcx> {
|
||||
|
||||
/// Set of trait imports actually used in the method resolution.
|
||||
/// This is used for warning unused imports.
|
||||
pub used_trait_imports: DefIdSet,
|
||||
pub used_trait_imports: Rc<RefCell<DefIdSet>>,
|
||||
|
||||
/// If any errors occurred while type-checking this body,
|
||||
/// this field will be set to `true`.
|
||||
@ -418,7 +418,7 @@ impl<'tcx> TypeckTables<'tcx> {
|
||||
liberated_fn_sigs: ItemLocalMap(),
|
||||
fru_field_types: ItemLocalMap(),
|
||||
cast_kinds: ItemLocalMap(),
|
||||
used_trait_imports: DefIdSet(),
|
||||
used_trait_imports: Rc::new(RefCell::new(DefIdSet())),
|
||||
tainted_by_errors: false,
|
||||
free_region_map: FreeRegionMap::new(),
|
||||
}
|
||||
@ -782,7 +782,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
|
||||
cast_kinds.hash_stable(hcx, hasher);
|
||||
generator_sigs.hash_stable(hcx, hasher);
|
||||
generator_interiors.hash_stable(hcx, hasher);
|
||||
used_trait_imports.hash_stable(hcx, hasher);
|
||||
used_trait_imports.borrow_mut().hash_stable(hcx, hasher);
|
||||
tainted_by_errors.hash_stable(hcx, hasher);
|
||||
free_region_map.hash_stable(hcx, hasher);
|
||||
})
|
||||
|
@ -163,7 +163,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
if let Some(import_id) = pick.import_id {
|
||||
let import_def_id = self.tcx.hir.local_def_id(import_id);
|
||||
debug!("used_trait_import: {:?}", import_def_id);
|
||||
self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
|
||||
|
||||
let tables = self.tables.borrow_mut();
|
||||
let mut ut = tables.used_trait_imports.borrow_mut();
|
||||
ut.insert(import_def_id);
|
||||
}
|
||||
|
||||
self.tcx.check_stability(pick.item.def_id, call_expr.id, span);
|
||||
@ -361,7 +364,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
if let Some(import_id) = pick.import_id {
|
||||
let import_def_id = self.tcx.hir.local_def_id(import_id);
|
||||
debug!("used_trait_import: {:?}", import_def_id);
|
||||
self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
|
||||
let tables = self.tables.borrow_mut();
|
||||
let mut ut = tables.used_trait_imports.borrow_mut();
|
||||
ut.insert(import_def_id);
|
||||
}
|
||||
|
||||
let def = pick.item.def();
|
||||
|
@ -106,9 +106,10 @@ use session::{CompileIncomplete, Session};
|
||||
use TypeAndSubsts;
|
||||
use lint;
|
||||
use util::common::{ErrorReported, indenter};
|
||||
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
|
||||
use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, NodeMap};
|
||||
|
||||
use std::cell::{Cell, RefCell, Ref, RefMut};
|
||||
use std::rc::Rc;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::cmp;
|
||||
use std::fmt::Display;
|
||||
@ -921,6 +922,12 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tables
|
||||
}
|
||||
|
||||
pub fn get_used_trait_imports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> Rc<RefCell<DefIdSet>> {
|
||||
Rc::clone(&tcx.typeck_tables_of(def_id).used_trait_imports)
|
||||
}
|
||||
|
||||
fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) {
|
||||
if !tcx.sess.target.target.is_abi_supported(abi) {
|
||||
struct_span_err!(tcx.sess, span, E0570,
|
||||
|
@ -23,6 +23,8 @@ use rustc::util::nodemap::DefIdSet;
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Entry point
|
||||
@ -49,7 +51,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
wbcx.visit_generator_interiors();
|
||||
|
||||
let used_trait_imports = mem::replace(&mut self.tables.borrow_mut().used_trait_imports,
|
||||
DefIdSet());
|
||||
Rc::new(RefCell::new(DefIdSet())));
|
||||
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
|
||||
wbcx.tables.used_trait_imports = used_trait_imports;
|
||||
|
||||
|
@ -19,6 +19,8 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc::hir;
|
||||
use rustc::util::nodemap::DefIdSet;
|
||||
|
||||
use check::get_used_trait_imports;
|
||||
|
||||
struct CheckVisitor<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
used_trait_imports: DefIdSet,
|
||||
@ -66,10 +68,9 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
let mut used_trait_imports = DefIdSet();
|
||||
for &body_id in tcx.hir.krate().bodies.keys() {
|
||||
let item_def_id = tcx.hir.body_owner_def_id(body_id);
|
||||
let tables = tcx.typeck_tables_of(item_def_id);
|
||||
let imports = &tables.used_trait_imports;
|
||||
let imports = get_used_trait_imports(tcx, item_def_id);
|
||||
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
|
||||
used_trait_imports.extend(imports);
|
||||
used_trait_imports.extend(imports.borrow().iter());
|
||||
}
|
||||
|
||||
let mut visitor = CheckVisitor { tcx, used_trait_imports };
|
||||
|
Loading…
Reference in New Issue
Block a user