Skip to content

Commit 6113520

Browse files
committed
Add unnecessary_import_braces lint.
The lint checks any unnecessary braces around one imported item like `use std::num::{abs};`. Signed-off-by: OGINO Masanori <[email protected]>
1 parent 036f380 commit 6113520

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/librustc/lint/builtin.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,41 @@ impl LintPass for UnnecessaryParens {
11051105
}
11061106
}
11071107

1108+
declare_lint!(UNNECESSARY_IMPORT_BRACES, Allow,
1109+
"unnecessary braces around an imported item")
1110+
1111+
pub struct UnnecessaryImportBraces;
1112+
1113+
impl LintPass for UnnecessaryImportBraces {
1114+
fn get_lints(&self) -> LintArray {
1115+
lint_array!(UNNECESSARY_IMPORT_BRACES)
1116+
}
1117+
1118+
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
1119+
match view_item.node {
1120+
ast::ViewItemUse(ref view_path) => {
1121+
match view_path.node {
1122+
ast::ViewPathList(_, ref items, _) => {
1123+
if items.len() == 1 {
1124+
match items[0].node {
1125+
ast::PathListIdent {ref name, ..} => {
1126+
let m = format!("braces around {} is unnecessary",
1127+
token::get_ident(*name).get());
1128+
cx.span_lint(UNNECESSARY_IMPORT_BRACES, view_item.span,
1129+
m.as_slice());
1130+
},
1131+
_ => ()
1132+
}
1133+
}
1134+
}
1135+
_ => ()
1136+
}
1137+
},
1138+
_ => ()
1139+
}
1140+
}
1141+
}
1142+
11081143
declare_lint!(UNUSED_UNSAFE, Warn,
11091144
"unnecessary use of an `unsafe` block")
11101145

src/librustc/lint/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl LintStore {
183183
NonSnakeCase,
184184
NonUppercaseStatics,
185185
UnnecessaryParens,
186+
UnnecessaryImportBraces,
186187
UnusedUnsafe,
187188
UnsafeBlock,
188189
UnusedMut,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(unnecessary_import_braces)]
12+
#![allow(dead_code)]
13+
#![allow(unused_imports)]
14+
15+
use test::{A}; //~ ERROR braces around A is unnecessary
16+
17+
mod test {
18+
pub struct A;
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)