rust-lang / rust-lang/rust

Bad `+ use<>` suggestion in nested macro_rules

Open
#133,769 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-edition-2024 A-lints A-macros A-suggestion-diagnostics C-bug D-edition D-invalid-suggestion E-needs-mcve I-edition-triaged L-impl_trait_overcaptures T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Failure in migrating rocket 0.5.1 to 2024 due to the _typed_stream macro getting modified to:

macro_rules! _typed_stream {
    ($S:ident, $($t:tt)*) => (
        $crate::__typed_stream! {
            $crate::response::stream::$S,
            $crate::response::stream::stream,
            $crate::futures::stream::Stream,
            $($t)*
        } + use<'b>
    )
}

where that is invalid syntax. Just removing the + use<'b> seems to make things work?

Unraveling this to a minimal example seems to be quite a bit of work since there are many layers of macros involved. This could also just be an issue with the rocket_codegen proc-macro respanning, but I did not unravel it that far.

Meta
rustc 1.85.0-nightly (5e1440ae5 2024-12-01)
binary: rustc
commit-hash: 5e1440ae514d98ddfcbf1607acb64d41e07ef616
commit-date: 2024-12-01
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

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 by reproducing the report with rustc 1.85.0-nightly and Rocket's _typed_stream macro in core/lib/src/response/stream/mod.rs:292-301. Trace the nested macro expansion and the rocket_codegen proc-macro respanning to determine why + use<'b> is suggested; done means the expansion no longer produces invalid syntax.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.