Skip to content

Generic (lifetime, type, const) parameters are unhygenic #145023

@lolbinarycat

Description

@lolbinarycat

I tried this code:

macro_rules! my_type {
    () => (&'_magic_lifetime T);
}

fn foo<'_magic_lifetime, T>(_x: my_type!()) {}

I expected to see this happen: compile error saying 'magic_lifetime and T are not defined, with a help message about macro hygiene, or at the very least a warning.

Instead, this happened: code compiles successfully with no warning.

Meta

rustc --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-hygieneArea: Macro hygieneA-lifetimesArea: Lifetimes / regionsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions