Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems like quantificator symbol do not works correctly in macros expression #103256

Open
sergio-ivanuzzo opened this issue Oct 19, 2022 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-macros Working group: Macros

Comments

@sergio-ivanuzzo
Copy link

I tried this code:

#[macro_export]
macro_rules! vec2 {
    ( $( $x:expr ),* ) => {
        {
            let mut temp_vec = Vec::new();
            $(
                temp_vec.push($x);
            )? // this one works the same as below
            temp_vec
        }
    };
}

#[macro_export]
macro_rules! vec3 {
    ( $( $x:expr ),* ) => {
        {
            let mut temp_vec = Vec::new();
            $(
                temp_vec.push($x);
            )* // this one works the same as above
            temp_vec
        }
    };
}

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:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-pc-windows-msvc
release: 1.60.0
LLVM version: 14.0.0

@sergio-ivanuzzo sergio-ivanuzzo added the C-bug Category: This is a bug. label Oct 19, 2022
@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Oct 19, 2022

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.

@sergio-ivanuzzo
Copy link
Author

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 ?

@PatchMixolydic
Copy link
Contributor

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.

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@dtolnay dtolnay added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Dec 15, 2023
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-macros Working group: Macros and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Jan 25, 2024
@fmease
Copy link
Member

fmease commented Jan 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-macros Working group: Macros
Projects
None yet
Development

No branches or pull requests

5 participants