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

Lint against calling intrinsics that have stable or safe wrappers #2997

Open
dtolnay opened this issue Aug 3, 2018 · 8 comments
Open

Lint against calling intrinsics that have stable or safe wrappers #2997

dtolnay opened this issue Aug 3, 2018 · 8 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions L-unnecessary Lint: Warn about unnecessary code

Comments

@dtolnay
Copy link
Member

dtolnay commented Aug 3, 2018

There are some intrinsics that there should be no reason to call. For example core::intrinsics::size_of. This intrinsic is exposed by the safe function core::mem::size_of which should always be called instead.

I would like to suggest a Clippy lint that notices calls to no-reason-to-call intrinsics and recommends the right stable or safe wrapper to call instead.

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints L-unnecessary Lint: Warn about unnecessary code L-suggestion Lint: Improving, adding or fixing lint suggestions labels Aug 3, 2018
@okuhn
Copy link

okuhn commented Oct 4, 2019

I started working on a fix.

@llogiq
Copy link
Contributor

llogiq commented Oct 5, 2019

Ping me (either here or on Twitter or Reddit) if you need anything, and feel free to share your progress even when not finished.

@krishna-veerareddy
Copy link
Contributor

@okuhn Hey were you able to make progress on this issue? If you are not able to work on it then please let me know and I can take over. Thanks!

@dtolnay
Copy link
Member Author

dtolnay commented Apr 1, 2020

@krishna-veerareddy I would recommend that you should go ahead if you are interested in working on this.

@cauebs
Copy link
Contributor

cauebs commented Nov 1, 2020

Have you guys got anything done? I'm thinking of giving this one a go.

I checked the documentation and the intrinsics module is quite regularly documented, so I'll probably use a Python script to scrape the pages and check which functions have safe alternatives linked. Having that list, the rest should be quite easy, right? Just checking paths in expressions.

Let me know if anyone's working on this or if you have some tips for me!

pickfire added a commit to pickfire/rust that referenced this issue Nov 2, 2020
I noticed that it is pointing to the same link when I was reading
rust-lang/rust-clippy#2997
@pickfire
Copy link
Contributor

pickfire commented Nov 2, 2020

@cauebs I noticed that the link dtolnay pointed out is even pointing to the same link. Not sure if scraping from python side would be a good idea since it may be outdated later on. I wonder if the rustdoc team can help on this. Let me ping @jyn514 first.

But if we want to make it easier, a macro to indicate stable alternative may be easier than scraping from html text I believe.

@jyn514
Copy link
Member

jyn514 commented Nov 2, 2020

If you want this to be automated, you'll need an attribute on it anyway for rustdoc to understand it. At that point I think it makes more sense to just add #[deprecated("use the stable wrapper instead")], which can be added one by one without special casing from either clippy or rustdoc.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 3, 2020
Fix intrinsic size_of stable link

I noticed that it is pointing to the same link when I was reading
rust-lang/rust-clippy#2997
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 3, 2020
Fix intrinsic size_of stable link

I noticed that it is pointing to the same link when I was reading
rust-lang/rust-clippy#2997
@GuillaumeGomez
Copy link
Member

Working on it.

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-suggestion Lint: Improving, adding or fixing lint suggestions L-unnecessary Lint: Warn about unnecessary code
Projects
None yet
Development

Successfully merging a pull request may close this issue.