Repository navigation
Fix let underscore place expr - #164994
yashaggarwal85d wants to merge 7 commits into
Conversation
|
r? @mu001999 rustbot has assigned @mu001999. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Reminder, once the PR becomes ready for a review, use |
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
|
Reopening after a conversation with the author |
|
@bors try |
…, r=<try> Fix let underscore place expr
This comment has been minimized.
This comment has been minimized.
|
Two more false positives are still left, and I’m not sure they’re worth the extra code in this PR: let (_, &_) = (1, &m.lock().unwrap()); // borrow inside a tuple
let S { ref a, b: _ } = temp(); // `ref a` extends the temporaryIn both cases the lock stays held, but it still lints. Should I add them to the FIXME on is_local_or_static_place, or try to handle them here? |
|
@rust-timer queue Let's check the perf first. |
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…, r=<try> Fix let underscore place expr
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (240909c): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -3.1%, secondary 1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 487.353s -> 486.474s (-0.18%) |
|
|
||
| /// Whether `expr` borrows a temporary whose lifetime is extended past the `let`, like | ||
| /// `let &_ = &m.lock().unwrap();`, and `pat` doesn't look behind any other reference. | ||
| fn borrows_extended_temporary( |
There was a problem hiding this comment.
Could we achieve this by simply checking the pattern is ref and the ty needs drop or is lock guard? 🤔
There was a problem hiding this comment.
I thought about that, but only checking for a ref pattern would stop linting cases where the lock really is dropped, like let &_ = identity(&m.lock()) or let &&_ = &identity(&m.lock()). Happy to switch to the simpler check if you think those false negatives are fine though
|
Thanks for the trying! IMO, I'll approve this after the removal, but I'd like to refer it to another reviewer for a second opinion. So you don't need to remove it for now. r? estebank, since you approved #97739 :) |
View all comments
let _ = y;whereyis a local guard doesn't move or dropy, butlet_underscore_lock(deny by default) says the lock is released immediately and suggestsdrop(y), which would change behaviour. Same forlet_underscore_drop.This skips the lint when the let initializer is a place expression. Temporaries still lint,
including fields of temporaries like
(m.lock(), 1).0.Fixes #164746
cc @theemathas @traviscross