]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const_arg_promotable2.rs
Auto merge of #64546 - weiznich:bugfix/rfc-2451-rerebalance-tests, r=nikomatsakis
[rust.git] / src / test / ui / consts / const_arg_promotable2.rs
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
6 #![feature(rustc_attrs)]
7 const fn foo(a: i32) {
8     bar(a); //~ ERROR argument 1 is required to be a constant
9 }
10
11 #[rustc_args_required_const(0)]
12 const fn bar(_: i32) {}
13
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 }