Skip to content

Suggestion for diagnostic imoprovement in case of null pointer that differs in mutability #85184

Closed
@elichai

Description

@elichai

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=08b90ff4a7eec137c7da11cbb5f8d81f

use core::ptr;

fn test(_: *mut u8){}

fn main() {
    test(ptr::null());
}

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:6:10
  |
6 |     test(ptr::null());
  |          ^^^^^^^^^^^ types differ in mutability
  |
  = note: expected raw pointer `*mut u8`
             found raw pointer `*const _`

Ideally it would suggest me to use ptr::null_mut() instead.

@estebank (opened this issue because you always ask people on twitter to open issues about diagnostic improvements :) )

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions