Skip to content

Commit dcf8ef2

Browse files
committed
Auto merge of #31321 - jseyfried:cleanup, r=nrc
The first commit improves detection of unused imports -- it should have been part of #30325. Right now, the unused import in the changed test would not be reported. The rest of the commits are miscellaneous, independent clean-ups in resolve that I didn't think warranted individual PRs. r? @nrc
2 parents 7bcced7 + 9c166cb commit dcf8ef2

File tree

11 files changed

+128
-290
lines changed

11 files changed

+128
-290
lines changed

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use front::map as ast_map;
2020
use session::Session;
2121
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2222
use middle::cstore::InlinedItem;
23-
use middle::ty::{self, Ty};
23+
use middle::ty;
2424

2525
use std::cell::RefCell;
2626
use std::collections::hash_map::Entry;

src/librustc_lint/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
2626
use syntax::{abi, ast};
2727
use syntax::attr::{self, AttrMetaMethods};
2828
use syntax::codemap::{self, Span};
29-
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
3029

3130
use rustc_front::hir;
3231
use rustc_front::intravisit::{self, Visitor};

src/librustc_resolve/build_reduced_graph.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,17 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
142142
}
143143

144144
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
145-
// Check each statement.
146-
for statement in &block.stmts {
147-
match statement.node {
148-
StmtDecl(ref declaration, _) => {
149-
match declaration.node {
150-
DeclItem(_) => {
151-
return true;
152-
}
153-
_ => {
154-
// Keep searching.
155-
}
156-
}
157-
}
158-
_ => {
159-
// Keep searching.
145+
fn is_item(statement: &hir::Stmt) -> bool {
146+
if let StmtDecl(ref declaration, _) = statement.node {
147+
if let DeclItem(_) = declaration.node {
148+
return true;
160149
}
161150
}
151+
false
162152
}
163153

164-
// If we found no items, we don't need to create
165-
// an anonymous module.
166-
167-
return false;
154+
// If any statements are items, we need to create an anonymous module
155+
block.stmts.iter().any(is_item)
168156
}
169157

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

312-
self.build_reduced_graph_for_external_crate(&external_module);
300+
self.build_reduced_graph_for_external_crate(external_module);
313301
}
314302
parent
315303
}
@@ -365,7 +353,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
365353
for variant in &(*enum_definition).variants {
366354
let item_def_id = self.ast_map.local_def_id(item.id);
367355
self.build_reduced_graph_for_variant(variant, item_def_id,
368-
&module, variant_modifiers);
356+
module, variant_modifiers);
369357
}
370358
parent
371359
}
@@ -421,7 +409,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
421409
};
422410

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

426414
self.trait_item_map.insert((item.name, def_id), item_def_id);
427415
}

0 commit comments

Comments
 (0)