rust-lang / rust-lang/rust

`unreachable_patterns` not emitted on macros generated by another crate's macro

Aperta
#158,366 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

A-diagnostics A-lints A-patterns C-bug L-false-negative L-unreachable_patterns needs-triage T-compiler
Lingua principale
Rust
Stelle
119k
Fork
16.2k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

I tried this code:

crate_a:

#[macro_export]
macro_rules! create_pats {
    () => {
        macro_rules! pat_a {
            () => {
                _
            };
        }
        macro_rules! pat_b {
            () => {
                _
            };
        }
    };
}

crate_b:

use crate_a::create_pats;

create_pats!();

#[deny(unreachable_patterns)]
fn demo(value: u8) -> i32 {
    match value {
        pat_a!() => 42,
        pat_b!() => 24,
    }
}

I expected to see this happen: unreachable_pattern error

error: unreachable pattern
  --> crate_a/src/lib.rs:11:17
   |
 6 |                 _
   |                 - matches any value
...
11 |                 _
   |                 ^ no value can reach this

  --> crate_b/src/main.rs:9:17
 9 |         pat_b!() => 24,
   |         -------- in this macro invocation
   |
note: the lint level is defined here
  --> src/main.rs:5:8
   |
 5 | #[deny(unreachable_patterns)]
   |        ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `pat_b` (in Nightly builds, run with -Z macro-backtrace for more info)

Instead, this happened: successful compilation

When the create_pats! macro is defined in crate_b, the lint is emitted as expected.

Meta

rustc --version --verbose:

rustc 1.98.0-nightly (b30f3df3b 2026-06-11)
binary: rustc
commit-hash: b30f3df3ba3c4c9de2f58f1a75dd9500b79b3f8d
commit-date: 2026-06-11
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6

@rustbot label +A-diagnostics +A-lints +A-patterns +L-unreachable_patterns +T-compiler +L-false-negative

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'esempio con due crate usando crate_a/src/lib.rs e crate_b/src/main.rs, quindi confrontalo con il caso in cui create_pats! è definito in crate_b. Traccia come viene gestito il lint unreachable_patterns per le macro generate tra crate. Il lavoro è completo quando il ramo pat_b!() viene diagnosticato come irraggiungibile quando il lint è negato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.