Skip to content

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

Closed
@jonas-schievink

Description

@jonas-schievink
#![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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)F-macro_metavar_expr`#![feature(macro_metavar_expr)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions