Closed
Description
Reproduced on versions:
rustc 1.29.0-nightly (12ed235ad 2018-07-18)
rustc 1.29.0-nightly (9fd3d7899 2018-07-07)
rustc 1.27.0 (3eda71b00 2018-06-19)
Isolated example to reproduce:
use std::ops::Deref;
struct Error {}
struct State {}
struct StateDeref { inner: State }
impl Deref for StateDeref {
type Target = State;
fn deref(&self) -> &Self::Target { &self.inner }
}
fn get_state() -> Result<StateDeref, Error> { Err(Error {}) }
fn need_ref_state_from(state: &State) -> bool { true }
fn state_info() -> Result<bool, Error> { Ok(need_ref_state_from(&get_state()?)) }
Actual error:
error[E0308]: try expression alternatives have incompatible types
--> src/main.rs:16:66
|
16 | fn state_info() -> Result<bool, Error> { Ok(need_ref_state_from(&get_state()?)) }
| ^^^^^^^^^^^^
| |
| expected struct `State`, found struct `StateDeref`
| help: try wrapping with a success variant: `Ok(get_state()?)`
|
= note: expected type `State`
found type `StateDeref`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
Mentioned suggestion about "wrap into Ok
" is incorrect at all. There we should deref the value from the get_state()?
.
Expected error: (something like this)
...
expected struct `State`, found struct `StateDeref`
help: try re-dereference(?) with a success variant: `&*get_state()?`