Skip to content

Wrong error when loop keyword used outside loop but inside closure - E0267 #2454

@MahadMuhammad

Description

@MahadMuhammad

Wrong Error when loop keyword used inside of closure but outside of loop - E0267


I tried this code from E0267:

// https://doc.rust-lang.org/error_codes/E0267.html
#![allow(unused)]
fn main() {
let w = || { break; }; // error: `break` inside of a closure
}

I expected to see this happen:

  • Give error like rustc i.e.,
➜  mahad-testsuite rustc E0267.rs
error[E0267]: `break` inside of a closure
 --> E0267.rs:4:14
  |
4 | let w = || { break; }; // error: `break` inside of a closure
  |         --   ^^^^^ cannot `break` inside of a closure
  |         |
  |         enclosing closure

error: aborting due to previous error

For more information about this error, try `rustc --explain E0267`.

Instead, this happened:

➜  mahad-testsuite ../gccrs-build/gcc/crab1 E0267.rs                                                                            
E0267.rs:4:14: error:break’ outside of a loop or labeled block [E0268]
    4 | let w = || { break; }; // error: `break` inside of a closure
      |              ^~~~~
E0267.rs:4:9: fatal error: unable to find lang item: ‘fn_once’
    4 | let w = || { break; }; // error: `break` inside of a closure
      |         ^~
compilation terminated.

Meta

  • What version of Rust GCC were you using, git sha b8268b6.
  • gccrs (Compiler-Explorer-Build-gcc-866512cbc09bc883ef844b2b6cb70a72335756a7-binutils-2.40) 13.0.1 20230417 (experimental)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions