Skip to content

Commit 4be041a

Browse files
committed
Also apply warn(for_loops_over_fallibles) to &T and &mut T, not just T = Result/Option.
1 parent ade234d commit 4be041a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compiler/rustc_lint/src/for_loops_over_fallibles.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
5252

5353
let ty = cx.typeck_results().expr_ty(arg);
5454

55-
let &ty::Adt(adt, args) = ty.kind() else { return };
55+
// let &ty::Adt(adt, args) = ty.kind() else { return };
56+
let (adt, args, _) = match ty.kind() {
57+
&ty::Adt(adt, args) => (adt, args, None),
58+
&ty::Ref(_, ty, mutability) => match ty.kind() {
59+
&ty::Adt(adt, args) => (adt, args, Some(mutability)),
60+
_ => return,
61+
},
62+
_ => return,
63+
};
5664

5765
let (article, ty, var) = match adt.did() {
5866
did if cx.tcx.is_diagnostic_item(sym::Option, did) => ("an", "Option", "Some"),

0 commit comments

Comments
 (0)