Skip to content

Commit

Permalink
Add test for useless_anonymous_reexport lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 12, 2023
1 parent 2df7770 commit ac4ea52
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,4 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_useless_anonymous_reexport = useless anonymous re-export
.note = only anonymous re-exports of traits are useful, this is {$article} `${desc}`
.note = only anonymous re-exports of traits are useful, this is {$article} `{$desc}`
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,7 @@ pub struct UnusedAllocationMutDiag;

#[derive(LintDiagnostic)]
#[diag(lint_useless_anonymous_reexport)]
#[note]
pub struct UselessAnonymousReexportDiag {
pub article: &'static str,
pub desc: &'static str,
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/lint/anonymous-reexport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![deny(useless_anonymous_reexport)]
#![crate_type = "rlib"]

mod my_mod {
pub trait Foo {}
pub type TyFoo = dyn Foo;
pub struct Bar;
pub type TyBar = Bar;
}

pub use self::my_mod::Foo as _;
pub use self::my_mod::TyFoo as _;
pub use self::my_mod::Bar as _; //~ ERROR
pub use self::my_mod::TyBar as _; //~ ERROR
#[allow(unused_imports)]
use self::my_mod::TyBar as _;
20 changes: 20 additions & 0 deletions tests/ui/lint/anonymous-reexport.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: useless anonymous re-export
--> $DIR/anonymous-reexport.rs:13:1
|
LL | pub use self::my_mod::Bar as _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/anonymous-reexport.rs:1:9
|
LL | #![deny(useless_anonymous_reexport)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: useless anonymous re-export
--> $DIR/anonymous-reexport.rs:14:1
|
LL | pub use self::my_mod::TyBar as _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

0 comments on commit ac4ea52

Please sign in to comment.