- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.L-for_loops_over_falliblesLint: for_loops_over_falliblesLint: for_loops_over_falliblesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
src/main.rs
fn main() {
    let _name = Some(1);
    dep::do_loop!(_name);
}dep/src/lib.rs
#[macro_export]
macro_rules! identity {
    ($x:ident) => {
        $x
    };
}
#[macro_export]
macro_rules! do_loop {
    ($x:ident) => {
        for $crate::identity!($x) in $x {}
    };
}Zip of all files needed for reproduction, for your convenience: repro.zip
Current output
warning: for loop over an `Option`. This is more readably written as an `if let` statement
 --> src\main.rs:3:5
  |
3 |     dep::do_loop!(_name);
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(for_loops_over_fallibles)]` on by default
help: to check pattern in a loop use `while let`
 --> C:\Users\theem\Downloads\repro\dep\src\lib.rs:4:9
  |
4 ~         while let Some(for $crate::identity!($x) in $x {}
5 ~         ) =
  |
help: consider using `if let` to clear intent
 --> C:\Users\theem\Downloads\repro\dep\src\lib.rs:4:9
  |
4 ~         if let Some(for $crate::identity!($x) in $x {}
5 ~         ) =
  |
warning: `repro` (bin "repro") generated 1 warningDesired output
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-pc-windows-msvc
release: 1.90.0
LLVM version: 20.1.8Anything else?
Discovered in #147973 as part of a crater run, in which rust gave the invalid suggestion in 1.90.0, but ICE'ed in beta.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.L-for_loops_over_falliblesLint: for_loops_over_falliblesLint: for_loops_over_falliblesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.