When compiling this crate on stable, there are no warnings, but on the latest nightly (15th of February), it finds this unreachable pattern which does not seem right:
warning: unreachable pattern
--> src/token_stream.rs:47:21
|
47 | Err(error) => Err(error)
| ^^^^^^^^^^
|
= note: #[warn(unreachable_patterns)] on by default
I don't think it is a false positive. The error type in question, ParsingError, is an enum with no variants, which means it is uninhabitable. By declaring the receiver field that way, it's saying that errors are not possible. So that arm is really unreachable.
This type of analysis became possible recently after @canndrew's work with #![feature(never_type)].
@durka That's smart! Maybe this particular case could have a more explicit error?
Yeah, help: 'error' is of type 'ParsingError', which is uninhabitable would be nice. @canndrew is that information available when the warning is generated?
@durka Not currently, but I think it could be generated and passed-up to where the warning is generated easily enough. I'd like to find out what's happening with this uninhabited patterns stuff first though before doing any more work on it.
Data Point: https://internals.rust-lang.org/t/match-with-identical-branches-why/5474/7
This lint's message can be confusing to newcomers. It should definitely contain more information than the lint name. Maybe lints should have something like clippy's lint-docs (which are modeled after the error code docs).
I just ran into this issue. MWE (playground):
fn main() {
return;
if true {
println!("");
}
}
prints:
warning: unreachable expression
--> src/main.rs:3:5
|
3 | / if true {
4 | | println!("");
5 | | }
| |_____^
|
= note: #[warn(unreachable_code)] on by default
but it does not explain why. This case is obviously trivial, but in a program with macros calling macros all the way down the information of "which exact source locations make a particular statement unreachable" can significantly improve productivity.
Most helpful comment
Data Point: https://internals.rust-lang.org/t/match-with-identical-branches-why/5474/7
This lint's message can be confusing to newcomers. It should definitely contain more information than the lint name. Maybe lints should have something like clippy's lint-docs (which are modeled after the error code docs).