Skip to content

Hygiene break in macros involving string containing single quote #50061

Closed
@dtolnay

Description

@dtolnay

This is minimized from the dramatic forum thread The latest nightly compiler has broken macros. The following code is fine in nightly-2018-04-12 but breaks with nightly-2018-04-15. Oddly, lots of minor perturbations make it succeed. For example remove the two @ characters and it works. Or remove the single quote in the string and it works.

#![feature(proc_macro, generators)]

extern crate futures_await as futures;
use futures::prelude::*;

macro_rules! j {
    (@ $v:tt) => {
        let _ = $v;
    };

    (# $v:tt) => {
        j!(@ $v);
    };
}

#[async]
fn test() -> Result<(), ()> {
    let s = "12'3";
    j!(# s);
    Ok(())
}
$ cargo +nightly-2018-04-12 build
   Compiling l v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 0.17 secs
$ cargo +nightly-2018-04-15 build
   Compiling l v0.1.0
error[E0425]: cannot find value `s` in this scope
 --> src/lib.rs:8:17
  |
8 |         let _ = $v;
  |                 ^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

@alexcrichton

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions