Skip to content

Conversation

Polygonalr
Copy link
Contributor

@Polygonalr Polygonalr commented Sep 28, 2025

Fixes #3929

  • More renames to indicate rest patterns more clearly.
  • Add support for lowering rest pattern present in StructPatternElements to HIR.
  • Fixes type checker throwing error when struct pattern is being matched against a tuple struct.

gcc/rust/ChangeLog:

	* ast/rust-pattern.h (StructPatternElements): Rename has_struct_pattern_etc
	to has_rest_pattern, and has_etc to has_rest to signify presense of rest
	patterns more clearly.
	* ast/rust-pattern.cc (StructPatternElements::as_string): Rename variables
	accordingly.
	* ast/rust-ast-collector.cc: Rename variables accordingly.
	* expand/rust-cfg-strip.cc: Rename variables accordingly.
	* parse/rust-parse-impl.h: Rename variable accordingly.
	* hir/tree/rust-hir-pattern.h (StructPatternElements): Add a boolean to track
	presense of rest pattern.
	* hir/rust-ast-lower-pattern.cc (visit(StructPattern)): Add support for
	lowering rest pattern to HIR.
	* typecheck/rust-hir-type-check-pattern.cc (visit(StructPattern)): Remove
	size check when rest pattern is present.

Signed-off-by: Yap Zhi Heng <[email protected]>
Previously, type checking of StructPattern will throw an error if it is used
to match against a tuple struct, even though it is possible to do so in rustc.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (visit(StructPattern)): Add type check
	support for StructPatterns matching against a TUPLE type ADT.
	* backend/rust-compile-pattern.cc(CompilePatternBindings::visit(StructPattern)):
	Update assert to allow TUPLE type ADTs.
	* hir/tree/rust-hir.cc (StructPatternField::as_string()): Improve info dumped.

Signed-off-by: Yap Zhi Heng <[email protected]>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added this pull request to the merge queue Sep 30, 2025
Merged via the queue into Rust-GCC:master with commit aa642e7 Sep 30, 2025
13 checks passed
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.

ICE: in visit, at rust/hir/rust-ast-lower-pattern.cc:122 struct match

2 participants