Skip to content

transpile: Don't require WithStmts parameter for most functions - #2010

Closed
Rua wants to merge 3 commits into
immunant:masterfrom
Rua:make_cast-no-withstmts
Closed

Rua wants to merge 3 commits into
immunant:masterfrom
Rua:make_cast-no-withstmts

Conversation

@Rua

@Rua Rua commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

The only thing here that actually required a WithStmts specifically was an assert for the NullToPointer case. That case was throwing out the existing WithStmts and replacing it with a new one, resulting in a double translation. NullToPointer is never returned by CastKind::from_types, and so that path is only ever hit when being called from convert_cast. So I just moved NullToPointer there instead.

@Rua
Rua force-pushed the make_cast-no-withstmts branch 10 times, most recently from 87e2433 to c596896 Compare September 16, 2026 10:04
@Rua
Rua force-pushed the make_cast-no-withstmts branch from c596896 to 654c3e0 Compare September 16, 2026 14:21
Comment thread c2rust-transpile/src/translator/mod.rs Outdated
}

CastKind::NullToPointer => {
return Ok(WithStmts::new_val(self.null_ptr(ty.ctype)?));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use target_ty.ctype here instead?

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.

Yes, fixed.

@Rua
Rua force-pushed the make_cast-no-withstmts branch 5 times, most recently from ad93fdb to f3643f6 Compare September 24, 2026 08:46
@Rua Rua changed the title transpile: Don't require WithStmts for make_cast and other cast functions transpile: Don't require WithStmts parameter for most functions Sep 26, 2026
@Rua
Rua force-pushed the make_cast-no-withstmts branch from 3fb8095 to fcf1a73 Compare September 26, 2026 16:38
@Rua
Rua force-pushed the make_cast-no-withstmts branch 2 times, most recently from 89aadc0 to b3392eb Compare October 8, 2026 11:12
@Rua
Rua force-pushed the make_cast-no-withstmts branch from b3392eb to bd2ce51 Compare October 22, 2026 19:26
@Rua
Rua force-pushed the make_cast-no-withstmts branch 2 times, most recently from 01168be to ec0416c Compare October 23, 2026 10:11
@Rua
Rua force-pushed the make_cast-no-withstmts branch from ec0416c to 7377e8e Compare October 23, 2026 10:15
@Rua

Rua commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

I'm closing this because now that #2018 landed, it's better to combine these changes with a larger refactor of make_cast that lets it also use IdOrExpr.

@Rua Rua closed this Oct 23, 2026
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