1
Fork 0

diagnostics: account for glob shadowing when linting redundant imports

Co-Authored-By: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
This commit is contained in:
Michael Howell 2023-03-25 09:28:28 -07:00
parent 2005e300c0
commit 000e94e67d
8 changed files with 142 additions and 14 deletions

View file

@ -0,0 +1,17 @@
// check-pass
pub struct Foo(bar::Bar);
pub mod bar {
pub struct Foo(pub Bar);
pub struct Bar(pub char);
}
pub fn warning() -> Foo {
use bar::*;
#[deny(unused_imports)]
use self::Foo; // no error
Foo(Bar('a'))
}
fn main() {}

View file

@ -0,0 +1,16 @@
// check-pass
#![warn(unused_imports)]
pub mod bar {
pub struct Foo(pub Bar);
pub struct Bar(pub char);
}
use bar::*;
pub fn warning() -> Foo {
use bar::Foo; //~ WARNING imported redundantly
Foo(Bar('a'))
}
fn main() {}

View 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(unused_imports)]
| ^^^^^^^^^^^^^^
warning: 1 warning emitted

View file

@ -0,0 +1,15 @@
// check-pass
#![warn(unused_imports)]
pub mod bar {
pub struct Foo(pub Bar);
pub struct Bar(pub char);
}
pub fn warning() -> bar::Foo {
use bar::*;
use bar::Foo; //~ WARNING imported redundantly
Foo(Bar('a'))
}
fn main() {}

View 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(unused_imports)]
| ^^^^^^^^^^^^^^
warning: 1 warning emitted

View file

@ -0,0 +1,21 @@
// check-pass
#![allow(nonstandard_style)]
pub mod bar {
pub struct Foo { pub bar: Bar }
pub struct Bar(pub char);
}
pub mod x {
use crate::bar;
pub const Foo: bar::Bar = bar::Bar('a');
}
pub fn warning() -> bar::Foo {
#![deny(unused_imports)] // no error
use bar::*;
use x::Foo;
Foo { bar: Foo }
}
fn main() {}

View file

@ -0,0 +1,19 @@
// check-pass
pub mod bar {
pub struct Foo(pub Bar);
pub struct Bar(pub char);
}
pub mod x {
pub struct Foo(pub crate::bar::Bar);
}
pub fn warning() -> x::Foo {
use bar::*;
#[deny(unused_imports)]
use x::Foo; // no error
Foo(Bar('a'))
}
fn main() {}