Skip to content

Commit 643261a

Browse files
authored
Rollup merge of #65320 - memoryruins:const_err, r=oli-obk
Report `CONST_ERR` lint in external macros fixes #65300 fixes #61058 r? @oli-obk
2 parents 433ea1a + 95a65cd commit 643261a

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/librustc/lint/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ declare_lint! {
2121
declare_lint! {
2222
pub CONST_ERR,
2323
Deny,
24-
"constant evaluation detected erroneous expression"
24+
"constant evaluation detected erroneous expression",
25+
report_in_external_macro: true
2526
}
2627

2728
declare_lint! {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(allow_internal_unstable)]
2+
3+
// Macro to help ensure CONST_ERR lint errors
4+
// are not silenced in external macros.
5+
// https://github.com/rust-lang/rust/issues/65300
6+
7+
#[macro_export]
8+
#[allow_internal_unstable(type_ascription)]
9+
macro_rules! static_assert {
10+
($test:expr) => {
11+
#[allow(dead_code)]
12+
const _: () = [()][!($test: bool) as usize];
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2018
2+
// aux-build:external_macro.rs
3+
4+
// Ensure that CONST_ERR lint errors
5+
// are not silenced in external macros.
6+
// https://github.com/rust-lang/rust/issues/65300
7+
8+
extern crate external_macro;
9+
use external_macro::static_assert;
10+
11+
fn main() {
12+
static_assert!(2 + 2 == 5); //~ ERROR
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: any use of this value will cause an error
2+
--> $DIR/const-external-macro-const-err.rs:12:5
3+
|
4+
LL | static_assert!(2 + 2 == 5);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1
6+
|
7+
= note: `#[deny(const_err)]` on by default
8+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)