Skip to content

Using while in const fn results in a misleading error message on stable #61508

Closed

Description

@not-an-aardvark

Playground Link

When while is used in a const fn on stable, it produces an error message: `if`, `match`, `&&` and `||` are not stable in const fn. This is a bit confusing because the function does not explicitly contain if, match, &&, or ||.

I would expect the error message to also mention that while is disallowed, or say that "loops are not allowed in const fn" (which it does when loop {} construct is encountered).

(It seems like it would be even better to have a specific error message for the disallowed construct that the compiler encounters rather than just providing a list of disallowed constructs, if this is possible architecturally.)

rustc version
rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-apple-darwin
release: 1.35.0
LLVM version: 8.0

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Jun 4, 2019
  2. added a commit that references this issue on Jun 11, 2019
    17393b2
  3. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions