Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MahadMuhammad opened this issue Jul 19, 2023 · 3 comments
Labels

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Jul 19, 2023

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)
@MahadMuhammad MahadMuhammad changed the title Wrong error when loop keyword used outside loop but inside closuer - [E0267](https://doc.rust-lang.org/error_codes/E0267.html) Wrong error when loop keyword used outside loop but inside closuer - E0267 Jul 19, 2023
@MahadMuhammad MahadMuhammad moved this to Issues for fixing error code support in Error Code Support & Improving User Errors Jul 19, 2023
@CohenArthur
Copy link
Member

The existing error code is wrong then - it should be E0268 https://doc.rust-lang.org/error_codes/E0268.html

And E267 is a special case for closures. So there are two issues - change the existing error code to E0268, and then special case closures and emit E0267 errors

@MahadMuhammad
Copy link
Contributor Author

@CohenArthur, I already changed the existing error code to E0268. Here's the PR #2453 I'll try to fix the special case. I opened this issue for fixing the special case ...

@MahadMuhammad MahadMuhammad changed the title Wrong error when loop keyword used outside loop but inside closuer - E0267 Wrong error when loop keyword used outside loop but inside closure - E0267 Jul 20, 2023
@CohenArthur
Copy link
Member

Ah, sorry :D didn't catch up to all the PRs yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants