Skip to content

ast: Check before visiting a while-let's label#3797

Merged
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:while-let-label
Jul 9, 2025
Merged

ast: Check before visiting a while-let's label#3797
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:while-let-label

Conversation

@CohenArthur

Copy link
Copy Markdown
Member

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label
before visiting it.

gcc/testsuite/ChangeLog:

* rust/compile/while_let_without_label.rs: New test.

@powerboat9

Copy link
Copy Markdown
Collaborator

Looks like we're missing binding context handling for the while let patterns -- speaking of, are they supposed to have multiple patterns, or should they just store a pattern which could be an AltPattern?

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

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label
	before visiting it.

gcc/testsuite/ChangeLog:

	* rust/compile/while_let_without_label.rs: New test.
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New visitor.
	* resolve/rust-late-name-resolver-2.0.h: Declare it.
	* resolve/rust-name-resolution-context.h (enum class): New binding context.
@CohenArthur

Copy link
Copy Markdown
Member Author

Looks like we're missing binding context handling for the while let patterns -- speaking of, are they supposed to have multiple patterns, or should they just store a pattern which could be an AltPattern?

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

I added a commit to handle while-let loops in NR2.0 in this PR, since we don't have the exclude file anymore - but I can split it in two PRs if you'd like @powerboat9.

regarding the vector of patterns vs alt-pattern - I'm not sure. this is how it's done in the base loop expression, but I think it could be changed to just one optional pattern (as loop loops don't have them)

@CohenArthur CohenArthur added this pull request to the merge queue Jul 9, 2025
Merged via the queue into Rust-GCC:master with commit 9f7b4f9 Jul 9, 2025
13 checks passed
powerboat9 added a commit to powerboat9/gccrs that referenced this pull request Jul 12, 2025
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

Successfully merging this pull request may close these issues.

2 participants