rust-lang / rust-lang/rust

`const_evaluatable_unchecked` incorrectly triggers when capturing return type of parent const block

Open
#148,433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-diagnostics needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

fn main() {
    const {
        [0; const { 0 }];
    }
    
    const {
        [0; {
            let _ = || ();
            0
        }];
    }
}

results in

warning: cannot use constants which depend on generic parameters in types
 --> src/main.rs:3:13
  |
3 |         [0; const { 0 }];
  |             ^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
  = note: `#[warn(const_evaluatable_unchecked)]` (part of `#[warn(future_incompatible)]`) on by default

warning: cannot use constants which depend on generic parameters in types
  --> src/main.rs:7:13
   |
 7 |           [0; {
   |  _____________^
 8 | |             let _ = || ();
 9 | |             0
10 | |         }];
   | |_________^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>

This is a false positive and we should not lint here.

Issue discovered by @edwloef in #76200

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 by compiling the reproducer in src/main.rs and compare the two const-block cases under the const_evaluatable_unchecked lint. Trace where the lint is emitted for these expressions; done means neither case produces this false-positive warning, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.