Skip to content

Suggest ptr::null, ptr::null_mut over casting. #1047

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
Stebalien opened this issue Jun 27, 2016 · 7 comments · Fixed by #1561
Closed

Suggest ptr::null, ptr::null_mut over casting. #1047

Stebalien opened this issue Jun 27, 2016 · 7 comments · Fixed by #1561
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-AST Type: Requires working with the AST

Comments

@Stebalien
Copy link

Add a lint to suggest converting all instances of:

0 as *const T;
0 as *mut T;

To:

std::ptr::null();
std::ptr::null_mut();

See rust-lang/rust#34456

@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2016

These are also in core. We should probably figure out whether no_std is set and suggest core::ptr::* in that case.

@mcarton
Copy link
Member

mcarton commented Jun 27, 2016

We should probably figure out whether no_std is set and suggest core::ptr::* in that case.

This could be done for a lot a paths in suggestions.

@mcarton mcarton added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-AST Type: Requires working with the AST L-style Lint: Belongs in the style lint group labels Jun 27, 2016
@llogiq
Copy link
Contributor

llogiq commented Jun 27, 2016

Sounds like we could use a utility function that walks the parent chain to look for #[no_std].

@mcarton
Copy link
Member

mcarton commented Jun 27, 2016

You don't even need to walk the parent chain, the current crate is available as LateContext::krate which has attributes.

@llogiq
Copy link
Contributor

llogiq commented Jun 28, 2016

True. I had forgotten that this attribute is crate-level only.

@alilleybrinker
Copy link

I'm happy to give this a shot.

@mcarton
Copy link
Member

mcarton commented Oct 27, 2016

Great! Feel free to ask if you have any question.

llogiq added a commit that referenced this issue Feb 21, 2017
This fixes #1047. I did not bother to add a full suggestion,
because replacing with `std::ptr::null()` may still lead to
inference failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-AST Type: Requires working with the AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants