Skip to content

Poor diagnostic: "length depth must be less than 0", but it mustn't #99060

New issue

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

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

Already on GitHub? # to your account

Closed
jonas-schievink opened this issue Jul 8, 2022 · 2 comments · Fixed by #99355
Closed

Poor diagnostic: "length depth must be less than 0", but it mustn't #99060

jonas-schievink opened this issue Jul 8, 2022 · 2 comments · Fixed by #99355
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) F-macro_metavar_expr `#![feature(macro_metavar_expr)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Jul 8, 2022

#![feature(macro_metavar_expr)]

macro_rules! metavar {
    ( $i:expr ) => {
        ${length(0)}
    };
}

const _: i32 = metavar!(0);

errors with:

error: length depth must be less than 0
 --> src/main.rs:5:10
  |
5 |         ${length(0)}
  |          ^^^^^^^^^^^

However, passing -1 as the depth is rejected with:

error: meta-variable expression depth must be a literal
 --> src/main.rs:5:11
  |
5 |         ${length(-1)}
  |           ^^^^^^

error: expected expression, found `$`
  --> src/main.rs:5:9
   |
5  |         ${length(-1)}
   |         ^ expected expression
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) requires-nightly This issue requires a nightly compiler in some way. F-macro_metavar_expr `#![feature(macro_metavar_expr)]` labels Jul 8, 2022
@compiler-errors
Copy link
Member

Am I mistaken or is this fixed on nightly?

@jonas-schievink
Copy link
Contributor Author

Ah, it looks like you have to invoke the macro for the error to happen. Updated the example to reflect that.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) F-macro_metavar_expr `#![feature(macro_metavar_expr)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants