Skip to content

Conversation

@xonx4l
Copy link
Contributor

@xonx4l xonx4l commented Dec 15, 2025

In the PR lint for black_boxing ZSTs is implemented as discussed in #137658

This PR implements a new lint which warns when std::hint::black_box is called with a Zero-Sized Type (ZST).

Changes:
Added #[rustc_diagnostic_item = "black_box"] to library/core/src/hint.rs.
Implemented a LateLintPass to detect calls to black_box where the argument's layout is a ZST.

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2025

r? @eholk

rustbot has assigned @eholk.
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

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: `black_box` on zero-sized callable `fn(u32, u32) -> u32 {add}` has no effect on call opacity
    --> compiler/rustc_lint/src/builtin.rs:3132:18
     |
3132 |     let add_bb = black_box(add);
     |                  ^^^^^^^^^^---^
     |                            |
     |                            zero-sized callable passed here
     |
     = note: zero-sized callable values have no runtime representation, so the call still targets the original function directly
     = help: coerce to a function pointer and call `black_box` on that pointer instead
     = note: `#[warn(black_box_zst_calls)]` on by default

warning: 2 warnings emitted

Test compiled successfully, but it's marked `compile_fail`.
\ (no newline at end of output)

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

4 participants