From 192c1d0717f2ba123b449a021257f2df571242d2 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 5 Jun 2019 13:25:17 +0200 Subject: [PATCH] Explain the existience of the regression test --- src/test/ui/consts/const_arg_promotable2.rs | 11 ++++++++++- src/test/ui/consts/const_arg_promotable2.stderr | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/ui/consts/const_arg_promotable2.rs b/src/test/ui/consts/const_arg_promotable2.rs index 5d9400a907bde..3399e51ed4edb 100644 --- a/src/test/ui/consts/const_arg_promotable2.rs +++ b/src/test/ui/consts/const_arg_promotable2.rs @@ -1,3 +1,8 @@ +// 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 @@ -6,4 +11,8 @@ const fn foo(a: i32) { #[rustc_args_required_const(0)] const fn bar(_: i32) {} -fn main() {} +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 index 67a1132f830f2..149d1ce89408d 100644 --- a/src/test/ui/consts/const_arg_promotable2.stderr +++ b/src/test/ui/consts/const_arg_promotable2.stderr @@ -1,5 +1,5 @@ error: argument 1 is required to be a constant - --> $DIR/const_arg_promotable2.rs:3:5 + --> $DIR/const_arg_promotable2.rs:8:5 | LL | bar(a); | ^^^^^^