Small cleanup of option_if_let_else and additional tests.

This commit is contained in:
Jason Newcomb 2021-08-26 11:27:43 -04:00
parent 8b3ca9a315
commit 3e5dcba2ee
No known key found for this signature in database
GPG key ID: DA59E8643A37ED06
4 changed files with 57 additions and 17 deletions

View file

@ -174,9 +174,9 @@ fn detect_option_if_let_else<'tcx>(
ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) => Some(e),
_ => None,
});
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(l), .. })) = e.kind {
match some_captures.get(l)
.or_else(|| (method_sugg == "map_or_else").then(|| ()).and_then(|_| none_captures.get(l)))
if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(local_id), .. })) = e.kind {
match some_captures.get(local_id)
.or_else(|| (method_sugg == "map_or_else").then(|| ()).and_then(|_| none_captures.get(local_id)))
{
Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None,