Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
memoryruins opened this issue Oct 11, 2019 · 5 comments · Fixed by #65320
Closed

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

memoryruins opened this issue Oct 11, 2019 · 5 comments · Fixed by #65320
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@memoryruins
Copy link
Contributor

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.

@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Oct 11, 2019

This feels like it's related to a similar issue (#61058) I created a while back.

@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 11, 2019
@Centril
Copy link
Contributor

Centril commented Oct 11, 2019

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Oct 11, 2019

This is probably because the "error" is just a lint. And we appear to silence it in external macros. We shouldn't do that. IIRC this is just a flag that needs to be set for the CONST_ERR lint macro

@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Oct 11, 2019
@Mark-Simulacrum
Copy link
Member

Yes, we need to set report_in_external_macro param on the lint I believe

@memoryruins
Copy link
Contributor Author

Ah, that makes sense! Building locally with the parameter set to confirm.
@rodrimati1992 it does ^^ will check the samples in there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants