Closed
Description
use std::fmt;
trait CargoCacheError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}
impl fmt::Display for dyn CargoCacheError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.fmt(f)
}
}
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum CacheError<'a> {
SomeCache(&'a str), // WARNING HERE
NoCache, // BUT NOT HERE
}
impl fmt::Display for CacheError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Self::NoCache => write!(f, ""),
Self::SomeCache(string) => write!(f, "oh no, {}", string),
}
}
}
pub fn main() {}
I expected to see this happen:
There should be a warning that CacheError::SomeCache
as well as CacheError::NoCache
are never constructed.
Instead, this happened:
Instead, there only was a warning about dead code for CacheError::NoCache
warning: variant is never constructed: `SomeCache`
--> src/main.rs:27:5
|
27 | SomeCache(&'a str), // WARNING HERE
| ^^^^^^^^^^^^^^^^^^
rustc --version --verbose
:
rustc 1.48.0-nightly (6af1bdda5 2020-09-15)
binary: rustc
commit-hash: 6af1bdda54abc9e919fc1137411dfc4311e05649
commit-date: 2020-09-15
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0