Don't warn when underscore is passed to macro

This commit is contained in:
Jules Bertholet 2025-12-03 11:37:54 -05:00
parent 4cc2f952e4
commit 6b5da2f177
No known key found for this signature in database
GPG key ID: 32034DAFC38C1BFC
4 changed files with 47 additions and 1 deletions

View file

@ -1349,6 +1349,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
if ident.name == kw::Underscore
&& !matches!(item.vis.kind, VisibilityKind::Inherited)
&& ident.span.eq_ctxt(item.vis.span)
{
self.lint_buffer.buffer_lint(
UNUSED_VISIBILITIES,

View file

@ -9,4 +9,21 @@
const _: () = {};
//~^WARN visibility qualifiers have no effect on `const _` declarations
macro_rules! foo {
() => {
const _: () = {};
//~^WARN visibility qualifiers have no effect on `const _` declarations
};
}
foo!();
macro_rules! bar {
($tt:tt) => {
pub const $tt: () = {};
};
}
bar!(_);
fn main() {}

View file

@ -9,4 +9,21 @@ pub const _: () = {};
pub(self) const _: () = {};
//~^WARN visibility qualifiers have no effect on `const _` declarations
macro_rules! foo {
() => {
pub const _: () = {};
//~^WARN visibility qualifiers have no effect on `const _` declarations
};
}
foo!();
macro_rules! bar {
($tt:tt) => {
pub const $tt: () = {};
};
}
bar!(_);
fn main() {}

View file

@ -16,5 +16,16 @@ warning: visibility qualifiers have no effect on `const _` declarations
LL | pub(self) const _: () = {};
| ^^^^^^^^^ help: remove the qualifier
warning: 2 warnings emitted
warning: visibility qualifiers have no effect on `const _` declarations
--> $DIR/unused-visibilities.rs:14:9
|
LL | pub const _: () = {};
| ^^^ help: remove the qualifier
...
LL | foo!();
| ------ in this macro invocation
|
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 3 warnings emitted