Replace REDUNDANT_IMPORT with UNUSED_IMPORTS
This commit is contained in:
parent
f9272364bf
commit
6e7b45e12b
6 changed files with 17 additions and 72 deletions
|
@ -392,12 +392,6 @@ declare_lint! {
|
||||||
"nested occurrence of `impl Trait` type"
|
"nested occurrence of `impl Trait` type"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
|
||||||
pub REDUNDANT_IMPORT,
|
|
||||||
Warn,
|
|
||||||
"redundant import"
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||||
/// that are used by other parts of the compiler.
|
/// that are used by other parts of the compiler.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -591,7 +585,7 @@ impl BuiltinLintDiagnostics {
|
||||||
let introduced = if is_imported { "imported" } else { "defined" };
|
let introduced = if is_imported { "imported" } else { "defined" };
|
||||||
db.span_label(
|
db.span_label(
|
||||||
span,
|
span,
|
||||||
format!("the item `{}` was {} here", ident, introduced)
|
format!("the item `{}` was already {} here", ident, introduced)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc::lint::builtin::BuiltinLintDiagnostics;
|
||||||
use rustc::lint::builtin::{
|
use rustc::lint::builtin::{
|
||||||
DUPLICATE_MACRO_EXPORTS,
|
DUPLICATE_MACRO_EXPORTS,
|
||||||
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
||||||
REDUNDANT_IMPORT,
|
UNUSED_IMPORTS,
|
||||||
};
|
};
|
||||||
use rustc::hir::def_id::{CrateNum, DefId};
|
use rustc::hir::def_id::{CrateNum, DefId};
|
||||||
use rustc::hir::def::*;
|
use rustc::hir::def::*;
|
||||||
|
@ -1308,7 +1308,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
is_redundant.present_items().all(|is_redundant| is_redundant)
|
is_redundant.present_items().all(|is_redundant| is_redundant)
|
||||||
{
|
{
|
||||||
self.session.buffer_lint_with_diagnostic(
|
self.session.buffer_lint_with_diagnostic(
|
||||||
REDUNDANT_IMPORT,
|
UNUSED_IMPORTS,
|
||||||
directive.id,
|
directive.id,
|
||||||
directive.span,
|
directive.span,
|
||||||
&format!("the item `{}` is imported redundantly", ident),
|
&format!("the item `{}` is imported redundantly", ident),
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#![deny(unused_imports)]
|
#![deny(unused_imports)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(redundant_import)]
|
|
||||||
|
|
||||||
use bar::c::cc as cal;
|
use bar::c::cc as cal;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ error: unused import: `foo::Square`
|
||||||
LL | use foo::Square;
|
LL | use foo::Square;
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
warning: the item `g` is imported redundantly
|
error: the item `g` is imported redundantly
|
||||||
--> $DIR/lint-unused-imports.rs:68:9
|
--> $DIR/lint-unused-imports.rs:68:9
|
||||||
|
|
|
|
||||||
LL | / fn g() {
|
LL | / fn g() {
|
||||||
|
@ -44,9 +44,7 @@ LL | | fn f() {
|
||||||
LL | | self::g();
|
LL | | self::g();
|
||||||
LL | | }
|
LL | | }
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_- the item `g` was already imported here
|
| |_- the item `g` was already defined here
|
||||||
|
|
|
||||||
= note: #[warn(redundant_import)] on by default
|
|
||||||
|
|
||||||
error: unused import: `self::g`
|
error: unused import: `self::g`
|
||||||
--> $DIR/lint-unused-imports.rs:68:9
|
--> $DIR/lint-unused-imports.rs:68:9
|
||||||
|
@ -54,7 +52,7 @@ error: unused import: `self::g`
|
||||||
LL | use self::g;
|
LL | use self::g;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
warning: the item `foo` is imported redundantly
|
error: the item `foo` is imported redundantly
|
||||||
--> $DIR/lint-unused-imports.rs:77:9
|
--> $DIR/lint-unused-imports.rs:77:9
|
||||||
|
|
|
|
||||||
LL | use test2::{foo, bar};
|
LL | use test2::{foo, bar};
|
||||||
|
@ -75,5 +73,5 @@ error: unused import: `test::B2`
|
||||||
LL | use test::B2;
|
LL | use test::B2;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// edition:2018
|
// edition:2018
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(redundant_import)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
mod T {
|
mod T {
|
||||||
pub struct U;
|
pub struct U;
|
||||||
|
|
|
@ -1,102 +1,56 @@
|
||||||
error: imports cannot refer to type parameters
|
error: imports cannot refer to type parameters
|
||||||
--> $DIR/future-proofing-locals.rs:13:9
|
--> $DIR/future-proofing-locals.rs:14:9
|
||||||
|
|
|
|
||||||
LL | use T as _;
|
LL | use T as _;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to type parameters
|
error: imports cannot refer to type parameters
|
||||||
--> $DIR/future-proofing-locals.rs:14:9
|
--> $DIR/future-proofing-locals.rs:15:9
|
||||||
|
|
|
|
||||||
LL | use T::U;
|
LL | use T::U;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to type parameters
|
error: imports cannot refer to type parameters
|
||||||
--> $DIR/future-proofing-locals.rs:15:9
|
--> $DIR/future-proofing-locals.rs:16:9
|
||||||
|
|
|
|
||||||
LL | use T::*;
|
LL | use T::*;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to type parameters
|
error: imports cannot refer to type parameters
|
||||||
--> $DIR/future-proofing-locals.rs:19:9
|
--> $DIR/future-proofing-locals.rs:20:9
|
||||||
|
|
|
|
||||||
LL | use T;
|
LL | use T;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to local variables
|
error: imports cannot refer to local variables
|
||||||
--> $DIR/future-proofing-locals.rs:25:9
|
--> $DIR/future-proofing-locals.rs:26:9
|
||||||
|
|
|
|
||||||
LL | use x as _;
|
LL | use x as _;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to local variables
|
error: imports cannot refer to local variables
|
||||||
--> $DIR/future-proofing-locals.rs:31:9
|
--> $DIR/future-proofing-locals.rs:32:9
|
||||||
|
|
|
|
||||||
LL | use x;
|
LL | use x;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to local variables
|
error: imports cannot refer to local variables
|
||||||
--> $DIR/future-proofing-locals.rs:37:17
|
--> $DIR/future-proofing-locals.rs:38:17
|
||||||
|
|
|
|
||||||
LL | use x;
|
LL | use x;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to type parameters
|
error: imports cannot refer to type parameters
|
||||||
--> $DIR/future-proofing-locals.rs:45:10
|
--> $DIR/future-proofing-locals.rs:46:10
|
||||||
|
|
|
|
||||||
LL | use {T as _, x};
|
LL | use {T as _, x};
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: imports cannot refer to local variables
|
error: imports cannot refer to local variables
|
||||||
--> $DIR/future-proofing-locals.rs:45:18
|
--> $DIR/future-proofing-locals.rs:46:18
|
||||||
|
|
|
|
||||||
LL | use {T as _, x};
|
LL | use {T as _, x};
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
warning: the item `T` is imported redundantly
|
|
||||||
--> $DIR/future-proofing-locals.rs:19:9
|
|
||||||
|
|
|
||||||
LL | / mod T {
|
|
||||||
LL | | pub struct U;
|
|
||||||
LL | | }
|
|
||||||
| |_- the item `T` was already imported here
|
|
||||||
...
|
|
||||||
LL | use T;
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= note: #[warn(redundant_import)] on by default
|
|
||||||
|
|
||||||
warning: the item `x` is imported redundantly
|
|
||||||
--> $DIR/future-proofing-locals.rs:31:9
|
|
||||||
|
|
|
||||||
LL | / mod x {
|
|
||||||
LL | | pub struct y;
|
|
||||||
LL | | }
|
|
||||||
| |_- the item `x` was already imported here
|
|
||||||
...
|
|
||||||
LL | use x;
|
|
||||||
| ^
|
|
||||||
|
|
||||||
warning: the item `x` is imported redundantly
|
|
||||||
--> $DIR/future-proofing-locals.rs:37:17
|
|
||||||
|
|
|
||||||
LL | / mod x {
|
|
||||||
LL | | pub struct y;
|
|
||||||
LL | | }
|
|
||||||
| |_- the item `x` was already imported here
|
|
||||||
...
|
|
||||||
LL | use x;
|
|
||||||
| ^
|
|
||||||
|
|
||||||
warning: the item `x` is imported redundantly
|
|
||||||
--> $DIR/future-proofing-locals.rs:45:18
|
|
||||||
|
|
|
||||||
LL | / mod x {
|
|
||||||
LL | | pub struct y;
|
|
||||||
LL | | }
|
|
||||||
| |_- the item `x` was already imported here
|
|
||||||
...
|
|
||||||
LL | use {T as _, x};
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to 9 previous errors
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue