Skip to content

Commit dcd46d6

Browse files
committed
Don't allow using const fn arguments as "args_required_const"
1 parent acda261 commit dcd46d6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
13041304
}
13051305
}
13061306

1307-
if self.mode == Mode::Fn {
1307+
// No need to do anything in constants and statics, as everything is "constant" anyway
1308+
// so promotion would be useless.
1309+
if self.mode != Mode::Static && self.mode != Mode::Const {
13081310
let constant_args = callee_def_id.and_then(|id| {
13091311
args_required_const(self.tcx, id)
13101312
}).unwrap_or_default();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(rustc_attrs)]
2+
const fn foo(a: i32) {
3+
bar(a); //~ ERROR argument 1 is required to be a constant
4+
}
5+
6+
#[rustc_args_required_const(0)]
7+
const fn bar(_: i32) {}
8+
9+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: argument 1 is required to be a constant
2+
--> $DIR/const_arg_promotable2.rs:3:5
3+
|
4+
LL | bar(a);
5+
| ^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)