-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix FP of identity_op
when encountering Default::default()
#15028
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 |
The current fix has false negatives at this code: fn test() -> usize {
0usize + &Default::default()
//~^ identity_op
}
fn main() {
let _n: usize = 0usize + &Default::default();
//~^ identity_op
} The lint also need to check whether the compiler can infer the type of I will make it ready when I finish. @rustbot author |
Reminder, once the PR becomes ready for a review, use |
37aacd0
to
e26f9be
Compare
e26f9be
to
7cb7e28
Compare
@rustbot ready |
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 have the feeling that this only solves one edge case but doesn't address the real problem. For example, the following code will fail as well:
trait Def {
fn def() -> Self;
}
impl Def for usize {
fn def() -> Self {
0
}
}
_ = 0usize + &Def::def();
The problem is not really the Default::default()
call, it is the fact that the associated function call returns a type which is neither given explicitly nor derived from the function arguments. Maybe checking this would solve the general case.
Thank you! I have modified the code. I have tried to find more cases about non-assoc function, but I can't. Now, the lint will exclude checking @rustbot ready |
It's strange. I passed the Now fixed. |
That's a reasonable approach, thanks! |
Fixes: #14932
changelog: Fix false positive of [
identity_op
] when encounteringDefault::default()
.