Skip to content

rust: avoid ICE on attributed struct base parsing#4514

Open
hriztam wants to merge 1 commit intoRust-GCC:masterfrom
hriztam:fix/internal_compiler_fix
Open

rust: avoid ICE on attributed struct base parsing#4514
hriztam wants to merge 1 commit intoRust-GCC:masterfrom
hriztam:fix/internal_compiler_fix

Conversation

@hriztam
Copy link
Copy Markdown
Contributor

@hriztam hriztam commented Apr 3, 2026

Address #4476

rust: avoid ICE on attributed struct base parsing

Parsing a struct expression like Foo { #[cfg(feature = -1)] .. }
could ICE because parse_struct_expr_struct_partial() unconditionally
called value() on an errored StructExprField result after
parse_struct_expr_field() had already identified .. as the struct
base.

Handle that case explicitly, emit a normal parser diagnostic when
attributes are attached to the struct-base .., and add a regression
test for the reduced reproducer.

Signed-off-by: Hritam Shrivastava hritamstark05@gmail.com

@@ -0,0 +1,12 @@
// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not required, it is already injected thanks to compile.exp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR

gcc/rust/ChangeLog:

	* parse/rust-parse-error.h (StructExprField): Add
	STRUCT_BASE_ATTRIBUTES.
	* parse/rust-parse-impl-expr.hxx
	(Parser<ManagedTokenSource>::parse_struct_expr_field):
	Reject attributes before struct-base `..`.
	(Parser<ManagedTokenSource>::parse_struct_expr_struct_partial):
	Handle struct-base parse results without dereferencing an errored
	expected.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4476.rs: New test.

Signed-off-by: Hritam Shrivastava <hritamstark05@gmail.com>
@hriztam hriztam force-pushed the fix/internal_compiler_fix branch from 131e341 to 8c466b7 Compare May 9, 2026 12:19
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