The await syntax struggles with fitting the for loop in any way. I think I have a diagnosis why, and a potential solution. solution still needs work.
The core of the problem is that the current for loop syntax is:
for PATTERN in EXPR {
}
and awaiting (and error handling with ?) is something that applies only to expressions, not patterns. The only EXPR that happens to be in the for loop is not the one we want awaiting/error handling to apply to.
So all the syntaxes struggle, because there’s literally no place for them. The only current options are to use expression-specific syntax as if it was a pattern (crates syntactical special cases), apply expression syntax to some implied/imaginary expression, or put it in a place where it looks like it applies to the wrong expression (either the stream or the for loop as a whole).
So the solution is to put another EXPR in the for loop synatax.
Currently Rust has two places where PATTERN and EXPR work together:
if/while let PATTERN = EXPR {}
and
match … {
PATTERN => EXPR
}
The difference is that in let the EXPR is evaluated first, then assigned to the pattern. In match the PATTERN is evaluated first, then used in EXPR.
(I’m using try!() instead of any of the await syntaxes to avoid suggesting any particular choice)
for let x = try!(/*how do you refer to an element here???*/) in stream {}
for x => try!(x) in stream {
/* how to refer to the result of try!(x)??? */
}
but both are still missing having a second pattern or some other way to refer to the missing element.
However, maybe that’s still a step forward, because presence of the second EXPR makes the for loop syntax orthogonal with other features. It’s automatically compatible with any await syntax, any error handling syntax, user macros, etc.
