mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Rollup merge of #123813 - compiler-errors:redundant-lint, r=petrochenkov
Add `REDUNDANT_IMPORTS` lint for new redundant import detection Defaults to Allow for now. Stacked on #123744 to avoid merge conflict, but much easier to review all as one. r? petrochenkov
This commit is contained in:
commit
20379e4d4e
@ -700,10 +700,10 @@ lint_reason_must_be_string_literal = reason must be a string literal
|
|||||||
lint_reason_must_come_last = reason in lint attribute must come last
|
lint_reason_must_come_last = reason in lint attribute must come last
|
||||||
|
|
||||||
lint_redundant_import = the item `{$ident}` is imported redundantly
|
lint_redundant_import = the item `{$ident}` is imported redundantly
|
||||||
.label_imported_here = the item `{ident}` is already imported here
|
.label_imported_here = the item `{$ident}` is already imported here
|
||||||
.label_defined_here = the item `{ident}` is already defined here
|
.label_defined_here = the item `{$ident}` is already defined here
|
||||||
.label_imported_prelude = the item `{ident}` is already imported by the extern prelude
|
.label_imported_prelude = the item `{$ident}` is already imported by the extern prelude
|
||||||
.label_defined_prelude = the item `{ident}` is already defined by the extern prelude
|
.label_defined_prelude = the item `{$ident}` is already defined by the extern prelude
|
||||||
|
|
||||||
lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
|
lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
|
||||||
.note = the most public imported item is `{$max_vis}`
|
.note = the most public imported item is `{$max_vis}`
|
||||||
|
@ -82,6 +82,7 @@ declare_lint_pass! {
|
|||||||
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
|
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
|
||||||
PTR_CAST_ADD_AUTO_TO_OBJECT,
|
PTR_CAST_ADD_AUTO_TO_OBJECT,
|
||||||
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
||||||
|
REDUNDANT_IMPORTS,
|
||||||
REDUNDANT_LIFETIMES,
|
REDUNDANT_LIFETIMES,
|
||||||
REFINING_IMPL_TRAIT_INTERNAL,
|
REFINING_IMPL_TRAIT_INTERNAL,
|
||||||
REFINING_IMPL_TRAIT_REACHABLE,
|
REFINING_IMPL_TRAIT_REACHABLE,
|
||||||
@ -426,6 +427,31 @@ declare_lint! {
|
|||||||
"imports that are never used"
|
"imports that are never used"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_lint! {
|
||||||
|
/// The `redundant_imports` lint detects imports that are redundant due to being
|
||||||
|
/// imported already; either through a previous import, or being present in
|
||||||
|
/// the prelude.
|
||||||
|
///
|
||||||
|
/// ### Example
|
||||||
|
///
|
||||||
|
/// ```rust,compile_fail
|
||||||
|
/// #![deny(redundant_imports)]
|
||||||
|
/// use std::option::Option::None;
|
||||||
|
/// fn foo() -> Option<i32> { None }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// {{produces}}
|
||||||
|
///
|
||||||
|
/// ### Explanation
|
||||||
|
///
|
||||||
|
/// Redundant imports are unnecessary and can be removed to simplify code.
|
||||||
|
/// If you intended to re-export the item to make it available outside of the
|
||||||
|
/// module, add a visibility modifier like `pub`.
|
||||||
|
pub REDUNDANT_IMPORTS,
|
||||||
|
Allow,
|
||||||
|
"imports that are redundant due to being imported already"
|
||||||
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
|
/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
|
||||||
/// (`.await`)
|
/// (`.await`)
|
||||||
|
@ -14,7 +14,7 @@ use rustc_middle::metadata::{ModChild, Reexport};
|
|||||||
use rustc_middle::{span_bug, ty};
|
use rustc_middle::{span_bug, ty};
|
||||||
use rustc_session::lint::builtin::{
|
use rustc_session::lint::builtin::{
|
||||||
AMBIGUOUS_GLOB_REEXPORTS, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
AMBIGUOUS_GLOB_REEXPORTS, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
||||||
UNUSED_IMPORTS,
|
REDUNDANT_IMPORTS, UNUSED_IMPORTS,
|
||||||
};
|
};
|
||||||
use rustc_session::lint::BuiltinLintDiag;
|
use rustc_session::lint::BuiltinLintDiag;
|
||||||
use rustc_span::edit_distance::find_best_match_for_name;
|
use rustc_span::edit_distance::find_best_match_for_name;
|
||||||
@ -1387,14 +1387,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
|
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
|
||||||
redundant_spans.sort();
|
redundant_spans.sort();
|
||||||
redundant_spans.dedup();
|
redundant_spans.dedup();
|
||||||
/* FIXME(unused_imports): Add this back as a new lint
|
self.lint_buffer.buffer_lint(
|
||||||
self.lint_buffer.buffer_lint_with_diagnostic(
|
REDUNDANT_IMPORTS,
|
||||||
UNUSED_IMPORTS,
|
|
||||||
id,
|
id,
|
||||||
import.span,
|
import.span,
|
||||||
BuiltinLintDiag::RedundantImport(redundant_spans, source),
|
BuiltinLintDiag::RedundantImport(redundant_spans, source),
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +178,8 @@ enum ImplTraitContext {
|
|||||||
|
|
||||||
/// Used for tracking import use types which will be used for redundant import checking.
|
/// Used for tracking import use types which will be used for redundant import checking.
|
||||||
/// ### Used::Scope Example
|
/// ### Used::Scope Example
|
||||||
/// ```rust,ignore (redundant_imports)
|
/// ```rust,compile_fail
|
||||||
/// #![deny(unused_imports)]
|
/// #![deny(redundant_imports)]
|
||||||
/// use std::mem::drop;
|
/// use std::mem::drop;
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let s = Box::new(32);
|
/// let s = Box::new(32);
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
//@ check-pass
|
|
||||||
// Check that we detect imports that are redundant due to the extern prelude
|
// Check that we detect imports that are redundant due to the extern prelude
|
||||||
// and that we emit a reasonable diagnostic.
|
// and that we emit a reasonable diagnostic.
|
||||||
// issue: rust-lang/rust#121915
|
// issue: rust-lang/rust#121915
|
||||||
|
//~^^^ NOTE the item `aux_issue_121915` is already defined by the extern prelude
|
||||||
|
|
||||||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
|
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
|
||||||
|
|
||||||
//@ compile-flags: --extern aux_issue_121915 --edition 2018
|
//@ compile-flags: --extern aux_issue_121915 --edition 2018
|
||||||
//@ aux-build: aux-issue-121915.rs
|
//@ aux-build: aux-issue-121915.rs
|
||||||
|
|
||||||
#[deny(unused_imports)]
|
#[deny(redundant_imports)]
|
||||||
|
//~^ NOTE the lint level is defined here
|
||||||
fn main() {
|
fn main() {
|
||||||
use aux_issue_121915;
|
use aux_issue_121915;
|
||||||
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
|
//~^ ERROR the item `aux_issue_121915` is imported redundantly
|
||||||
aux_issue_121915::item();
|
aux_issue_121915::item();
|
||||||
}
|
}
|
||||||
|
14
tests/ui/imports/redundant-import-extern-prelude.stderr
Normal file
14
tests/ui/imports/redundant-import-extern-prelude.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: the item `aux_issue_121915` is imported redundantly
|
||||||
|
--> $DIR/redundant-import-extern-prelude.rs:14:9
|
||||||
|
|
|
||||||
|
LL | use aux_issue_121915;
|
||||||
|
| ^^^^^^^^^^^^^^^^ the item `aux_issue_121915` is already defined by the extern prelude
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/redundant-import-extern-prelude.rs:11:8
|
||||||
|
|
|
||||||
|
LL | #[deny(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -1,12 +1,11 @@
|
|||||||
//@ check-pass
|
|
||||||
//@ compile-flags: --extern aux_issue_121915 --edition 2015
|
//@ compile-flags: --extern aux_issue_121915 --edition 2015
|
||||||
//@ aux-build: aux-issue-121915.rs
|
//@ aux-build: aux-issue-121915.rs
|
||||||
|
|
||||||
extern crate aux_issue_121915;
|
extern crate aux_issue_121915;
|
||||||
|
|
||||||
#[deny(unused_imports)]
|
#[deny(redundant_imports)]
|
||||||
fn main() {
|
fn main() {
|
||||||
use aux_issue_121915;
|
use aux_issue_121915;
|
||||||
//FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly
|
//~^ ERROR the item `aux_issue_121915` is imported redundantly
|
||||||
aux_issue_121915::item();
|
aux_issue_121915::item();
|
||||||
}
|
}
|
||||||
|
17
tests/ui/imports/redundant-import-issue-121915-2015.stderr
Normal file
17
tests/ui/imports/redundant-import-issue-121915-2015.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error: the item `aux_issue_121915` is imported redundantly
|
||||||
|
--> $DIR/redundant-import-issue-121915-2015.rs:8:9
|
||||||
|
|
|
||||||
|
LL | extern crate aux_issue_121915;
|
||||||
|
| ------------------------------ the item `aux_issue_121915` is already imported here
|
||||||
|
...
|
||||||
|
LL | use aux_issue_121915;
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/redundant-import-issue-121915-2015.rs:6:8
|
||||||
|
|
|
||||||
|
LL | #[deny(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
//@ check-pass
|
|
||||||
// Check that we detect imports (of built-in attributes) that are redundant due to
|
// Check that we detect imports (of built-in attributes) that are redundant due to
|
||||||
// the language prelude and that we emit a reasonable diagnostic.
|
// the language prelude and that we emit a reasonable diagnostic.
|
||||||
|
//~^^ NOTE the item `allow` is already defined by the extern prelude
|
||||||
|
|
||||||
// Note that we use the term "extern prelude" in the label even though "language prelude"
|
// Note that we use the term "extern prelude" in the label even though "language prelude"
|
||||||
// would be more correct. However, it's not worth special-casing this.
|
// would be more correct. However, it's not worth special-casing this.
|
||||||
@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
//@ edition: 2018
|
//@ edition: 2018
|
||||||
|
|
||||||
#![deny(unused_imports)]
|
#![deny(redundant_imports)]
|
||||||
|
//~^ NOTE the lint level is defined here
|
||||||
|
|
||||||
use allow; //FIXME(unused_imports): ~ ERROR the item `allow` is imported redundantly
|
use allow; //~ ERROR the item `allow` is imported redundantly
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
14
tests/ui/imports/redundant-import-lang-prelude-attr.stderr
Normal file
14
tests/ui/imports/redundant-import-lang-prelude-attr.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: the item `allow` is imported redundantly
|
||||||
|
--> $DIR/redundant-import-lang-prelude-attr.rs:15:5
|
||||||
|
|
|
||||||
|
LL | use allow;
|
||||||
|
| ^^^^^ the item `allow` is already defined by the extern prelude
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/redundant-import-lang-prelude-attr.rs:12:9
|
||||||
|
|
|
||||||
|
LL | #![deny(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -1,16 +1,17 @@
|
|||||||
//@ check-pass
|
|
||||||
// Check that we detect imports that are redundant due to the language prelude
|
// Check that we detect imports that are redundant due to the language prelude
|
||||||
// and that we emit a reasonable diagnostic.
|
// and that we emit a reasonable diagnostic.
|
||||||
|
//~^^ NOTE the item `u8` is already defined by the extern prelude
|
||||||
|
|
||||||
// Note that we use the term "extern prelude" in the label even though "language prelude"
|
// Note that we use the term "extern prelude" in the label even though "language prelude"
|
||||||
// would be more correct. However, it's not worth special-casing this.
|
// would be more correct. However, it's not worth special-casing this.
|
||||||
|
|
||||||
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
|
// See also the discussion in <https://github.com/rust-lang/rust/pull/122954>.
|
||||||
|
|
||||||
#![deny(unused_imports)]
|
#![deny(redundant_imports)]
|
||||||
|
//~^ NOTE the lint level is defined here
|
||||||
|
|
||||||
use std::primitive::u8;
|
use std::primitive::u8;
|
||||||
//FIXME(unused_imports): ~^ ERROR the item `u8` is imported redundantly
|
//~^ ERROR the item `u8` is imported redundantly
|
||||||
|
|
||||||
const _: u8 = 0;
|
const _: u8 = 0;
|
||||||
|
|
||||||
|
14
tests/ui/imports/redundant-import-lang-prelude.stderr
Normal file
14
tests/ui/imports/redundant-import-lang-prelude.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: the item `u8` is imported redundantly
|
||||||
|
--> $DIR/redundant-import-lang-prelude.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use std::primitive::u8;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^ the item `u8` is already defined by the extern prelude
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/redundant-import-lang-prelude.rs:10:9
|
||||||
|
|
|
||||||
|
LL | #![deny(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -1,20 +1,19 @@
|
|||||||
//@ compile-flags: --edition 2021
|
//@ compile-flags: --edition 2021
|
||||||
|
#![deny(unused_imports, redundant_imports)]
|
||||||
#![deny(unused_imports)]
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn test0() {
|
fn test0() {
|
||||||
// Test remove FlatUnused
|
// Test remove FlatUnused
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
|
//~^ ERROR the item `TryFrom` is imported redundantly
|
||||||
let _ = u32::try_from(5i32);
|
let _ = u32::try_from(5i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test1() {
|
fn test1() {
|
||||||
// FIXME(yukang) Test remove NestedFullUnused
|
// FIXME(yukang) Test remove NestedFullUnused
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
//FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly
|
//~^ ERROR the item `TryFrom` is imported redundantly
|
||||||
//FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly
|
//~| ERROR the item `TryInto` is imported redundantly
|
||||||
|
|
||||||
let _ = u32::try_from(5i32);
|
let _ = u32::try_from(5i32);
|
||||||
let _a: i32 = u32::try_into(5u32).unwrap();
|
let _a: i32 = u32::try_into(5u32).unwrap();
|
||||||
@ -24,7 +23,7 @@ fn test2() {
|
|||||||
// FIXME(yukang): Test remove both redundant and unused
|
// FIXME(yukang): Test remove both redundant and unused
|
||||||
use std::convert::{AsMut, Into};
|
use std::convert::{AsMut, Into};
|
||||||
//~^ ERROR unused import: `AsMut`
|
//~^ ERROR unused import: `AsMut`
|
||||||
//FIXME(unused_imports): ~| ERROR the item `Into` is imported redundantly
|
//~| ERROR the item `Into` is imported redundantly
|
||||||
|
|
||||||
let _a: u32 = (5u8).into();
|
let _a: u32 = (5u8).into();
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,62 @@
|
|||||||
|
error: the item `TryFrom` is imported redundantly
|
||||||
|
--> $DIR/suggest-remove-issue-121315.rs:7:9
|
||||||
|
|
|
||||||
|
LL | use std::convert::TryFrom;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `TryFrom` is already defined here
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/suggest-remove-issue-121315.rs:2:25
|
||||||
|
|
|
||||||
|
LL | #![deny(unused_imports, redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: the item `TryFrom` is imported redundantly
|
||||||
|
--> $DIR/suggest-remove-issue-121315.rs:14:24
|
||||||
|
|
|
||||||
|
LL | use std::convert::{TryFrom, TryInto};
|
||||||
|
| ^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `TryFrom` is already defined here
|
||||||
|
|
||||||
|
error: the item `TryInto` is imported redundantly
|
||||||
|
--> $DIR/suggest-remove-issue-121315.rs:14:33
|
||||||
|
|
|
||||||
|
LL | use std::convert::{TryFrom, TryInto};
|
||||||
|
| ^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `TryInto` is already defined here
|
||||||
|
|
||||||
error: unused import: `AsMut`
|
error: unused import: `AsMut`
|
||||||
--> $DIR/suggest-remove-issue-121315.rs:25:24
|
--> $DIR/suggest-remove-issue-121315.rs:24:24
|
||||||
|
|
|
|
||||||
LL | use std::convert::{AsMut, Into};
|
LL | use std::convert::{AsMut, Into};
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/suggest-remove-issue-121315.rs:3:9
|
--> $DIR/suggest-remove-issue-121315.rs:2:9
|
||||||
|
|
|
|
||||||
LL | #![deny(unused_imports)]
|
LL | #![deny(unused_imports, redundant_imports)]
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: the item `Into` is imported redundantly
|
||||||
|
--> $DIR/suggest-remove-issue-121315.rs:24:31
|
||||||
|
|
|
||||||
|
LL | use std::convert::{AsMut, Into};
|
||||||
|
| ^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `Into` is already defined here
|
||||||
|
|
||||||
error: unused import: `From`
|
error: unused import: `From`
|
||||||
--> $DIR/suggest-remove-issue-121315.rs:34:24
|
--> $DIR/suggest-remove-issue-121315.rs:33:24
|
||||||
|
|
|
|
||||||
LL | use std::convert::{From, Infallible};
|
LL | use std::convert::{From, Infallible};
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
//@ check-pass
|
#![deny(redundant_imports)]
|
||||||
#![deny(unused_imports)]
|
|
||||||
|
|
||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly
|
use S; //~ ERROR the item `S` is imported redundantly
|
||||||
|
|
||||||
let _s = S;
|
let _s = S;
|
||||||
}
|
}
|
||||||
|
17
tests/ui/lint/unused/issue-59896.stderr
Normal file
17
tests/ui/lint/unused/issue-59896.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error: the item `S` is imported redundantly
|
||||||
|
--> $DIR/issue-59896.rs:6:9
|
||||||
|
|
|
||||||
|
LL | struct S;
|
||||||
|
| --------- the item `S` is already defined here
|
||||||
|
...
|
||||||
|
LL | use S;
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/issue-59896.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![deny(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![warn(unused_imports)]
|
#![warn(redundant_imports)]
|
||||||
|
|
||||||
pub mod bar {
|
pub mod bar {
|
||||||
pub struct Foo(pub Bar);
|
pub struct Foo(pub Bar);
|
||||||
@ -9,7 +9,7 @@ pub mod bar {
|
|||||||
use bar::*;
|
use bar::*;
|
||||||
|
|
||||||
pub fn warning() -> Foo {
|
pub fn warning() -> Foo {
|
||||||
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
|
use bar::Foo; //~ WARNING imported redundantly
|
||||||
Foo(Bar('a'))
|
Foo(Bar('a'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr
Normal file
17
tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
warning: the item `Foo` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-glob-parent.rs:12:9
|
||||||
|
|
|
||||||
|
LL | use bar::*;
|
||||||
|
| ------ the item `Foo` is already imported here
|
||||||
|
...
|
||||||
|
LL | use bar::Foo;
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant-glob-parent.rs:2:9
|
||||||
|
|
|
||||||
|
LL | #![warn(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![warn(unused_imports)]
|
#![warn(redundant_imports)]
|
||||||
|
|
||||||
pub mod bar {
|
pub mod bar {
|
||||||
pub struct Foo(pub Bar);
|
pub struct Foo(pub Bar);
|
||||||
@ -8,7 +8,7 @@ pub mod bar {
|
|||||||
|
|
||||||
pub fn warning() -> bar::Foo {
|
pub fn warning() -> bar::Foo {
|
||||||
use bar::*;
|
use bar::*;
|
||||||
use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly
|
use bar::Foo; //~ WARNING imported redundantly
|
||||||
Foo(Bar('a'))
|
Foo(Bar('a'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
tests/ui/lint/use-redundant/use-redundant-glob.stderr
Normal file
16
tests/ui/lint/use-redundant/use-redundant-glob.stderr
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
warning: the item `Foo` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-glob.rs:11:9
|
||||||
|
|
|
||||||
|
LL | use bar::*;
|
||||||
|
| ------ the item `Foo` is already imported here
|
||||||
|
LL | use bar::Foo;
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant-glob.rs:2:9
|
||||||
|
|
|
||||||
|
LL | #![warn(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![warn(unused_imports)]
|
#![warn(redundant_imports)]
|
||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -23,8 +23,7 @@ mod foo {
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
{
|
{
|
||||||
use std::string::String;
|
use std::string::String; //~ WARNING the item `String` is imported redundantly
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly
|
|
||||||
// 'String' from 'std::string::String'.
|
// 'String' from 'std::string::String'.
|
||||||
let s = String::new();
|
let s = String::new();
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
|
17
tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr
Normal file
17
tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
warning: the item `String` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-issue-71450.rs:26:13
|
||||||
|
|
|
||||||
|
LL | use std::string::String;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `String` is already defined here
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant-issue-71450.rs:3:9
|
||||||
|
|
|
||||||
|
LL | #![warn(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
@ -1,16 +1,12 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![warn(unused_imports)]
|
#![warn(redundant_imports)]
|
||||||
|
|
||||||
|
|
||||||
use std::option::Option::Some;
|
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly
|
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
|
||||||
use std::option::Option::None;
|
|
||||||
//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly
|
|
||||||
|
|
||||||
use std::result::Result::Ok;
|
use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly
|
use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly
|
||||||
use std::result::Result::Err;
|
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly
|
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
warning: the item `Some` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2015.rs:5:5
|
||||||
|
|
|
||||||
|
LL | use std::option::Option::Some;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `Some` is already defined here
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2015.rs:2:9
|
||||||
|
|
|
||||||
|
LL | #![warn(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: the item `None` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2015.rs:6:5
|
||||||
|
|
|
||||||
|
LL | use std::option::Option::None;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `None` is already defined here
|
||||||
|
|
||||||
|
warning: the item `Ok` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2015.rs:8:5
|
||||||
|
|
|
||||||
|
LL | use std::result::Result::Ok;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `Ok` is already defined here
|
||||||
|
|
||||||
|
warning: the item `Err` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2015.rs:9:5
|
||||||
|
|
|
||||||
|
LL | use std::result::Result::Err;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `Err` is already defined here
|
||||||
|
|
||||||
|
warning: 4 warnings emitted
|
||||||
|
|
@ -1,11 +1,9 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
#![warn(unused_imports)]
|
#![warn(redundant_imports)]
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `TryFrom` is imported redundantly
|
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly
|
||||||
use std::convert::TryInto;
|
|
||||||
//FIXME(unused_imports): ~^ WARNING the item `TryInto` is imported redundantly
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _e: Result<i32, _> = 8u8.try_into();
|
let _e: Result<i32, _> = 8u8.try_into();
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
warning: the item `TryFrom` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2021.rs:5:5
|
||||||
|
|
|
||||||
|
LL | use std::convert::TryFrom;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `TryFrom` is already defined here
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2021.rs:3:9
|
||||||
|
|
|
||||||
|
LL | #![warn(redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: the item `TryInto` is imported redundantly
|
||||||
|
--> $DIR/use-redundant-prelude-rust-2021.rs:6:5
|
||||||
|
|
|
||||||
|
LL | use std::convert::TryInto;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the item `TryInto` is already defined here
|
||||||
|
|
||||||
|
warning: 2 warnings emitted
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![warn(unused_imports)]
|
#![warn(unused_imports, redundant_imports)]
|
||||||
|
|
||||||
use crate::foo::Bar;
|
use crate::foo::Bar;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ use m1::*; //~ WARNING unused import
|
|||||||
use m2::*; //~ WARNING unused import
|
use m2::*; //~ WARNING unused import
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use crate::foo::Bar; //FIXME(unused_imports): ~ WARNING imported redundantly
|
use crate::foo::Bar; //~ WARNING imported redundantly
|
||||||
let _a: Bar = 3;
|
let _a: Bar = 3;
|
||||||
baz();
|
baz();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ LL | use m1::*;
|
|||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/use-redundant.rs:2:9
|
--> $DIR/use-redundant.rs:2:9
|
||||||
|
|
|
|
||||||
LL | #![warn(unused_imports)]
|
LL | #![warn(unused_imports, redundant_imports)]
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: unused import: `m2::*`
|
warning: unused import: `m2::*`
|
||||||
@ -16,5 +16,20 @@ warning: unused import: `m2::*`
|
|||||||
LL | use m2::*;
|
LL | use m2::*;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
warning: 2 warnings emitted
|
warning: the item `Bar` is imported redundantly
|
||||||
|
--> $DIR/use-redundant.rs:21:9
|
||||||
|
|
|
||||||
|
LL | use crate::foo::Bar;
|
||||||
|
| --------------- the item `Bar` is already imported here
|
||||||
|
...
|
||||||
|
LL | use crate::foo::Bar;
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/use-redundant.rs:2:25
|
||||||
|
|
|
||||||
|
LL | #![warn(unused_imports, redundant_imports)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: 3 warnings emitted
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user