Skip to content

Unimplement fmt::Debug for c_void - #160115

Open
Jules-Bertholet wants to merge 1 commit into
rust-lang:mainfrom
Jules-Bertholet:no-c-void-debug
Open

Unimplement fmt::Debug for c_void#160115
Jules-Bertholet wants to merge 1 commit into
rust-lang:mainfrom
Jules-Bertholet:no-c-void-debug

Conversation

@Jules-Bertholet

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

Copy link
Copy Markdown
Contributor

Taking a shared reference to c_void is never correct, and this impl should never have been added.

This is obviously a breaking change, so needs crater and FCP.

@rustbot label T-libs-api needs-fcp A-FFI

See also #159986, #159935

@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 Jul 29, 2026
@rustbot

rustbot commented Jul 29, 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 7 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-libs-api [DEPRECATED; DO NOT USE] labels Jul 29, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 82b0460 (82b04601f285a69721a2b7d1db460b48a7edeef4)
Base parent: 26ae60a (26ae60a9eeb20b4935be49d7a931a650fa1d2923)

@theemathas

Copy link
Copy Markdown
Contributor

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-160115 created and queued.
🤖 Automatically detected try build 82b0460
⚠️ Try build based on commit 03942bc, but latest commit is 588c33e. Did you forget to make a new try build?
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2026
@clarfonthey

clarfonthey commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Worth also commenting that there's a blanket Debug impl for *const T and *mut T, and so, this would not affect anything reasonable that uses c_void from deriving Debug.

(Regardless, it would be unsound to actually access data inside these pointers without verifying it's valid, but I could imagine some scenario where someone thought those only implemented Debug when T: Debug, for some weird reason. Those weird reasons don't exist.)

@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-160115 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@asquared31415

Copy link
Copy Markdown
Contributor

Something of note is that there exists impl Debug for ! which is similarly invalid to obtain. However, I think that this PR is useful because it's significantly easier to accidentally obtain a c_void in ways that are not protected as well as !. In particular, using Debug on a struct with &c_void is relatively common in the ecosystem, but &! less so because there's no common expectation that it's valid as a pointee.

@Jules-Bertholet

Jules-Bertholet commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

impl Debug for ! is also useful in dead code (e.g unwrapping a Result<_, !>); the impl for c_void is not.

@clarfonthey

Copy link
Copy Markdown
Contributor

Yeah, I would expect impl Debug for ! to mostly cover cases like Result<T, !> being Debug, whereas I genuinely can't imagine a case where this would happen with c_void. With how infectious the unsafety from FFI can be, if you're doing type maths enough to the point where &c_void shows up, I would say you're probably doing something wrong.

But either way, crater should let us know how people are using this.

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-160115 is completed!
📊 674 regressed and 1 fixed (1052665 total)
📊 5754 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-160115/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 11, 2026
@theemathas

theemathas commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Most of the regressions (608 of them) are from the lz4-sys crate, here.

#[derive(Debug)]
#[repr(C)]
pub struct LZ4StreamEncode(c_void);

#[derive(Debug)]
#[repr(C)]
pub struct LZ4StreamDecode(c_void);

These structs are only ever used via a raw pointer, and the derives seem extraneous.

Taking a shared reference to `c_void` is always wrong.
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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-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.

9 participants