Skip to content

lint on core::ffi::c_void as an &/&mut referent - #159986

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

lint on core::ffi::c_void as an &/&mut referent#159986
Jules-Bertholet wants to merge 2 commits into
rust-lang:mainfrom
Jules-Bertholet:c-void-refs

Conversation

@Jules-Bertholet

Copy link
Copy Markdown
Contributor

core::ffi::c_void has size 1 and a highly non-trivial validity invariant. Creating an & or &mut reference to it is a recipe for UB. It's also widespread, e.g. here in Miri, here across GitHub. Let's lint on it!

Also fixes false negatives in c_void_returns. Like that lint, this should probably become deny-by-default eventually.

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`.
unsafe extern "C" fn libffi_closure_callback<'tcx>(
_cif: &libffi::low::ffi_cif,
_result: &mut c_void,
_result: &mut (),

@RalfJung RalfJung Jul 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Shouldn't this be a raw pointer? Presumably it's mutating more than 0 bytes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is forced on us by libffi.
Also we're not doing anything with this reference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing how libffi itself forces &mut c_void? If I look at the repo, it only uses *mut c_void.

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.

It forces &mut <something>.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense.

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.

7 participants