Skip to content

Resolve: improve detection of unused imports and other miscellaneous improvements #31321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 5, 2016
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use front::map as ast_map;
use session::Session;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use middle::cstore::InlinedItem;
use middle::ty::{self, Ty};
use middle::ty;

use std::cell::RefCell;
use std::collections::hash_map::Entry;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{abi, ast};
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{self, Span};
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};

use rustc_front::hir;
use rustc_front::intravisit::{self, Visitor};
Expand Down
32 changes: 10 additions & 22 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,17 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
}

fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
// Check each statement.
for statement in &block.stmts {
match statement.node {
StmtDecl(ref declaration, _) => {
match declaration.node {
DeclItem(_) => {
return true;
}
_ => {
// Keep searching.
}
}
}
_ => {
// Keep searching.
fn is_item(statement: &hir::Stmt) -> bool {
if let StmtDecl(ref declaration, _) = statement.node {
if let DeclItem(_) = declaration.node {
return true;
}
}
false
}

// If we found no items, we don't need to create
// an anonymous module.

return false;
// If any statements are items, we need to create an anonymous module
block.stmts.iter().any(is_item)
}

/// Constructs the reduced graph for one item.
Expand Down Expand Up @@ -309,7 +297,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
let external_module = self.new_extern_crate_module(parent_link, def);
self.define(parent, name, TypeNS, (external_module, sp));

self.build_reduced_graph_for_external_crate(&external_module);
self.build_reduced_graph_for_external_crate(external_module);
}
parent
}
Expand Down Expand Up @@ -365,7 +353,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
for variant in &(*enum_definition).variants {
let item_def_id = self.ast_map.local_def_id(item.id);
self.build_reduced_graph_for_variant(variant, item_def_id,
&module, variant_modifiers);
module, variant_modifiers);
}
parent
}
Expand Down Expand Up @@ -421,7 +409,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
};

let modifiers = DefModifiers::PUBLIC; // NB: not DefModifiers::IMPORTABLE
self.define(&module_parent, item.name, ns, (def, item.span, modifiers));
self.define(module_parent, item.name, ns, (def, item.span, modifiers));

self.trait_item_map.insert((item.name, def_id), item_def_id);
}
Expand Down
Loading