Skip to content

Rustc behaviour with loops in const/static context #3783

@philberty

Description

@philberty
          Nice work but i just realised yes this need another change sorry. This null_tree check should still stay but you need another check the error should be:
error[E0658]: `loop` is not allowed in a `static`
 --> <source>:1:17
  |
1 | static _X: () = loop {};
  |                 ^^^^^^^
  |
  = note: see issue #52000 <https://github.com/rust-lang/rust/issues/52000> for more information

error: aborting due to previous error

So what you need to do is add a catch here:

TyTy::BaseType *block_tyty = nullptr;

if (ctx->const_context_p ())
 {
     rich_location r;
     rust_error_at (r, ErrorCode::0658, "%<loop%> is not allowed in const context");
     return;
  }

Originally posted by @philberty in #3781 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions