Skip to content

Nomenclature question: what is the EXPR in for PATTERN in EXPR { } called? #1841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jieyouxu opened this issue Jun 4, 2025 · 1 comment

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Jun 4, 2025

Location

https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops

Context

I was reviewing a test cleanup PR rust-lang/rust#141974, and I was trying to say something about the EXPR in

for PATTERN in EXPR {
    //         ^--- what is this expr called?
    // ...
}

but I couldn't find a good term for this12. The current grammar calls this EXPR

Expressionexcept struct expression

whereas for e.g. match EXPR { .. } or if let PATTERN = EXPR { .. }, there's a more "meaningful name" for that EXPR, which is the scrutinee expr.

Footnotes

  1. In the community discord, terms like "interatee" or "iterable" or "into-iterable" were suggested, but yeah.

  2. Nadrieril came up with "loopee", which is an excellent term 😆

@iampi31415
Copy link

iampi31415 commented Jun 4, 2025

Do they all need a name though?

Should the borrow expression call it borrowee ?

And the deref expression, dereferencee ? (We may use pointer here, but you get the gist.)

Just say what EXPR can be, which is done in the document.

IteratorLoopExpression :
for Pattern in Expression except struct expression BlockExpression

And to an extent, the traditional iterator seems fine to me, but I'd not add an extra label.

for expression extracts values from an iterator, looping until the iterator is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants