Skip to content

Commit 2942cf7

Browse files
committed
Improve unused import detection
1 parent 197326d commit 2942cf7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/librustc_resolve/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2788,8 +2788,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27882788
}
27892789

27902790
if check_ribs {
2791-
if let Some(def) = self.resolve_identifier_in_local_ribs(identifier, namespace) {
2792-
return Some(def);
2791+
match self.resolve_identifier_in_local_ribs(identifier, namespace, record_used) {
2792+
Some(def) => return Some(def),
2793+
None => {}
27932794
}
27942795
}
27952796

@@ -3001,7 +3002,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30013002

30023003
fn resolve_identifier_in_local_ribs(&mut self,
30033004
ident: hir::Ident,
3004-
namespace: Namespace)
3005+
namespace: Namespace,
3006+
record_used: bool)
30053007
-> Option<LocalDef> {
30063008
// Check the local set of ribs.
30073009
let name = match namespace { ValueNS => ident.name, TypeNS => ident.unhygienic_name };
@@ -3033,7 +3035,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30333035
ident.unhygienic_name,
30343036
namespace,
30353037
true,
3036-
true) {
3038+
record_used) {
30373039
if let Some(def) = binding.def() {
30383040
return Some(LocalDef::from_def(def));
30393041
}

src/test/compile-fail/lint-unused-imports.rs

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ mod bar {
6969
}
7070
}
7171

72+
fn g() {
73+
use self::g; //~ ERROR unused import
74+
fn f() {
75+
self::g();
76+
}
77+
}
78+
7279
fn main() {
7380
cal(foo::Point{x:3, y:9});
7481
let mut a = 3;

0 commit comments

Comments
 (0)