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 !.


fn main() {
    if true {
        // return has type `!` which, is some cases, causes never type fallback
    } else {
        // the type produced by this call is not specified explicitly,
        // so it will be inferred from the previous branch
    // depending on the fallback, this may compile (because `()` implements `Default`),
    // or it may not (because `!` does not implement `Default`)



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 {
} else {
    // type is explicitly specified, fallback can't hurt us no more
    <() as Default>::default()

See Tracking Issue for making ! fall back to !.