Skip to content

Commit

Permalink
Don't allow using const fn arguments as "args_required_const"
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 5, 2019
1 parent acda261 commit dcd46d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/const_arg_promotable2.rs
Original file line number Diff line number Diff line change
@@ -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() {}
8 changes: 8 additions & 0 deletions src/test/ui/consts/const_arg_promotable2.stderr
Original file line number Diff line number Diff line change
@@ -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.