Skip to content

Report E0435 for locals in array lengths - #5101

Open
u7k4rs6 wants to merge 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-5092-array-len-local
Open

u7k4rs6 wants to merge 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-5092-array-len-local

Conversation

@u7k4rs6

@u7k4rs6 u7k4rs6 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

a local in an array length printed non const capacity domain '%T'. now it's E0435 like rustc, anything else non-constant gets a plain message.

Fixes #5092

@philberty philberty left a comment

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.

minor nit to move that into the rust-compile-base.cc

Comment thread gcc/rust/backend/rust-compile-expr.cc Outdated
// rustc reports a local in an array length as E0435
// shortcut: only a bare path is checked, `n + 1` gets the plain message
static void
report_non_const_length (Context *ctx, HIR::Expr &length)

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.

feels like this should be moved into the rust-compile-base.cc

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.

moved it into HIRCompileBase 👍

A local in an array length printed a broken '%T' error, now it's E0435
like rustc.

Fixes Rust-GCC#5092

Assisted-by: Claude Opus (Anthropic)

gcc/rust/ChangeLog:

	* backend/rust-compile-base.h (HIRCompileBase::report_non_const_length):
	New function.
	* backend/rust-compile-base.cc (HIRCompileBase::report_non_const_length):
	Likewise.
	* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): Use it.

gcc/testsuite/ChangeLog:

	* rust/compile/issues/issue-5092.rs: New test.

Signed-off-by: Utkarsh Bahuguna <utkarshbahuguna10@gmail.com>
@u7k4rs6
u7k4rs6 force-pushed the fix-5092-array-len-local branch from 1116c21 to bf38a4b Compare November 26, 2026 11:13
@u7k4rs6
u7k4rs6 requested a review from philberty November 26, 2026 15:55

This branch has not been deployed

No deployments
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.

Array length using a local gives a broken message instead of E0435

2 participants