
Description
Heya,
I'm currently learning rust through a small systems-related project, with a knowledgeable mentor ( @GuillaumeGomez ) ;)
When (badly) attempting to match over the Result<EnumType, String> returned by one of my functions, I only made a match explicit for one Ok
case, and was expecting to have one kitchen-sink case to catch all other cases (This was aimed at testing).
The error I got rightly claimed that I was using incompatible types, but did not make it clear that I was either missing some potential cases (Ok over some other types of my enum) .
I do not know whether this would be easy or feasible, but it could be nice to have a suggestion pointing at the potential error that the match may deserve to be more detailed.
Here is a sample test code:
use std::fs::{self,File};
use std::net::{self,TcpStream,TcpListener};
enum FdImplementor {
File(File),
TcpStream(TcpStream),
TcpListener(TcpListener),
}
fn do_smthg() -> Result<FdImplementor, String> {
Ok(FdImplementor::File(fs::File::create("/tmp/pathtest.txt").map_err(|_| "failed to create file")?))
}
fn test() -> Result<bool, String> {
match do_smthg() {
Ok(FdImplementor::File(file)) => Ok(true),
e => e
}
}
fn main() {
test();
}
And the error:
rustc 1.13.0 (2c6933acc 2016-11-07)
error[E0308]: match arms have incompatible types
--> <anon>:15:5
|
15 | match do_smthg() {
| ^ expected bool, found enum `FdImplementor`
|
= note: expected type `std::result::Result<bool, std::string::String>`
= note: found type `std::result::Result<FdImplementor, std::string::String>`
note: match arm with an incompatible type
--> <anon>:17:14
|
17 | e => e
| ^
error: aborting due to previous error