Skip to content
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

Suggest ptr::null_mut::<T>() instead of ptr::null::<T>() as *mut T #13361

Closed
nyurik opened this issue Sep 6, 2024 · 1 comment · Fixed by #13369
Closed

Suggest ptr::null_mut::<T>() instead of ptr::null::<T>() as *mut T #13361

nyurik opened this issue Sep 6, 2024 · 1 comment · Fixed by #13369
Assignees
Labels
A-lint Area: New lints

Comments

@nyurik
Copy link
Contributor

nyurik commented Sep 6, 2024

What it does

Use the null_mut() directly instead of first creating a read-only null() and casting it

Advantage

  • shorter easier to read code
  • avoid accidental later mis-casting

Drawbacks

none

Example

let a = ptr::null::<T>() as *mut T;
let b = ptr::null_mut::<T>() as *const T;

Could be written as:

let a = ptr::null_mut::<T>();
let b = ptr::null::<T>();
@nyurik nyurik added the A-lint Area: New lints label Sep 6, 2024
@samueltardieu
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants