-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[arithmetic_side_effects
] Fix #10792
#10793
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
r? @Manishearth (rustbot has picked a reviewer for you, use r? to override) |
clippy_utils/src/consts.rs
Outdated
_ => None, | ||
} | ||
mir::ConstantKind::Val(ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() { | ||
ty::Adt(_, _) => Some(Constant::Int(int.assert_bits(int.size()))), |
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.
Initially I thought of bringing the field's ident from ExprKind::Field
to here in order to search the actual type with something like def.all_fields().find(|field| ... match ident logic ...)
but then I realized that someone probably already did this in a clever way.
The problem is, I don't know any other way. Do you have any thoughts about this matter?
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.
Hey @rust-lang/clippy, has someone maybe worked mir and has an idea how to solve this? :)
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.
My search in the deepest and darkest parts of Rustc wasn't a success and since no one else replied, I moved forward with the initial idea. Hey, at least it is working 🙄
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.
Would be better to add a variant to Constant
to hold struct types and then resolve fields as they come up. The variant can just be a reference to an allocation.
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 sorry @Jarcho, can you elaborate?
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'm guessing he recommends adding a new variant like Constant::Field(bits-as-int)
and let the lint handle the type of the bits inside. Does that make sense? And @Jarcho was this what you meant?
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.
Add something like Constant::Adt(ConstantKind<'tcx>)
, have Constant::fetch_path
return that when needed and then fields as needed in Constant::expr
.
You need to be handle any nested fields (e.g. a.b.c.d
) as well arrays and slices (can be done in a different pr).
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.
Add something like
Constant::Adt(ConstantKind<'tcx>)
, haveConstant::fetch_path
return that when needed and then fields as needed inConstant::expr
.
Done as requested
r? @xFrednet (limited internet this week, redirecting reviews) |
fa54b19
to
8f1ed40
Compare
This version looks good to me. Thank you for figuring this out :) Lord bors, would you be so kind and merge this PR :) |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
1 similar comment
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix #10792