`unreachable_patterns` not emitted on macros generated by another crate's macro
オープン
まだ誰も着手していません。
A-diagnostics
A-lints
A-patterns
C-bug
L-false-negative
L-unreachable_patterns
needs-triage
T-compiler
- 主要言語
- Rust
- スター
- 119k
- フォーク
- 16.2k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず crate_a/src/lib.rs と crate_b/src/main.rs を使って 2 つの crate の例を再現し、次に create_pats! が crate_b で定義されている場合と比較します。crate をまたいで生成されたマクロに対して unreachable_patterns lint がどのように処理されるかを追跡します。lint を deny したときに pat_b!() アームが到達不能として診断されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 50/100