forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#117390 - chenyukang:yukang-fix-117284-unused-macro, r=estebank Fix unused variables lint issue for args in macro Fixes rust-lang#117284 r? ````@estebank````
- Loading branch information
Showing
5 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![deny(unused_variables)] | ||
macro_rules! make_var { | ||
($struct:ident, $var:ident) => { | ||
let $var = $struct.$var; | ||
}; | ||
} | ||
|
||
#[allow(unused)] | ||
struct MyStruct { | ||
var: i32, | ||
} | ||
|
||
fn main() { | ||
let s = MyStruct { var: 42 }; | ||
make_var!(s, var); //~ ERROR unused variable: `var` | ||
let a = 1; //~ ERROR unused variable: `a` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error: unused variable: `var` | ||
--> $DIR/issue-117284-arg-in-macro.rs:15:18 | ||
| | ||
LL | make_var!(s, var); | ||
| ^^^ | ||
| | ||
help: `var` is captured in macro and introduced a unused variable | ||
--> $DIR/issue-117284-arg-in-macro.rs:4:13 | ||
| | ||
LL | let $var = $struct.$var; | ||
| ^^^^ | ||
... | ||
LL | make_var!(s, var); | ||
| ----------------- in this macro invocation | ||
note: the lint level is defined here | ||
--> $DIR/issue-117284-arg-in-macro.rs:1:9 | ||
| | ||
LL | #![deny(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the macro `make_var` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: unused variable: `a` | ||
--> $DIR/issue-117284-arg-in-macro.rs:16:9 | ||
| | ||
LL | let a = 1; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_a` | ||
|
||
error: aborting due to 2 previous errors | ||
|