Don't allow using const fn arguments as "args_required_const"

This commit is contained in:
Oliver Scherer 2019-06-05 09:37:16 +02:00
parent acda261de8
commit dcd46d6b67
3 changed files with 20 additions and 1 deletions

View file

@ -1304,7 +1304,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
}
}
if self.mode == Mode::Fn {
// No need to do anything in constants and statics, as everything is "constant" anyway
// so promotion would be useless.
if self.mode != Mode::Static && self.mode != Mode::Const {
let constant_args = callee_def_id.and_then(|id| {
args_required_const(self.tcx, id)
}).unwrap_or_default();

View file

@ -0,0 +1,9 @@
#![feature(rustc_attrs)]
const fn foo(a: i32) {
bar(a); //~ ERROR argument 1 is required to be a constant
}
#[rustc_args_required_const(0)]
const fn bar(_: i32) {}
fn main() {}

View file

@ -0,0 +1,8 @@
error: argument 1 is required to be a constant
--> $DIR/const_arg_promotable2.rs:3:5
|
LL | bar(a);
| ^^^^^^
error: aborting due to previous error