Skip to content

False negatives without build-std #15183

@mkroening

Description

@mkroening

Summary

Building std via -Z build-std can make cargo-clippy emit more warnings on user code than without building std.

Lint Name

clippy::unwrap_or_default

Reproducer

I tried this code:

pub fn foo() -> Option<*mut u8> {
    None
}

pub fn bar() -> *mut u8 {
    foo().unwrap_or(std::ptr::null_mut())
}

I expected to see this happen:

$ cargo +nightly clippy -Z build-std
    Checking foo v0.1.0 (/Users/mkroening/Downloads/foo)
warning: use of `unwrap_or` to construct default value
 --> src/lib.rs:6:11
  |
6 |     foo().unwrap_or(std::ptr::null_mut())
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default
  = note: `#[warn(clippy::unwrap_or_default)]` on by default

warning: `foo` (lib) generated 1 warning (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s

Instead, this happened:

cargo +nightly clippy
    Checking foo v0.1.0 (/Users/mkroening/Downloads/foo)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s

Version

rustc 1.90.0-nightly (35f603652 2025-06-29)
binary: rustc
commit-hash: 35f6036521777bdc0dcea1f980be4c192962a168
commit-date: 2025-06-29
host: aarch64-apple-darwin
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions