Repository navigation
Fix let underscore place expr - #164994
yashaggarwal85d wants to merge 5 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.
| } | ||
|
|
||
| /// Whether `expr` is a place based on a local or a static, so no temporary is involved. | ||
| fn is_local_or_static_place(expr: &hir::Expr<'_>) -> bool { |
There was a problem hiding this comment.
I'm thinking about cases like:
let &_ = &m.lock().unwrap(); // Shouldn't lintand
fn identity<T>(x: &T) -> &T { x }
let _ = *identity(&NontrivialDrop); // Should lint
let d = NontrivialDrop;
let _ = *identity(&d); // Shouldn't lintI suspect we may not be able to cover the above cases at the HIR level by further modifying is_local_or_static_place. If so, I think that's fine. Our goal can be to reduce false positives as much as possible without introducing any new false negatives.
Could you investigate further whether we can eliminate more false positives? If not, I'd like to see some FIXME comments on is_local_or_static_place explaining its current limitations.
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