rust-lang / rust-lang/rust

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

Đang mở
#158,366 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

A-diagnostics A-lints A-patterns C-bug L-false-negative L-unreachable_patterns needs-triage T-compiler
Ngôn ngữ chính
Rust
Star
119k
Fork
16.2k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ gồm hai crate bằng crate_a/src/lib.rs và crate_b/src/main.rs, sau đó so sánh với trường hợp create_pats! được định nghĩa trong crate_b. Theo dõi cách lint unreachable_patterns được xử lý đối với các macro được tạo qua các crate. Hoàn tất khi nhánh pat_b!() được chẩn đoán là không thể đạt tới khi lint bị từ chối.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
50/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.