Skip to content

const_evaluatable_unchecked incorrectly triggers when capturing return type of parent const block #148433

@lcnr

Description

@lcnr
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

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 lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions