Skip to content

Commit 7654c22

Browse files
Don't warn when underscore is passed to macro
1 parent 18fcdf3 commit 7654c22

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13411341
}
13421342
if ident.name == kw::Underscore
13431343
&& !matches!(item.vis.kind, VisibilityKind::Inherited)
1344+
&& ident.span.eq_ctxt(item.vis.span)
13441345
{
13451346
self.lint_buffer.buffer_lint(
13461347
UNUSED_VISIBILITIES,

tests/ui/lint/unused-visibilities.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,21 @@
99
const _: () = {};
1010
//~^WARN visibility qualifiers have no effect on `const _` declarations
1111

12+
macro_rules! foo {
13+
() => {
14+
const _: () = {};
15+
//~^WARN visibility qualifiers have no effect on `const _` declarations
16+
};
17+
}
18+
19+
foo!();
20+
21+
macro_rules! bar {
22+
($tt:tt) => {
23+
pub const $tt: () = {};
24+
};
25+
}
26+
27+
bar!(_);
28+
1229
fn main() {}

tests/ui/lint/unused-visibilities.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,21 @@ pub const _: () = {};
99
pub(self) const _: () = {};
1010
//~^WARN visibility qualifiers have no effect on `const _` declarations
1111

12+
macro_rules! foo {
13+
() => {
14+
pub const _: () = {};
15+
//~^WARN visibility qualifiers have no effect on `const _` declarations
16+
};
17+
}
18+
19+
foo!();
20+
21+
macro_rules! bar {
22+
($tt:tt) => {
23+
pub const $tt: () = {};
24+
};
25+
}
26+
27+
bar!(_);
28+
1229
fn main() {}

tests/ui/lint/unused-visibilities.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,16 @@ warning: visibility qualifiers have no effect on `const _` declarations
1616
LL | pub(self) const _: () = {};
1717
| ^^^^^^^^^ help: remove the qualifier
1818

19-
warning: 2 warnings emitted
19+
warning: visibility qualifiers have no effect on `const _` declarations
20+
--> $DIR/unused-visibilities.rs:14:9
21+
|
22+
LL | pub const _: () = {};
23+
| ^^^ help: remove the qualifier
24+
...
25+
LL | foo!();
26+
| ------ in this macro invocation
27+
|
28+
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
30+
warning: 3 warnings emitted
2031

0 commit comments

Comments
 (0)