You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::fmt::Display;use std::fmt::Error;use std::fmt::Formatter;structA{s:Option<String>,}implDisplayforA{fnfmt(&self,f:&mutFormatter) -> Result<(),Error>{matchself.s{// This is either Ok(()) or Err(_)Some(ref s) => write!(f, "{}", s)?,// This is obviously Ok(())None => Ok(()),}}}
Error message:
error[E0308]: match arms have incompatible types
--> tests/src/main.rs:13:28
|
13 | Some(ref s) => write!(f, "{}", s)?,
| ^^^^^^^^^^^^^^^^^^^
||| expected enum `std::result::Result`, found ()
| match arm with an incompatible type|
= note: expected type`std::result::Result<(), std::fmt::Error>` found type`()`error: aborting due to previous errorerror: Could not compile `tests`.
I think the work around looks... weird, where one arm returns Result<>, the other returns (). While the first code looks pretty clear: both arms return Result<>.
My
rustc
version:1.25.0
.Currently this doesn't compile:
Error message:
Work around:
I think the work around looks... weird, where one arm returns
Result<>
, the other returns()
. While the first code looks pretty clear: both arms returnResult<>
.Perhaps #24157 is related, I'm not sure.
Thank you,
The text was updated successfully, but these errors were encountered: