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

Add a new lint ptr_as_ptr #6542

Merged
merged 2 commits into from
Jan 5, 2021
Merged

Add a new lint ptr_as_ptr #6542

merged 2 commits into from
Jan 5, 2021

Conversation

rail-rain
Copy link
Contributor

This PR adds a new lint ptr_as_ptr which checks for as casts between raw pointers without changing its mutability and suggest replacing it with pointer::cast. Closes #5890.

Open question: should this lint be pedantic or style? I set it pedantic for now because the original post suggests using it, but I think the lint also fits well to style.


changelog: New lint ptr_as_ptr

@rust-highfive
Copy link

r? @flip1995

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 3, 2021
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Only the MSRV stuff is incomplete.

I especially like the suggestion generation and that it doesn't produce unnecessary fishes.

clippy_lints/src/types.rs Show resolved Hide resolved
tests/ui/ptr_as_ptr.fixed Show resolved Hide resolved
@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jan 4, 2021
@bors
Copy link
Contributor

bors commented Jan 4, 2021

☔ The latest upstream changes (presumably #6538) made this pull request unmergeable. Please resolve the merge conflicts.

which checks for `as` casts between raw pointers
without changing its mutability
and suggest replacing it with `pointer::cast`.
@rail-rain
Copy link
Contributor Author

It looks like I was not careful enough about the MSRV stuff. Thanks very much for your help!

@rail-rain
Copy link
Contributor Author

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jan 4, 2021
}

fn _msrv_1_38() {
#![clippy::msrv = "1.38"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't know that inner attributes can also be put into functions. I always assumed that they only work on crate and module level. But it makes sense, that they work for every item(-block)-like thing.

@flip1995
Copy link
Member

flip1995 commented Jan 5, 2021

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jan 5, 2021

📌 Commit dfa5d7e has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jan 5, 2021

⌛ Testing commit dfa5d7e with merge a6b72d3...

@bors
Copy link
Contributor

bors commented Jan 5, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing a6b72d3 to master...

@bors bors merged commit a6b72d3 into rust-lang:master Jan 5, 2021
@rail-rain rail-rain deleted the ptr_as_ptr branch January 5, 2021 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint to disallow using as for pointer casts in favor of .cast()
5 participants