TypeId constant in patterns has confusing error message

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

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

Hướng nghiên cứu

Start with the pattern-matching diagnostic path and the related pull request #166205 mentioned in the issue. Reproduce the example with the reported nightly compiler, then trace why matching the TypeId constant produces the raw-pointer unpredictability error instead of a StructuralPartialEq error. Done when the diagnostic reports the expected reason and relevant compiler tests cover the case.

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

Mô tả

A-diagnostics A-patterns C-bug D-incorrect S-has-mcve T-compiler

I tried this code:

use std::any::TypeId;

const abc: TypeId = TypeId::of::<i32>();

fn main() {
    match TypeId::of::<i32>() {
        abc => {},
        _ => {},
    }
}

I expected to see this happen: It gives an error mentioning that TypeId is not StructuralPartialEq

Instead, this happened: I get an error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon

Meta

rustc --version --verbose:

rustc 1.102.0-nightly (5df8c02af 2026-11-16)
binary: rustc
commit-hash: 5df8c02afdf6b882bc301442cea70f026e3d3974
commit-date: 2026-11-16
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.5

From what I can tell, it seems to think that TypeId is a function pointer, but not other structs. Not related to the provenience either as copying the data field from TypeId into a local struct doesn't reproduce. I was told that this issue may be relevant as well.

Ngôn ngữ chính
Rust
Star
123k
Fork
16.6k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
532

Chuẩn bị môi trường

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.

Issue khác của rust-lang/rust

Tất cả issue của rust-lang/rust

Issue tương tự

Thêm issue về Rust

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.