pub static DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK: &'static Lint
Expand description
The dependency_on_unit_never_type_fallback
lint detects cases where code compiles with
never type fallback being ()
, but will stop compiling with fallback being !
.
§Example
ⓘ
#![deny(dependency_on_unit_never_type_fallback)]
fn main() {
if true {
// return has type `!` which, is some cases, causes never type fallback
return
} else {
// the type produced by this call is not specified explicitly,
// so it will be inferred from the previous branch
Default::default()
};
// depending on the fallback, this may compile (because `()` implements `Default`),
// or it may not (because `!` does not implement `Default`)
}
{{produces}}
§Explanation
Due to historic reasons never type fallback was ()
, meaning that !
got spontaneously
coerced to ()
. There are plans to change that, but they may make the code such as above
not compile. Instead of depending on the fallback, you should specify the type explicitly:
if true {
return
} else {
// type is explicitly specified, fallback can't hurt us no more
<() as Default>::default()
};