-
Notifications
You must be signed in to change notification settings - Fork 707
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
Remove all casts that use the as
operator
#31
Comments
|
Thanks, Ms2ger. I'm looking forward to taking advantage of that. See rust-lang/rfcs#1218 and rust-lang/rust#28921. I left a comment rust-lang/rust#28921 (comment) wherein I ask for additional cast-free conversions. As part of fixing this issue, or in a follow-up, we should add a lint (static analysis) that verifies there are no uses of |
Fixed, at least as far as the current state of the code goes, in 377f611 and a8276b2. One line of test code from 377f611 casts |
This will become an issue against as we'll be casting |
For the ones where implicit conversion doesn't work yet (e.g. conversions to/from
(from https://internals.rust-lang.org/t/the-problem-with-array-slice-vector-indexes/3129) |
In sha1.rs there is now this:
We should make a function and put it in ring::polyfill to avoid using /cc @SimonSapin |
I don’t mind moving that line into a separate function, but I don’t see how that would improve safety. As long as the input is a |
The goal of the polyfill submodule is to identify missing functionality in Rust's stdlib or language where the lack of the functionality forces a program to unnecessarily use Similarly, the long-term goal of this ring issue is to shape ring into an example that demonstrates that we can (and should) live without the Normally I don't merge any changes with |
I believe there is a non-default clippy lint for this so we should be able to enable that lint to verify this. |
Quoting the documentation for
And, sure enough, it looks like "just" enabling the However, PR #1784 still leaves some things to be desired; see that PR for details. |
PR #1892 removes Pointer -> usize conversions that were done for the purpose of aligning pointers. I believe that's the last change that warrants having a tracking issue, so I'm closing this. |
Rust doesn't have implicit widening, so casts that are lossy (not necessarily safe) look just like casts that are 100% safe. Instead of using the
as
operator for widening casts, we should use (and create, if necessary) functions that safely do widening conversions, and use those. Then the use ofas
would be limited to only those functions.This depends on #4.
The text was updated successfully, but these errors were encountered: