Closed
Description
Working on #41414, I found this error that surprised me:
#![feature(try_trait)]
fn main() {
let my_string = "hello".to_string();
let _x: Result<&str, i32> = {
std::ops::Try::from_ok(&my_string)
//~^ type mismatch resolving `<std::result::Result<&str, i32> as std::ops::Try>::Ok == &std::string::String`
};
}
I'd expected that it'd work, since the trait method is -> Self
, and the result of the block is fully constrained, and writing it this way of course works:
<Result<&str, i32> as std::ops::Try>::from_ok(&my_string)
Of course, this may well just be a normal "mixing coercions and inference is annoying" case that people who understand inference wouldn't have expected to work 😅