-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Warn by default when casting a pointer to an integer smaller than usize #1782
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
Conversation
I don't like platform dependent warnings. Rust code is supposed to be platform independent, except for things inside cfg blocks. What comes next, a warn for |
I think I'd honestly be fine warning when casting a pointer to anything other than a |
cc #1052 |
I'd rather throw it into clippy (as suggested in the alternatives) and create an RFC for moving lints from clippy to rustc (#1501). |
Will there ever be platforms where a pointer does not fit into 64 bits? |
It's possible, but in that case |
I asked because I want to convert |
This has come up before in whether a |
I agree with @sfackler that warning when not casting to usize probably makes sense. As for the matter of "platform dependent lints", I still think that the overall strategy of ensuring that rust code is portable to major platforms by default, but providing opt-in lints or other tools for ensuring compliance beyond that makes sense. I'm not sure how much discussion about this idea has been happening lately. That said, it might be that I'd rather see this change happen as part of a bigger suite of changes addressing integer sizes conversions. |
If the official recommendation is that isize and usize should only be used for pointers, and memory sizes, then this lint seems like a rather good idea (even if it's only in clippy for now). |
@vks @sfackler @nikomatsakis |
So I think there are two main questions to resolve here:
I'm inclined to say: it's ok to add new lints to rustc that fall into the "almost certainly a bug" category. I'd be wary of style lints. I'm not sure what to think about target dependent lints, but I find the reasoning in the RFC reasonably persuasive. I'd be interested to hear if @aturon thinks that indeed scenarios do apply here (the mechanism described in the current RFC is not obviously applicable, right?). |
@petrochenkov indeed, I'll have to review #37423 and compare I guess. From skimming the comments it seems the sense was "let's figure out how this interacts with scenarios"...maybe we have a better idea of that now? |
I agree. Clippy is more for things which are less certain or not bugs. We do have a bunch of "almost certainly a bug" lints -- I think they're fine where they are, but would be open to upstreaming too. |
This seems like another case of the "you have to use Has |
Just to weigh in from the perspective of the portability lint RFC: the whole point of that RFC is to add a platform-specific lint, so this seems fine on that front at least. If we wanted to aim for maximum alignment with the portability lint, we'd want to warn when e.g. going from I'm about to merge the portability lint RFC, and as far as I'm concerned, this RFC is basically an implementation issue for that one. So we might consider punting on this RFC, getting the initial implementation working, and then revisiting this as a PR later (when we have more experience). |
@rfcbot fcp postpone I agree with @aturon's comment here:
Let's get the portability lint underway. At that point, I think we can see whether we feel this is a natural consequence thereof (and hence just implement it) or it we want to revisit the RFC in that context. (Thanks to @comex for a good RFC in any case.) |
Team member @nikomatsakis has proposed to postpone this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
1 similar comment
🔔 This is now entering its final comment period, as per the review above. 🔔 |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
Closing as postponed. Thanks again, @comex! |
As it says on the tin.
Rendered