Skip to content

library: use core::ffi::c_* types - #159868

Open
xtqqczze wants to merge 1 commit into
rust-lang:mainfrom
xtqqczze:library-ffi
Open

library: use core::ffi::c_* types#159868
xtqqczze wants to merge 1 commit into
rust-lang:mainfrom
xtqqczze:library-ffi

Conversation

@xtqqczze

Copy link
Copy Markdown
Contributor

No description provided.

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-fuchsia Operating system: Fuchsia O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 24, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xtqqczze
xtqqczze marked this pull request as ready for review July 27, 2026 21:51
@rustbot

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in std_detect

cc @Amanieu, @folkertdev, @sayantn

compiler-builtins is developed in its own repository. If possible, consider making this change to rust-lang/compiler-builtins instead.

cc @tgross35

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 27, 2026
@rustbot

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

r? @nia-e

rustbot has assigned @nia-e.
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: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 7 candidates

@xtqqczze

Copy link
Copy Markdown
Contributor Author

r? @tgross35

@rustbot rustbot assigned tgross35 and unassigned nia-e Jul 27, 2026
@rustbot

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@tgross35 tgross35 left a comment

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.

Most of this seems completely reasonable. However, I don't think we should change imports from std to core in examples. E.g.:

+ /// use core::ffi::c_char;
  /// use std::ffi::CString;
- /// use std::os::raw::c_char;

It's a bit cleaner to import only from std::ffi than to mix core and std.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Comment on lines -575 to +576
/// use std::ffi::{CString, CStr};
/// use core::ffi::CStr;
/// use std::ffi::CString;

@madsmtm madsmtm Jul 28, 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.

I'm greatly in favor of using std::ffi::* instead of std::os::raw::*, but I'm not convinced that using core in documentation is the best idea? I'd prefer to guide users towards using the std re-exports.

Especially because core isn't available in the 2015 edition, so users copying the code into a sample file and running bare rustc on it will get an error. (Somewhat mitigated by rust-lang/compiler-team#1019, but still).

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.

Especially because core isn't available in the 2015 edition, so users copying the code into a sample file and running bare rustc on it will get an error.

Is this really a significant issue? If someone compiles the example with the 2015 edition, the compiler already shows a suggested fix:

error[E0433]: cannot find `core` in the crate root
 --> <source>:1:5
  |
1 | use core::ffi::CStr;
  |     ^^^^ you might be missing crate `core`
  |
help: try using `std` instead of `core`
  |
1 - use core::ffi::CStr;
1 + use std::ffi::CStr;
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0433`.

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.

Ditto on that #159868 (review). It's also just consistency; if you have std available it's more common to import everything from std than to split it up.

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.

I think it would be reasonable to customize the resolve error under 2015 to mention the difference in a note.

@rust-bors

rust-bors Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #160517) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-fuchsia Operating system: Fuchsia O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants