Rust-GCC / Rust-GCC/gccrs

Unexpected "cannot find value in this scope" error when compiling `core/src/fmt/mod.rs`

Open
#4,560 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Summary

Compiling libgrust/rustc-lib/core/src/fmt/mod.rs produces cannot find value ‘ZEROES’ in this scope [E0425] errors, which is unexpected as ZEROES was declared properly. The problematic code in question:

...
    for part in formatted.parts {
        match *part {
            flt2dec::Part::Zero(mut nzeroes) => {
                const ZEROES: &str = // 64 zeroes
                    "0000000000000000000000000000000000000000000000000000000000000000";
                while nzeroes > ZEROES.len() {
                    self.buf.write_str(ZEROES)?;
                    nzeroes -= ZEROES.len();
                }
                if nzeroes > 0 {
                    self.buf.write_str(&ZEROES[..nzeroes])?;
                }
            }
            flt2dec::Part::Num(mut v) => {
                let mut s = [0; 5];
                let len = part.len();
                for c in s[..len].iter_mut().rev() {
                    *c = b'0' + (v % 10) as u8;
                    v /= 10;
                }
                write_bytes(self.buf, &s[..len])?;
            }
            flt2dec::Part::Copy(buf) => {
                write_bytes(self.buf, buf)?;
            }
        }
    }
...

Reduced (note that there's no #![feature(no_core)] and #![no_core]):

fn main() -> i32 {
    let mut a = 0;
    for a in 0..10 {
        const zero: i32 = 0;
        a += zero;
    }
}
Reproducer

Compile PATH_TO_GCCRS/libgrust/rustc-lib/core/src/fmt/mod.rs with crab1.

Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

No response

Actual behavior

cannot find value ‘ZEROES’ in this scope [E0425]

Expected behavior

No errors.

GCC Version

5c63b4c0d93d20efd014ccfd4250d82e27c3a23b

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced Rust reproducer and the reported core/src/fmt/mod.rs case, then run them with crab1 to confirm the E0425 diagnostic. Trace how the compiler handles the const declaration inside the for loop and compare the result with the expected successful compilation. Done means both reproductions compile without the cannot-find-value error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.