From 4be041a2cd9f134ee42579beb14840b9abebcb75 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 15 May 2024 10:00:42 -0500 Subject: [PATCH] Also apply `warn(for_loops_over_fallibles)` to &T and &mut T, not just T = Result/Option. --- compiler/rustc_lint/src/for_loops_over_fallibles.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index a6876d8aae79..d766393db29a 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -52,7 +52,15 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles { let ty = cx.typeck_results().expr_ty(arg); - let &ty::Adt(adt, args) = ty.kind() else { return }; + // let &ty::Adt(adt, args) = ty.kind() else { return }; + let (adt, args, _) = match ty.kind() { + &ty::Adt(adt, args) => (adt, args, None), + &ty::Ref(_, ty, mutability) => match ty.kind() { + &ty::Adt(adt, args) => (adt, args, Some(mutability)), + _ => return, + }, + _ => return, + }; let (article, ty, var) = match adt.did() { did if cx.tcx.is_diagnostic_item(sym::Option, did) => ("an", "Option", "Some"),