The notion of types-in-patterns came up twice, afaict independently, within 8 hours of each other on Saturday:
(I don’t actually intend to propose anything right now; just thought it an interesting area to explore.)
For example, I rather like this:
match "4".parse() {
Ok(x: u16) => ...,
Err(e) => ...,
}
Compared to ::<u16> or let r: Result<u16, _> =, that feels more direct and less noisy/sigily.
Interestingly, one can already do a hacky version of that that if parsing a struct:
match "asdf".parse() {
Ok(x @ String {..}) => println!("yup: {}", x),
Err(e) => eprintln!("Nope: {:?}", e),
}
I could also imagine something like this being legal:
fn foo(Wrapping(x: u16)) -> ...
since it fully-specifies the type of the function argument.
Of course, @rkruppe rightly pointed out that this mixes poorly with struct patterns, since : there already has a different meaning.