about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-13 13:34:36 +0200
committerGitHub <noreply@github.com>2019-10-13 13:34:36 +0200
commit643261aad437d5f0b2e8af0702337df2f41b3318 (patch)
tree350c948a57f3378e4c0a6025e7c6a5d372b17be7
parent433ea1a03011cd5de595274c2736f26340ce5875 (diff)
parent95a65cd1e3d0242339d71326cfdd638e869a37d6 (diff)
downloadrust-643261aad437d5f0b2e8af0702337df2f41b3318.tar.gz
rust-643261aad437d5f0b2e8af0702337df2f41b3318.zip
Rollup merge of #65320 - memoryruins:const_err, r=oli-obk
Report `CONST_ERR` lint in external macros

fixes #65300
fixes #61058

r? @oli-obk
-rw-r--r--src/librustc/lint/builtin.rs3
-rw-r--r--src/test/ui/consts/auxiliary/external_macro.rs14
-rw-r--r--src/test/ui/consts/const-external-macro-const-err.rs13
-rw-r--r--src/test/ui/consts/const-external-macro-const-err.stderr11
4 files changed, 40 insertions, 1 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index 5ca474a8b1d..983e3a9922e 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -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! {
diff --git a/src/test/ui/consts/auxiliary/external_macro.rs b/src/test/ui/consts/auxiliary/external_macro.rs
new file mode 100644
index 00000000000..d260634c996
--- /dev/null
+++ b/src/test/ui/consts/auxiliary/external_macro.rs
@@ -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];
+    }
+}
diff --git a/src/test/ui/consts/const-external-macro-const-err.rs b/src/test/ui/consts/const-external-macro-const-err.rs
new file mode 100644
index 00000000000..616d24f4a7b
--- /dev/null
+++ b/src/test/ui/consts/const-external-macro-const-err.rs
@@ -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
+}
diff --git a/src/test/ui/consts/const-external-macro-const-err.stderr b/src/test/ui/consts/const-external-macro-const-err.stderr
new file mode 100644
index 00000000000..237c4d792c9
--- /dev/null
+++ b/src/test/ui/consts/const-external-macro-const-err.stderr
@@ -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
+