Skip to content

Commit

Permalink
Explain the existience of the regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 5, 2019
1 parent dcd46d6 commit 192c1d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/test/ui/consts/const_arg_promotable2.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion src/test/ui/consts/const_arg_promotable2.stderr
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^
Expand Down

0 comments on commit 192c1d0

Please sign in to comment.