I don't understand why this compiles with the type value of "typpo" in the Match statement.
I am assuming it is because the variable "typpo" is acting as the "_" catch-all variable.
// This stub file contains items which aren't used yet; feel free to remove this module attribute // to enable stricter warnings. #![allow(unused)] /// various log levels #[derive(Clone, PartialEq, Debug)] pub enum LogLevel { Info, Warning, Error, } /// primary function for emitting logs pub fn log(level: LogLevel, message: &str) -> String { match level { LogLevel::Info => info(&message), LogLevel::Warning => warn(&message), typpo => error(&message), } } pub fn info(message: &str) -> String { format!("[INFO]: {}", &message) } pub fn warn(message: &str) -> String { format!("[WARNING]: {}", &message) } pub fn error(message: &str) -> String { format!("[ERROR]: {}", &message) } However, if this is true, then why does this also compile, where we have multiple catch all variables? Why does it not warn of an unused code path at "typpo", since the variable above "typppo" already catches all?
// This stub file contains items which aren't used yet; feel free to remove this module attribute // to enable stricter warnings. #![allow(unused)] /// various log levels #[derive(Clone, PartialEq, Debug)] pub enum LogLevel { Info, Warning, Error, } /// primary function for emitting logs pub fn log(level: LogLevel, message: &str) -> String { match level { LogLevel::Info => info(&message), typppo => warn(&message), typpo => error(&message), } } pub fn info(message: &str) -> String { format!("[INFO]: {}", &message) } pub fn warn(message: &str) -> String { format!("[WARNING]: {}", &message) } pub fn error(message: &str) -> String { format!("[ERROR]: {}", &message) }
typpolater. You can read more about it in the book chapter 6#![allow(unused)]. Remove it and compile again. The compiler will give you a very good hint.#![allow(unused)]but I did it in a web playground on exercism.org, so it didn't show WARNINGS. That's why I assumed it compiled without warning, but I believe there would have been a warning if I could have seen them. Thank you.