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

Report CONST_ERR lint in external macros #65320

Merged
merged 2 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ declare_lint! {
declare_lint! {
pub CONST_ERR,
Deny,
"constant evaluation detected erroneous expression"
"constant evaluation detected erroneous expression",
report_in_external_macro: true
}

declare_lint! {
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/consts/auxiliary/external_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(allow_internal_unstable)]

// Macro to help ensure CONST_ERR lint errors
// are not silenced in external macros.
// https://github.com/rust-lang/rust/issues/65300

#[macro_export]
#[allow_internal_unstable(type_ascription)]
macro_rules! static_assert {
($test:expr) => {
#[allow(dead_code)]
const _: () = [()][!($test: bool) as usize];
}
}
13 changes: 13 additions & 0 deletions src/test/ui/consts/const-external-macro-const-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// edition:2018
// aux-build:external_macro.rs

// Ensure that CONST_ERR lint errors
// are not silenced in external macros.
// https://github.com/rust-lang/rust/issues/65300

extern crate external_macro;
use external_macro::static_assert;

fn main() {
static_assert!(2 + 2 == 5); //~ ERROR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works outside "expression" scope too, right? Can we test it there? I seem to recall some differences, but maybe that was a transient state...

Copy link
Contributor Author

@memoryruins memoryruins Oct 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like the following? which now works too with the param set.

static_assert!(false); //~ ERROR
fn main() { /* ... */ }

}
11 changes: 11 additions & 0 deletions src/test/ui/consts/const-external-macro-const-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: any use of this value will cause an error
--> $DIR/const-external-macro-const-err.rs:12:5
|
LL | static_assert!(2 + 2 == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1
|
= note: `#[deny(const_err)]` on by default
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error