Skip to content
Permalink
Browse files

Explain the existience of the regression test

  • Loading branch information...
oli-obk committed Jun 5, 2019
1 parent dcd46d6 commit 192c1d0717f2ba123b449a021257f2df571242d2
Showing with 11 additions and 2 deletions.
  1. +10 −1 src/test/ui/consts/const_arg_promotable2.rs
  2. +1 −1 src/test/ui/consts/const_arg_promotable2.stderr
@@ -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);
}
@@ -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);
| ^^^^^^

0 comments on commit 192c1d0

Please sign in to comment.
You can’t perform that action at this time.