Skip to content

Commit 192c1d0

Browse files
committed
Explain the existience of the regression test
1 parent dcd46d6 commit 192c1d0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This test is a regression test for a bug where we only checked function calls in no-const
2+
// functions for `rustc_args_required_const` arguments. This meant that even though `bar` needs its
3+
// argument to be const, inside a const fn (callable at runtime), the value for it may come from a
4+
// non-constant (namely an argument to the const fn).
5+
16
#![feature(rustc_attrs)]
27
const fn foo(a: i32) {
38
bar(a); //~ ERROR argument 1 is required to be a constant
@@ -6,4 +11,8 @@ const fn foo(a: i32) {
611
#[rustc_args_required_const(0)]
712
const fn bar(_: i32) {}
813

9-
fn main() {}
14+
fn main() {
15+
// this function call will pass a runtime-value (number of program arguments) to `foo`, which
16+
// will in turn forward it to `bar`, which expects a compile-time argument
17+
foo(std::env::args().count() as i32);
18+
}

src/test/ui/consts/const_arg_promotable2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: argument 1 is required to be a constant
2-
--> $DIR/const_arg_promotable2.rs:3:5
2+
--> $DIR/const_arg_promotable2.rs:8:5
33
|
44
LL | bar(a);
55
| ^^^^^^

0 commit comments

Comments
 (0)