-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Move the trivial_numeric_casts lint to allow-by-default #1020
Comments
I do not oppose this change. I think we ended up with warn by default by miscommunication, rather than intention. I marginally prefer warn by default because I think that ought to be the default behaviour for most integer casts, but I think I have a much higher tolerance for |
See also rust-lang/rust#23734 |
If only someone had mentioned this exact problem during the RFC discussion. |
At the risk of sounding repetitive, what about an attribute (maybe |
I would much prefer to have the lint simply not warn if casting between type aliases. Warning me by default when I say something like Note that this isn't just an issue with type aliases that may vary by configuration, it's also an issue with type aliases where the programmer simply doesn't necessarily know which concrete type the type alias is an alias for (and isn't required to know either; if they were then why would I be using a type alias?) or does know but simply wants to make it clear to any potential readers that they're intentionally using the type alias because it carries some semantic meaning. |
This appears to have happened: https://play.rust-lang.org/?gist=227c8025f371351c94cc404a57765c23&version=stable |
This lint was recently added in rust-lang/rust#23630 as part of #803 and it disallows casts such as
foo as i64
whenfoo
has the typei64
.In theory this does sound like a lint which is nice to have, but I've found that in the context of FFI it's doesn't always play out so well. Because
libc::c_int
is simply an alias of some concrete primitive type, it is typically casted out into a known integer to be worked with in Rust. In this specific case the target type ofi32
is frequently chosen, triggering this lint. Having to annotate crates with#[allow(trivial_numeric_casts)]
is somewhat annoying for this common use case, and the broader lint (trivial_casts
) seems more relevant to remain as warn-by-default.cc @nrc
The text was updated successfully, but these errors were encountered: