Skip to content

Commit ac4ea52

Browse files
Add test for useless_anonymous_reexport lint
1 parent 2df7770 commit ac4ea52

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,4 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
510510
lint_opaque_hidden_inferred_bound_sugg = add this bound
511511
512512
lint_useless_anonymous_reexport = useless anonymous re-export
513-
.note = only anonymous re-exports of traits are useful, this is {$article} `${desc}`
513+
.note = only anonymous re-exports of traits are useful, this is {$article} `{$desc}`

compiler/rustc_lint/src/lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ pub struct UnusedAllocationMutDiag;
15331533

15341534
#[derive(LintDiagnostic)]
15351535
#[diag(lint_useless_anonymous_reexport)]
1536+
#[note]
15361537
pub struct UselessAnonymousReexportDiag {
15371538
pub article: &'static str,
15381539
pub desc: &'static str,

tests/ui/lint/anonymous-reexport.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![deny(useless_anonymous_reexport)]
2+
#![crate_type = "rlib"]
3+
4+
mod my_mod {
5+
pub trait Foo {}
6+
pub type TyFoo = dyn Foo;
7+
pub struct Bar;
8+
pub type TyBar = Bar;
9+
}
10+
11+
pub use self::my_mod::Foo as _;
12+
pub use self::my_mod::TyFoo as _;
13+
pub use self::my_mod::Bar as _; //~ ERROR
14+
pub use self::my_mod::TyBar as _; //~ ERROR
15+
#[allow(unused_imports)]
16+
use self::my_mod::TyBar as _;
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: useless anonymous re-export
2+
--> $DIR/anonymous-reexport.rs:13:1
3+
|
4+
LL | pub use self::my_mod::Bar as _;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/anonymous-reexport.rs:1:9
9+
|
10+
LL | #![deny(useless_anonymous_reexport)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: useless anonymous re-export
14+
--> $DIR/anonymous-reexport.rs:14:1
15+
|
16+
LL | pub use self::my_mod::TyBar as _;
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)