rust-lang/rust

Prevent await from creating a generator

cramertj opened this issue · 8 comments

The await macro implemented in #51580 can be abused to create a generator (e.g. || await!()). This shouldn't be allowed.

Is there an explanation somewhere of why this is necessarily bad?

@BatmanAoD The fact that await!() internally uses yield is an implementation detail which shouldn't be exposed to end users. Eventually we'd like to be able to use async generators (where both yield and await are valid and mean very different things) in order to write Streams.

Ah, okay.

Is there any compelling reason to permit await! inside a closure at all, with any semantics?

@BatmanAoD Non-async closures? No. await shouldn't be allowed outside of async closures, blocks, and functions.

Oh, I didn't notic that the async/await RFC permitted specifying that a closure could be async. Yes, I meant non-async closures.

Inside of async closures, permitting await! as-is shouldn't really be a problem, right?

Should this be tagged as AsyncAwait-Blocker?

Yup!

(but it's also in the group of issues that would be obviously fixed by native syntax)