Skip to content

transpile: Do not consider Bool an integral type - #2005

Open
Rua wants to merge 1 commit into
immunant:masterfrom
Rua:bool-not-integral
Open

transpile: Do not consider Bool an integral type#2005
Rua wants to merge 1 commit into
immunant:masterfrom
Rua:bool-not-integral

Conversation

@Rua

@Rua Rua commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

CTypeKind::is_unsigned_integral_type returns true for Bool, which is a bit of a footgun and probably not what most code (or coders) expect. So this removes it. I made sure to check that no code elsewhere relies on this including Bool and adjusted it where necessary. Most of the time, it was being used for wrapping arithmetic, which isn't possible on booleans anyway.

Comment thread c2rust-transpile/src/c_ast/mod.rs
matches!(*self, Self::Enum { .. })
}

pub fn is_enum_or_integral_type(&self) -> bool {

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.

Do we not want true here for bool? Does it regress anything?

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.

This function is only called in CastKind::from_types, where Bool is also handled separately. Possibly the IntegralToPointer case is not, so I've added handling for bool explicitly there now.

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.

You might be introducing some regressions in from_types, can you test bool-to-unsigned casts and maybe bool-to-float? (I'm not sure how much we care about the latter, but it might still be worth to see what happens)

@Rua
Rua force-pushed the bool-not-integral branch from 734cb83 to c7bae39 Compare September 10, 2026 09:03
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