Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elichai opened this issue May 11, 2021 · 1 comment · Fixed by #112302
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@elichai
Copy link
Contributor

elichai commented May 11, 2021

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 :) )

@elichai elichai added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2021
@camelid camelid added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. labels May 11, 2021
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Mar 15, 2022

Here is a permalink.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=08b90ff4a7eec137c7da11cbb5f8d81f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants