Assume that any external function might return a type alias#16415
Assume that any external function might return a type alias#16415dswij merged 1 commit intorust-lang:masterfrom
Conversation
|
Draft for the time being, in order to get a lintcheck run. |
e66a412 to
802b354
Compare
|
Lintcheck changes for 759c2bf
This comment will be updated if you push new changes |
802b354 to
39f281d
Compare
|
Well, lintcheck shows that we detect more cases by doing it more cleanly. We could also exclude code behind rust-src if we have a way to detect this easily, but this might be overkill. Undrafting. |
We might not have the declaration around if `extern crate` is used, or if rust-src is not installed for the standard library. Better err on the safe side rather than having a behavior depending on what happens to be available at compile time.
39f281d to
759c2bf
Compare
|
The lint emission in libc is wrong. |
It is just a manifestation of an existing shortcoming which already exists and was masked in libc at just this line for whatever reason. Other casts in this file were already detected the same way. There are no attempts to detect type aliases in struct fields or tuple definitions. The following program exhibits this shortcoming both before and after this PR: #![allow(unused)]
#![deny(clippy::unnecessary_cast)]
type I = i32;
struct S {
i: I,
}
fn main() {
let s = S { i: 42 };
let i = s.i as i32;
}$ clippy-driver t.rs
error: casting to the same type is unnecessary (`i32` -> `i32`)
--> t.rs:11:13
|
11 | let i = s.i as i32;
| ^^^^^^^^^^ help: try: `s.i` |
We might not have the declaration around if
extern crateis used, or if rust-src is not installed for the standard library. Better err on the safe side rather than having a behavior depending on what happens to be available at compile time.Fixes #14625
changelog: [
unnecessary_cast]: do not warn on casts of external function return type