Why does the never type not implement all traits?

116 points AdmiralQuokka 49 comments

todo!() is often used to mark an unfinished function. It's convenient, because it silences the compiler about mismatched return types. However, that doens't work if the return type is an "impl trait". Why not though? There wouldn't be any harm in pretending the never type implements all traits, right? Can't call non-existant methods on values that will never exist, right?

Is there a fundamental reason why this cannot be or is it just a current compiler limitation?

Example:

) -> impl Iterator<Item = (usize, usize)> {
     └─`!` is not an iterator
       the trait `std::iter::Iterator` is not implemented for `!`