From 2942cf7b0ace5a23fc26713f49de7b1e696bfb16 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 24 Feb 2016 08:46:25 +0000 Subject: [PATCH] Improve unused import detection --- src/librustc_resolve/lib.rs | 10 ++++++---- src/test/compile-fail/lint-unused-imports.rs | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index aa529de085ea..6900cbbba8d2 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2788,8 +2788,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } if check_ribs { - if let Some(def) = self.resolve_identifier_in_local_ribs(identifier, namespace) { - return Some(def); + match self.resolve_identifier_in_local_ribs(identifier, namespace, record_used) { + Some(def) => return Some(def), + None => {} } } @@ -3001,7 +3002,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { fn resolve_identifier_in_local_ribs(&mut self, ident: hir::Ident, - namespace: Namespace) + namespace: Namespace, + record_used: bool) -> Option { // Check the local set of ribs. let name = match namespace { ValueNS => ident.name, TypeNS => ident.unhygienic_name }; @@ -3033,7 +3035,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ident.unhygienic_name, namespace, true, - true) { + record_used) { if let Some(def) = binding.def() { return Some(LocalDef::from_def(def)); } diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index 080c5e400ac9..3c1f4b043062 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -69,6 +69,13 @@ mod bar { } } +fn g() { + use self::g; //~ ERROR unused import + fn f() { + self::g(); + } +} + fn main() { cal(foo::Point{x:3, y:9}); let mut a = 3;