-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Type assertion error i8
vs u8
#60226
Comments
Nah, I have to disagree. The C-Standard does not define whether a char is signed or unsigned. Read https://stackoverflow.com/q/2054939/ .
Then what's the problem with doing it?
That's third party code and not the official rust compiler. They use their own code IIRC. |
No sorry, I disagree, this is not a C issue, this is a Rust type inference coherence issue: In ra/mod.rs
In the code above, type inference is used for all variables. Since |
You forgot the #[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "l4re", target_arch = "x86_64"),
all(target_os = "freebsd", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "powerpc64")),
all(target_os = "netbsd", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc")),
all(target_os = "openbsd", target_arch = "aarch64"),
all(target_os = "fuchsia", target_arch = "aarch64")))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
#[doc(include = "os/raw/char.md")]
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "s390x")),
all(target_os = "android", any(target_arch = "aarch64",
target_arch = "arm")),
all(target_os = "l4re", target_arch = "x86_64"),
all(target_os = "freebsd", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "powerpc64")),
all(target_os = "netbsd", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc")),
all(target_os = "openbsd", target_arch = "aarch64"),
all(target_os = "fuchsia", target_arch = "aarch64"))))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; |
From the code snippet above it is fairly clear that The types in this example therefore are all concrete (there are no inference variables), therefore inference cannot plausibly be a cause of any sort of a bug here. This indeed does not appear to be a bug. Therefore closing, but do complain if you still feel otherwise. |
@hellow554 @nagisa
Obviously the IntelliJ parser ignores the |
similar to: sportsball-ai/blackmagic-raw-rs#3 > Apparently c_char is aliased to u8 on linux/arm64, whereas it's i8 on linux/amd64. > Some context here: rust-lang/rust#60226 > And see c_char_definition here: https://doc.rust-lang.org/src/std/os/raw/mod.rs.html#103
The error was following: ``` error[E0308]: mismatched types --> /home/[redacted]/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/elephantry-3.0.0/src/connection.rs:41:50 | 41 | connection.set_notice_processor(Some(notice_processor), std::ptr::null_mut()); | ---- ^^^^^^^^^^^^^^^^ expected `u8`, found `i8` | | | arguments to this enum variant are incorrect | = note: expected fn pointer `unsafe extern "C" fn(_, *const u8)` found fn item `extern "C" fn(_, *const i8) {notice_processor}` ``` Relevant links: - rust-lang/rust#60226 - https://github.com/sportsball-ai/blackmagic-raw-rs/pull/3/files
Commit fixes following error when building on linux arm64 (Ubuntu in Docker on Apple M1): error[E0308]: mismatched types --> /home/[redacted]/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/elephantry-3.0.0/src/connection.rs:41:50 | 41 | connection.set_notice_processor(Some(notice_processor), std::ptr::null_mut()); | ---- ^^^^^^^^^^^^^^^^ expected `u8`, found `i8` | | | arguments to this enum variant are incorrect | = note: expected fn pointer `unsafe extern "C" fn(_, *const u8)` found fn item `extern "C" fn(_, *const i8) {notice_processor}` Relevant links: - rust-lang/rust#60226 - https://github.com/sportsball-ai/blackmagic-raw-rs/pull/3/files
Rustc 1.33. The following code:
will generate a compilation error
On my system (MacOS)
c_char
is aliased tou8
so this should be fine.Actually, casting
*c
toi8
will compile but the Rust plugin of IntelliJ will report an error (see attached picture)The text was updated successfully, but these errors were encountered: