about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-09-17 08:48:31 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-09-17 08:48:31 -0700
commite68c95329e52ce455915e604292af3a36a595576 (patch)
tree39b2c4e59f46303672c14ea7a230e49c174c4d79
parentfc6eb9a911a12159d2a1156d6f138cebef0bf945 (diff)
parent61135205e190e3ca2c5896d05610dfb304f7a12f (diff)
downloadrust-e68c95329e52ce455915e604292af3a36a595576.tar.gz
rust-e68c95329e52ce455915e604292af3a36a595576.zip
rollup merge of #16931 : omasanori/unnecessary-path-brackets
-rw-r--r--src/librustc/lint/builtin.rs35
-rw-r--r--src/librustc/lint/context.rs1
-rw-r--r--src/test/compile-fail/lint-unnecessary-import-braces.rs21
3 files changed, 57 insertions, 0 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index eed41edac9d..edca4ce317d 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -1107,6 +1107,41 @@ impl LintPass for UnnecessaryParens {
     }
 }
 
+declare_lint!(UNNECESSARY_IMPORT_BRACES, Allow,
+              "unnecessary braces around an imported item")
+
+pub struct UnnecessaryImportBraces;
+
+impl LintPass for UnnecessaryImportBraces {
+    fn get_lints(&self) -> LintArray {
+        lint_array!(UNNECESSARY_IMPORT_BRACES)
+    }
+
+    fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
+        match view_item.node {
+            ast::ViewItemUse(ref view_path) => {
+                match view_path.node {
+                    ast::ViewPathList(_, ref items, _) => {
+                        if items.len() == 1 {
+                            match items[0].node {
+                                ast::PathListIdent {ref name, ..} => {
+                                    let m = format!("braces around {} is unnecessary",
+                                                    token::get_ident(*name).get());
+                                    cx.span_lint(UNNECESSARY_IMPORT_BRACES, view_item.span,
+                                                 m.as_slice());
+                                },
+                                _ => ()
+                            }
+                        }
+                    }
+                    _ => ()
+                }
+            },
+            _ => ()
+        }
+    }
+}
+
 declare_lint!(UNUSED_UNSAFE, Warn,
               "unnecessary use of an `unsafe` block")
 
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index c75b57dcafa..e39685705df 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -183,6 +183,7 @@ impl LintStore {
                      NonSnakeCase,
                      NonUppercaseStatics,
                      UnnecessaryParens,
+                     UnnecessaryImportBraces,
                      UnusedUnsafe,
                      UnsafeBlock,
                      UnusedMut,
diff --git a/src/test/compile-fail/lint-unnecessary-import-braces.rs b/src/test/compile-fail/lint-unnecessary-import-braces.rs
new file mode 100644
index 00000000000..c44918d9879
--- /dev/null
+++ b/src/test/compile-fail/lint-unnecessary-import-braces.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![deny(unnecessary_import_braces)]
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use test::{A}; //~ ERROR braces around A is unnecessary
+
+mod test {
+    pub struct A;
+}
+
+fn main() {}