TypeId constant in patterns has confusing error message

Aperta
#166,630 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

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.

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

Descrizione

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.

Lingua principale
Rust
Stelle
123k
Fork
16.6k
Merge medio
2g 17h
PR unite (30g)
532

Preparare l'ambiente

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.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.