Skip to content

rustc_data_structures::static_assert!(false) does not error #65300

Closed
@memoryruins

Description

@memoryruins

1.40.0-nightly 2019-10-09 20cc75272619cc452e3a

The following does not error locally / on the playground https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9dde03338a31e2f40491a66dc3a18761

#![feature(rustc_private)]

extern crate rustc_data_structures;
use rustc_data_structures::static_assert;

fn main() {
    // doesn't error, but should
    static_assert!(2 + 2 == 5);

    // correctly errors when uncommented
    // const _: () = [()][!(2 + 2 == 5) as usize];

    // https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_data_structures/macros.rs.html#4-11
}

If I copy paste the macro into the same file, it errors as expected https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=bec79345cfe7cecf1b92eed6c2736152

error: any use of this value will cause an error
  --> src/main.rs:11:23
   |
11 |         const _: () = [()][!($test: bool) as usize];
   |         --------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
   |                       |
   |                       index out of bounds: the len is 1 but the index is 1
...
16 |     static_assert!(2 + 2 == 5);
   |     --------------------------- in this macro invocation
   |
   = note: `#[deny(const_err)]` on by default

Checking other macros, rustc_data_structures::static_assert_size (which is defined next to static_assert) and static_assertions::const_assert error as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions