about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZachary S <zasample18+github@gmail.com>2024-05-15 10:00:42 -0500
committerZachary S <zasample18+github@gmail.com>2024-05-15 11:05:44 -0500
commit4be041a2cd9f134ee42579beb14840b9abebcb75 (patch)
tree084683825c0b9da3cff8eab88384d831b5bda139
parentade234d5743795423db6cc7cd52541390a088eab (diff)
downloadrust-4be041a2cd9f134ee42579beb14840b9abebcb75.tar.gz
rust-4be041a2cd9f134ee42579beb14840b9abebcb75.zip
Also apply `warn(for_loops_over_fallibles)` to &T and &mut T, not just T = Result/Option.
-rw-r--r--compiler/rustc_lint/src/for_loops_over_fallibles.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs
index a6876d8aae7..d766393db29 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"),