-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Simplify some of the logic in the invalid_reference_casting
lint
#116199
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? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
I'm not so sure about the last commit, it fixes the ICEs in #116199 (comment) but at the cost a new scaled down function, just to avoid outside expr outside the current body. Maybe we should check that the result of |
/// dbg!(def); | ||
/// // ^^^ input | ||
/// ``` | ||
pub fn expr_or_init<'a>(&self, mut expr: &'a hir::Expr<'tcx>) -> &'a hir::Expr<'tcx> { |
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.
Isn't it a bit dangerous to change the other method's name and reusing it for this one?
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.
Yes, a bit, but the function was added very recently, has only one user (the utf8 lints) and it is now better matching the similar function from clippy: clippy_utils::expr_or_init
.
arg | ||
} else if had_at_least_one_cast { |
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.
IIUC, this flag is an optimization to avoid calling node_type
if we haven't seed any cast. Is this worth it? node_type
is a simple hashmap lookup.
This deserves at least a comment.
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.
Since we are now checking the end type at the start, I agree keeping this flag doesn't seems compelling enough. Removed.
ffb8f04
to
1b2c1a8
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1393ef1): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 631.024s -> 630.971s (-0.01%) |
This PR simplifies 2 areas of the logic for the
invalid_reference_casting
lint:expr_or_init
function instead of a manual detectionThose two simplifications permits us to detect more cases, as can be seen in the test output changes.