Skip to content

Check does not evaluate const assertion, build does #111240

Closed as not planned
Closed as not planned
@matthiasbeyer

Description

@matthiasbeyer

I tried this code:

struct Check;
impl Check {
    const CHECK: () = assert!(1 == 2);
}

fn main() {
    let _ = Check::CHECK;
}

(playground)

Above code does not build if you use the playground "run" button.
But the "build" button, which seems to be the equivalent to cargo-check on above code, does "build" (typecheck and everything).

This is reproducible with:

  • cargo-build/cargo-run does fail the build, as expected
  • cargo-check does not fail the build, unexpectedly

Meta

rustc --version --verbose:

rustc 1.69.0 (84c898d65 2023-04-16)                                                                                                                                                                                                            
binary: rustc                                                                                                                                                                                                                                  
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc                                                                                                                                                                                          
commit-date: 2023-04-16                                                                                                                                                                                                                        
host: x86_64-unknown-linux-gnu                                                                                                                                                                                                                 
release: 1.69.0                                                                                                                                                                                                                                
LLVM version: 15.0.7  

On the playground:

  • stable as described above
  • beta as described above
  • nightly as expected: the "build" button (cargo-check as I assume), fails as expected

Found with @TheNeikos, also thanks to them for helping me reducing the code example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions