rust-lang / rust-lang/rust-clippy
semicolon_if_nothing_returned breaks `unsafe { nullpointer }`
Open
Nobody has claimed this yet.
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Using the following flags
--force-warn clippy::semicolon-if-nothing-returned
this code:
use std::ptr;
fn main() {
let a_billion_dollar_mistake = ptr::null();
unsafe {
*a_billion_dollar_mistake
}
}
caused the following diagnostics:
Checking _main v0.1.0 (/tmp/icemaker_global_tempdir.DOE7jUlq8RhE/icemaker_clippyfix_tempdir.tfQ4LVtK96ol/_main)
warning: consider adding a `;` to the last statement for consistent formatting
--> src/main.rs:7:9
|
7 | *a_billion_dollar_mistake
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `*a_billion_dollar_mistake;`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
= note: requested on the command line with `--force-warn clippy::semicolon-if-nothing-returned`
warning: `_main` (bin "_main") generated 1 warning (run `cargo clippy --fix --bin "_main"` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
However after applying these diagnostics, the resulting code:
use std::ptr;
fn main() {
let a_billion_dollar_mistake = ptr::null();
unsafe {
*a_billion_dollar_mistake;
}
}
no longer compiled:
error[E0283]: type annotations needed for `*const _`
--> src/main.rs:4:9
|
4 | let a_billion_dollar_mistake = ptr::null();
| ^^^^^^^^^^^^^^^^^^^^^^^^ ----------- type must be known at this point
|
= note: cannot satisfy `_: Thin`
note: required by a bound in `null`
--> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:828:31
|
828 | pub const fn null<T: ?Sized + Thin>() -> *const T {
| ^^^^ required by this bound in `null`
help: consider giving `a_billion_dollar_mistake` an explicit type, where the type for type parameter `T` is specified
|
4 | let a_billion_dollar_mistake: *const T = ptr::null();
| ++++++++++
Version:
rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported semicolon_if_nothing_returned diagnostic with the Rust snippet and inspect that lint's implementation and existing tests. The fix is done when applying the lint suggestion preserves compilation for this case and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100