Skip to content

single_range_in_vec_init wrongly unmangles macros #16044

@profetia

Description

@profetia

Summary

single_range_in_vec_init wrongly unmangles macros in the range expression

Reproducer

I tried this code:

    macro_rules! as_i32 {
        ($x:expr) => {
            $x as i32
        };
    }

    let input = vec![0..as_i32!(10)];

I expected to see this happen:

help: if you wanted a `Vec` that contains the entire range, try
   |
12 -     let input = vec![0..as_i32!(10)];
12 +     let input = (0..as_i32!(10)).collect::<std::vec::Vec<i32>>();

Instead, this happened:

help: if you wanted a `Vec` that contains the entire range, try
   |
12 -     let input = vec![0..as_i32!(10)];
12 +     let input = (0..$x as i32).collect::<std::vec::Vec<i32>>();

Version

rustc 1.93.0-nightly (d5419f1e9 2025-10-30)
binary: rustc
commit-hash: d5419f1e97b90741d51841f800d3c697c662567d
commit-date: 2025-10-30
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions