Skip to content

Negative numbers are not correctly identified as literals inside macros #70050

Closed
@connorskees

Description

@connorskees

Negative numbers are no longer parsed as literals when used as a parameter to a macro inside a macro. This appears to be a regression from stable to nightly.

According to cargo-bisect-rustc, #69023 is responsible (thanks to @jebrosen for helping with this on the Rust discord)
Specifically, the changes to this function look suspicious.

The below fails to compile:

macro_rules! foo {
    ($a:literal) => {
        bar!($a)
    }
}

macro_rules! bar {
    ($b:literal) => {}
}

fn main() {
    // fails on nightly, but not stable
    foo!(-2);
    // doesn't fail
    bar!(-2);
}

with the following error on nightly-2020-02-14,

~ >cargo b
error: no rules expected the token `-2`
  --> src\main.rs:3:14
   |
3  |         bar!($a)
   |              ^^ no rules expected this token in macro call
...
7  | macro_rules! bar {
   | ---------------- when calling this macro
...
12 |     foo!(-2);
   |     --------- in this macro invocation
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions