Why doesn't rust warn about this missing match / typo?

⚓ Rust    📅 2025-05-04    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 109 days ago. The information described in this article may have changed.

This bug caused data corruption for me. It's really nasty, and I can not believe it compiles. Even asking for "help" on SO about this has given me no answers as to why it even compiles.

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused)]

use PlayerItemTypes::*;

pub enum PlayerItemTypes {
    MAGIC_LAMP,
    DEATH_DOLL,
    SCROLL_OF_EXIT,
}

impl PlayerItemTypes {
    pub fn GetDisplayName(&self) -> &str {
        return match (self) {
            //MAGIC_LAMP     => "Magic Lamp", // should warn about non-exhaustive
            DEATH_DOLL     => "Death Doll",
            SCROLL_EXIT    => "Scroll of Exit",
        }
    }
}

fn main() {

}

9 posts - 4 participants

Read full topic

🏷️ rust_feed