Skip to content

lint on more incorrect usages of core::ffi::c_void - #159986

Open
Jules-Bertholet wants to merge 5 commits into
rust-lang:mainfrom
Jules-Bertholet:c-void-refs
Open

lint on more incorrect usages of core::ffi::c_void#159986
Jules-Bertholet wants to merge 5 commits into
rust-lang:mainfrom
Jules-Bertholet:c-void-refs

Conversation

@Jules-Bertholet

@Jules-Bertholet Jules-Bertholet commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

core::ffi::c_void has size 1 and a highly non-trivial validity invariant. It should only ever be used behind a raw pointer. However, people mess this up all the time.

Also fixes false negatives in the pre-exisiting c_void_returns. Like that lint, these new lints are warn-by-default, but should eventually be upgraded to deny.

See also #159935

@rustbot label T-lang needs-fcp A-FFI

@rustbot

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

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

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

r? @fee1-dead

rustbot has assigned @fee1-dead.
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: compiler
  • compiler expanded to 74 candidates
  • Random selection from 17 candidates

@rustbot rustbot added A-FFI Area: Foreign function interface (FFI) needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-lang Relevant to the language team labels Jul 27, 2026
@rust-log-analyzer

This comment has been minimized.

Also, fix false negatives in `c_void_returns`.
Comment thread src/tools/miri/src/shims/native_lib/mod.rs
@RalfJung

Copy link
Copy Markdown
Member

The lint should probably also complain about statics of type c_void.

@Jules-Bertholet Jules-Bertholet changed the title lint on core::ffi::c_void as an &/&mut referent lint on more incorrect usages of core::ffi::c_void Jul 28, 2026
Also, fix another false negative in `c_void_returns`.
@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

The lint should probably also complain about statics of type c_void.

Added another lint for this

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

Added a third lint, against c_void function parameters.

@theemathas

Copy link
Copy Markdown
Contributor

Idea (not sure if this is feasible): If we do anything that asks for the size of c_void, emit a warning unless it's for a pointer offset operation

@mejrs

mejrs commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Idea (not sure if this is feasible): If we do anything that asks for the size of c_void, emit a warning unless it's for a pointer offset operation

We can emit a warning regardless, with a note to just use byte_add for offset operations. (Is that what people are using size_of for..?)

@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

Added a fourth lint to check for incorrect usage of c_void in MIR.

@rust-log-analyzer

This comment has been minimized.

Also, extend `c_void_references` to lint on
references to `c_void` in MIR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-FFI Area: Foreign function interface (FFI) needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants