Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting bool to pointer type results in invalid Rust #1077

Closed
jorendorff opened this issue Apr 8, 2024 · 1 comment · Fixed by #1134
Closed

Casting bool to pointer type results in invalid Rust #1077

jorendorff opened this issue Apr 8, 2024 · 1 comment · Fixed by #1134
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jorendorff
Copy link

The fix should be the same as #1030, but presumably with something like size_t as the intermediate type.

(Why, you might ask, would anyone ever do this in real code. The answer is that C doesn't have generics, so projects will have, say, a single hash table type with void * values, and store booleans in it by casting.)

@kkysen kkysen added bug Something isn't working good first issue Good for newcomers labels Aug 29, 2024
@fw-immunant
Copy link
Contributor

This code reproduces this bug:

#include <stdbool.h>

void f(bool b) {
    void* x = (void*)b;
}

It gets translated to:

#[no_mangle]
pub unsafe extern "C" fn f(mut b: bool) {
    let mut x: *mut libc::c_void = b as *mut libc::c_void;
}

which does not compile (E0606).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants