-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix cast-lossless
should not suggest when casting type is from macro input
#15358
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
rustbot has assigned @samueltardieu. Use |
Lintcheck changes for 938e79f
This comment will be updated if you push new changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit puzzled by the proposed fix. For example, what should happen in the following case?
macro_rules! zero {
($int:ty) => {{
let data: [u16; 3] = [0, 0, 0];
data[0] as $int
}};
}
let _ = zero!(u8);
let _ = zero!(u16);
let _ = zero!(u32);
let _ = zero!(u64);
let _ = zero!(u128);
If Clippy gives a suggestion (as it does because of the u32
, u64
, and u128
cases) and the user applies it, then the code with u8
won't compile anymore. Isn't that dangerous to presume that the from()
type relative function can be used just because one instance (or three in this case) appears to allow it?
In the proposed fix, no lint will be given for |
I think it should be silenced, because you cannot "fix" the macro if that could make some other uses of it not compile because of this fix. |
What do you mean? |
@samueltardieu Updated. Now they are silenced. |
In the reproducer given in #15348, The
But it should be:
This might be a bug in rustc |
This might be fixed by rust-lang/rust#144711. |
Closes #15348
The span of the
as
expr is also incorrect, but I believe it is not a bug from Clippy.changelog: [
cast-lossless
] fix wrong suggestions when casting type is from macro input