rust-lang / rust-lang/rust

rust compiler suggests to add lifetime to macro: `#'static[...]`

Open
#131,107 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics C-bug D-invalid-suggestion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

https://github.com/Anatoly03/Netz/tree/bf8c6917b68c70cc0677b540402c4d64707670bc/util-parser

(The token stream generated by the broken macro is logged into the console.)

Current output
error[E0106]: missing lifetime specifier
 --> util-parser/tests/whitespace.rs:5:5
  |
5 |     #[grammar(~)]
  |     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
  = note: this error originates in the attribute macro `grammar` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
  |
5 |     #'static [grammar(~)]
  |      +++++++
help: instead, you are more likely to want to return an owned value
  |
5 |     String
  |
Desired output
  [expand macro code with broken lines displayed]

error[????]: could not compile macro `grammar` due to ... errors
Rationale and extra context

Image

Other cases

No response

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

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

Reproduce the diagnostic with the linked Netz util-parser tree and Rust 1.81.0, starting from the grammar attribute macro and its logged token stream. Done means broken macro expansion lines are displayed and the misleading lifetime suggestion is replaced by a macro-compilation error.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.