Skip to content
Permalink
Browse files

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

  • Loading branch information...
oli-obk committed Jun 5, 2019
1 parent acda261 commit dcd46d6b67710b4991aebdb4d6e53b15fe26479a
@@ -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();
@@ -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() {}
@@ -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

0 comments on commit dcd46d6

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