Skip to content

Default RawOsError to i16 for 16-bit targets - #160543

Open
bushrat011899 wants to merge 1 commit into
rust-lang:mainfrom
bushrat011899:raw_os_error_c_int_default
Open

Default RawOsError to i16 for 16-bit targets#160543
bushrat011899 wants to merge 1 commit into
rust-lang:mainfrom
bushrat011899:raw_os_error_c_int_default

Conversation

@bushrat011899

@bushrat011899 bushrat011899 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ACP: rust-lang/libs-team#755
Tracking issue: #154046 & #107792
Fixes #160541

Description

As noted by @tgross35, it's likely desirable for RawOsError to default to i16 for 16-bit platforms. Practically, this only affects AVR and MSP430. Since c_int is defined as:

crate::cfg_select! {
    any(target_arch = "avr", target_arch = "msp430") => {
        pub(super) type c_int = i16;
        pub(super) type c_uint = u16;
    }
    _ => {
        pub(super) type c_int = i32;
        pub(super) type c_uint = u32;
    }
}

This also ensures for all platforms (excluding UEFI), RawOsError is equivalent to c_int. Since neither sets of targets had an implementation of std, this hasn't yet been litigated. While RawOsError is unstable, it seems reasonable to choose a default more likely to align with the underlying OS (if any).


Notes

  • No AI tooling of any kind was used during the creation of this PR.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 5, 2026
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

r? @Darksonn

rustbot has assigned @Darksonn.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from 6 candidates

Comment thread library/core/src/io/error.rs
@Darksonn

Darksonn commented Aug 5, 2026

Copy link
Copy Markdown
Member

Sorry I'm at capacity for the next two weeks.

@rustbot reroll

@rustbot rustbot assigned clarfonthey and unassigned Darksonn Aug 5, 2026
@bushrat011899

Copy link
Copy Markdown
Contributor Author

Clar I don't know why RustBot keeps giving you my PRs but hello again!

@bushrat011899
bushrat011899 force-pushed the raw_os_error_c_int_default branch from 74b8b44 to 9b6ba41 Compare August 5, 2026 09:55
@bushrat011899 bushrat011899 changed the title Default RawOsError to c_int instead of i32 Default RawOsError to i16 for 16-bit targets Aug 5, 2026
@rust-log-analyzer

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the raw_os_error_c_int_default branch from 9b6ba41 to bbc212a Compare August 5, 2026 10:12
Comment thread library/core/src/io/error.rs
#[test]
fn raw_os_error_ffi_guarantees() {
let _: RawOsError = cfg_select! {
target_os = "uefi" => 0 as usize,

@lygstate lygstate Aug 5, 2026

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.

well, the test already declare that.

View changes since the review

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.

Yeah tgross35's suggestion to use explicitly sized types is compared against the c_int assumption just so if a target is ever added that violates it, we know about it.

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.

Fwiw I was thinking to put it in a `const _: () = { /* ... */ } so the tests don't actually have to be run (I don't think we run coretests on these 16-bit platforms), but it doesn't matter much

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.

Yeah I'm not a huge fan of that particular const trick. The test as written is still compile-time evaluated, it'll just hopefully give a nicer message if/when it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core::io::RawOsError should probably be an i16 on AVR and MSP430

7 participants