rust-lang / rust-lang/rust

inconsistent `stringify!`

Open
#140,060 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-pretty C-enhancement T-compiler T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#[macro_export]
macro_rules! reproduce_macro {
    () => {{
        [stringify!(a::b), stringify!(&a)]
    }};
}

#[test]
pub fn reproduce() {
    let expected = [stringify!(a::b), stringify!(&a)];
    assert_eq!(expected, ["a::b", "&a"]);

    let actual = reproduce_macro!();
    assert_eq!(actual, ["a :: b", "& a"]);
}

I expected to see this happen: explanation

actual equal expected

Instead, this happened: explanation

actual not equal expected

$ cargo test -r
       Fresh reproduce v0.1.0 (/tmp/reproduce)
    Finished `release` profile [optimized] target(s) in 0.00s
     Running `/tmp/reproduce/target/release/deps/reproduce-7e181f6f7847a00f`

running 1 test
test reproduce ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests reproduce
     Running `/home/vscode/.rustup/toolchains/nightly-2025-04-14-x86_64-unknown-linux-gnu/bin/rustdoc --edition=2021 --crate-type lib --color auto --crate-name reproduce --test src/lib.rs --test-run-directory /tmp/reproduce -L dependency=/tmp/reproduce/target/release/deps -L dependency=/tmp/reproduce/target/release/deps --extern reproduce=/tmp/reproduce/target/release/deps/libreproduce-c271e11eea147c9e.rlib -C embed-bitcode=no --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' --error-format human`

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Meta

rustc --version --verbose:

<version>
channel = "nightly-2025-04-14"
Backtrace

<backtrace>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided reproduce_macro! test and run it with cargo test to confirm the differing stringify! output for direct and macro-expanded inputs. Trace the compiler's stringify! handling for these two entry points, then add or update a regression test showing consistent spacing and verify the reproduction passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.