Open sergio-ivanuzzo opened 2 years ago
This is caught by the allow-by-default meta_variable_misuse
lint (playground):
warning: meta-variable repeats with different Kleene operator
--> src/lib.rs:9:31
|
5 | ( $( $x:expr ),* ) => {
| - expected repetition
...
9 | temp_vec.push($x);
| ^^
10 | )? // this one works the same as below
| - conflicting repetition
|
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(meta_variable_misuse)]
| ^^^^^^^^^^^^^^^^^^^^
See also #61053, the original tracking issue for the lint, and #95943, which contains a discussion on why this lint is allow-by-default.
This is caught by the allow-by-default
meta_variable_misuse
lint (playground):warning: meta-variable repeats with different Kleene operator --> src/lib.rs:9:31 | 5 | ( $( $x:expr ),* ) => { | - expected repetition ... 9 | temp_vec.push($x); | ^^ 10 | )? // this one works the same as below | - conflicting repetition | note: the lint level is defined here --> src/lib.rs:1:9 | 1 | #![warn(meta_variable_misuse)] | ^^^^^^^^^^^^^^^^^^^^
See also #61053, the original tracking issue for the lint, and #95943, which contains a discussion on why this lint is allow-by-default.
So this lint supposed to be used only in debug purposes right ?
As far as I'm aware, you can leave it turned on as long as you're willing to accept a few false positives. For what its worth, I don't remember encountering any false positives, but this lint has saved me a bit of trouble several times.
Some discussion happened here: Zulip | #wg-macros > Repetition operator mismatch between transcriber and matcher.
I tried this code:
I expected to see this happen: macros expression that use "?" should return error
Instead, this happened: both macros works in same way
Meta
rustc --version --verbose
: