Skip to content

Incorrect span in for_loops_over_fallibles with macros #140747

Closed
@bvanjoi

Description

@bvanjoi

Code

fn main() {
    macro_rules! x {
        () => {
            None::<i32>
        };
    }
    for _ in x! {} {}
}

Current output

warning: for loop over an `Option`. This is more readably written as an `if let` statement
 --> crates/a/src/main.rs:4:13
  |
4 |             None::<i32>
  |             ^^^^^^^^^^^
...
7 |     for _ in x! {} {}
  |              ----- in this macro invocation
  |
  = note: `#[warn(for_loops_over_fallibles)]` on by default
  = note: this warning originates in the macro `x` (in Nightly builds, run with -Z macro-backtrace for more info)
help: to check pattern in a loop use `while let`
  |
4 ~             ) = 
5 |         };
6 |     }
7 ~     while let Some(_ in x! {} {}
  |
help: consider using `if let` to clear intent
  |
4 ~             ) = 
5 |         };
6 |     }
7 ~     if let Some(_ in x! {} {}
  |

Desired output

Ensure spans are either hidden or accurately displayed.

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.88.0-nightly (27d6200a7 2025-05-06)
binary: rustc
commit-hash: 27d6200a70601f6fcf419bf2f9e37989f3624ca4
commit-date: 2025-05-06
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.4

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions