Skip to content

rustc --explain E0744 says "while" is forbidden but accepts it nontheless #79083

Closed
@karolherbst

Description

@karolherbst

I have to use some sort of loop construct within a const function. rustc --explain E0744 does explain that loop constructs are at the moment not supported, but as I was trying out for first and the compiler rejected it, it would have been helpful if the explanation would hint me towards while working.

I think the doc just needs a small update and I think the file to update is https://github.com/rust-lang/rust/blob/master/compiler/rustc_error_codes/src/error_codes/E0744.md

I tried this code:

const fn foo() -> [u8; 10] {
    let mut a = [0; 10];
    let b = b"hi";
    let mut i = 0;
    while i < b.len() {
        a[i] = b[i];
        i += 1;
    }
    
    a
}

pub const BAR: [u8; 10] = foo();

Meta

rustc --version --verbose:

rustc 1.47.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Metadata

Metadata

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-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