Skip to content

Conversation

@Lishin1215
Copy link
Contributor

@Lishin1215 Lishin1215 commented Jul 16, 2025

Fixes #3783 .

gcc/rust/ChangeLog:

        * backend/rust-compile-expr.cc (CompileExpr::visit): add a catch for const/static

gcc/testsuite/ChangeLog:

        * rust/compile/loop_constant_context.rs: New test.
        * rust/compile/issue-3618.rs:

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static.

gcc/testsuite/ChangeLog:

	* rust/compile/loop_constant_context.rs: New test.
	* rust/compile/issue-3618.rs:

Signed-off-by: lishin <[email protected]>
@Lishin1215
Copy link
Contributor Author

In this patch I use ctx->const_context_p() to block loop in const/static,
and using !DECL_DECLARED_CONSTEXPR_P(fnctx.fndecl) to allow loop inside const fn. (like this example )

However, this may still reject the valid case mentioned here here

static _X: () = loop {
    break;
};

Thanks!

@philberty
Copy link
Member

Good catch i raised that test case as an issue. I think lets go for your Patch and merge it for now. That test case we can handle because we could add in a check for the result of the loop if its a ! never type or () i bet we just ignore it

@philberty philberty added this pull request to the merge queue Jul 18, 2025
Merged via the queue into Rust-GCC:master with commit 28c3348 Jul 18, 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.

Rustc behaviour with loops in const/static context

2 participants