-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team
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 😅
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team