`unreachable_patterns` not emitted on macros generated by another crate's macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two-crate example using crate_a/src/lib.rs and crate_b/src/main.rs, then compare it with the case where create_pats! is defined in crate_b. Trace how the unreachable_patterns lint is handled for macros generated across crates. Done means the pat_b!() arm is diagnosed as unreachable when the lint is denied.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100