Skip to content

transpile: Convert final return statement into tail expression#1497

Open
Rua wants to merge 3 commits intoimmunant:masterfrom
Rua:return-tail-expr
Open

transpile: Convert final return statement into tail expression#1497
Rua wants to merge 3 commits intoimmunant:masterfrom
Rua:return-tail-expr

Conversation

@Rua
Copy link
Contributor

@Rua Rua commented Dec 6, 2025

@Rua Rua marked this pull request as draft December 6, 2025 19:00
@Rua
Copy link
Contributor Author

Rua commented Dec 7, 2025

I ran into an unexpected snag with this one: the stmts_block helper function is adding back the semicolon if it's missing. Ideally I would just remove that behaviour, but that has the obvious potential to break a lot of things, so does anyone know why it's there and what other things rely on it?

Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

It seems this is passing c2rust-testsuite CI even though there are many errors, so something went wrong there. Ugh.

@Rua Rua force-pushed the return-tail-expr branch 7 times, most recently from 80842e4 to d50212e Compare December 10, 2025 18:40
@Rua Rua marked this pull request as ready for review December 10, 2025 19:05
@Rua
Copy link
Contributor Author

Rua commented Dec 10, 2025

I was able to remove the semicolon-adding code from stmts_block without any adverse effects in the tests, so let's hope it wasn't needed anywhere else. I think this is ready for review now.

@Rua
Copy link
Contributor Author

Rua commented Dec 17, 2025

In order to solve #1506 I had to add another variant to the ImplicitReturnType enum, because with Void it was adding a return that doesn't belong there. I don't know if that's actually the correct solution here. I don't quite understand the label break stuff in the compound statements translation, and there is likely some interaction with #1509 as well.

@Rua Rua force-pushed the return-tail-expr branch 2 times, most recently from ad48749 to a87f05b Compare January 8, 2026 10:37
Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

I don't quite understand the label break stuff in the compound statements translation, and there is likely some interaction with #1509 as well.

I'm not sure if you saw, but we have #1544 now to fix #1509.

@Rua
Copy link
Contributor Author

Rua commented Jan 16, 2026

I don't think this PR will affect that one, but we'll have to see I suppose.

@Rua Rua force-pushed the return-tail-expr branch from a87f05b to f00044e Compare January 19, 2026 17:03
@Rua
Copy link
Contributor Author

Rua commented Jan 19, 2026

@ahomescu the test here is failing since merging #1544. It's inserting a label and a block, seemingly for no reason. Is that a bug in your code or in mine?

EDIT: Seems to occur with current master as well. I've updated the test so that it includes the additional block.

@Rua Rua force-pushed the return-tail-expr branch from f00044e to fc564d8 Compare January 19, 2026 17:25
@Rua Rua marked this pull request as draft January 19, 2026 17:26
@Rua Rua force-pushed the return-tail-expr branch from 265a4ff to 40ee213 Compare January 19, 2026 17:57
@Rua Rua force-pushed the return-tail-expr branch from 40ee213 to f0797ee Compare January 19, 2026 18:07
@Rua Rua marked this pull request as ready for review January 19, 2026 18:49
@Rua Rua requested a review from kkysen January 23, 2026 13:46
@ahomescu
Copy link
Contributor

@ahomescu the test here is failing since merging #1544. It's inserting a label and a block, seemingly for no reason. Is that a bug in your code or in mine?

EDIT: Seems to occur with current master as well. I've updated the test so that it includes the additional block.

That's not surprising, #1544 changed a few details about how we emit the expression in a WithStmts. We should fix here whatever conflicts that caused.

@ahomescu
Copy link
Contributor

There is also a clippy lint for this https://rust-lang.github.io/rust-clippy/master/index.html#needless_return. Could we just run that instead?

@Rua
Copy link
Contributor Author

Rua commented Jan 24, 2026

Can clippy run even when no Cargo.toml has been generated?

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.

transpile: return is stripped from end of statement expressions transpile: return is emitted in final statement

3 participants