rollup merge of #16931 : omasanori/unnecessary-path-brackets

This commit is contained in:
Alex Crichton 2014-09-17 08:48:31 -07:00
commit e68c95329e
3 changed files with 57 additions and 0 deletions

View File

@ -1107,6 +1107,41 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
}
}
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")

View File

@ -183,6 +183,7 @@ macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => (
NonSnakeCase,
NonUppercaseStatics,
UnnecessaryParens,
UnnecessaryImportBraces,
UnusedUnsafe,
UnsafeBlock,
UnusedMut,

View File

@ -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() {}