about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-05 18:29:39 +0000
committerbors <bors@rust-lang.org>2019-06-05 18:29:39 +0000
commit7cdaffd7962c4aae0cadd82baa241901b03f9458 (patch)
treef053afdeb0cc36faa2d4c419cbf370e467c6d854 /src/test
parent47f4975cd751a03c941431b35cd7a6cba6201730 (diff)
parent694b0486371752cd75270788f30e19a16601f88d (diff)
downloadrust-7cdaffd7962c4aae0cadd82baa241901b03f9458.tar.gz
rust-7cdaffd7962c4aae0cadd82baa241901b03f9458.zip
Auto merge of #61548 - Centril:rollup-5t6cvbk, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #61503 (Fix cfg(test) build for x86_64-fortanix-unknown-sgx)
 - #61534 (Edit docs of ExitStatus)
 - #61536 (Don't allow using const fn arguments as "args_required_const")
 - #61538 (Don't use GNU noexec stack note)
 - #61546 (azure: Fix some minor issues which have broken our configuration )

Failed merges:

r? @ghost
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const_arg_promotable2.rs18
-rw-r--r--src/test/ui/consts/const_arg_promotable2.stderr8
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/ui/consts/const_arg_promotable2.rs b/src/test/ui/consts/const_arg_promotable2.rs
new file mode 100644
index 00000000000..3399e51ed4e
--- /dev/null
+++ b/src/test/ui/consts/const_arg_promotable2.rs
@@ -0,0 +1,18 @@
+// This test is a regression test for a bug where we only checked function calls in no-const
+// functions for `rustc_args_required_const` arguments. This meant that even though `bar` needs its
+// argument to be const, inside a const fn (callable at runtime), the value for it may come from a
+// non-constant (namely an argument to the const fn).
+
+#![feature(rustc_attrs)]
+const fn foo(a: i32) {
+    bar(a); //~ ERROR argument 1 is required to be a constant
+}
+
+#[rustc_args_required_const(0)]
+const fn bar(_: i32) {}
+
+fn main() {
+    // this function call will pass a runtime-value (number of program arguments) to `foo`, which
+    // will in turn forward it to `bar`, which expects a compile-time argument
+    foo(std::env::args().count() as i32);
+}
diff --git a/src/test/ui/consts/const_arg_promotable2.stderr b/src/test/ui/consts/const_arg_promotable2.stderr
new file mode 100644
index 00000000000..149d1ce8940
--- /dev/null
+++ b/src/test/ui/consts/const_arg_promotable2.stderr
@@ -0,0 +1,8 @@
+error: argument 1 is required to be a constant
+  --> $DIR/const_arg_promotable2.rs:8:5
+   |
+LL |     bar(a);
+   |     ^^^^^^
+
+error: aborting due to previous error
+