tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.19k stars 677 forks source link

Exaustiveness checking for LevelInner leaks through public API #2871

Open udoprog opened 5 months ago

udoprog commented 5 months ago

I'm not sure whether or not this is intended, but given the separation between Level and LevelInner I'll just report it anyway.

If you set up a match over Level, the following counts as an exhaustive match:

fn level(level: tracing::Level) -> &'static str {
    match level {
        tracing::Level::ERROR => "error",
        tracing::Level::WARN => "warn",
        tracing::Level::INFO => "info",
        tracing::Level::DEBUG => "debug",
        tracing::Level::TRACE => "trace",
    }
}

This is a potential compatibility issue if additional variants are added or if the internals of Level are changed (e.g. something that can not be exhaustively matched over). Rust seems to "peek through" the private enum that the constant is composed out of when checking that the pattern is exhaustive, even with private enums like LevelInner.

Version

0.1.40

hawkw commented 5 months ago

yeah, this is a known issue and...it's really unfortunate. we're just not going to add new levels ever, i guess.

which, honestly, we probably weren't going to do in the first place, so i don't know if trying to make it non-exhaustive was actually worth the effort.