Don't allow using const fn arguments as "args_required_const"
This commit is contained in:
parent
acda261de8
commit
dcd46d6b67
3 changed files with 20 additions and 1 deletions
|
@ -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| {
|
let constant_args = callee_def_id.and_then(|id| {
|
||||||
args_required_const(self.tcx, id)
|
args_required_const(self.tcx, id)
|
||||||
}).unwrap_or_default();
|
}).unwrap_or_default();
|
||||||
|
|
9
src/test/ui/consts/const_arg_promotable2.rs
Normal file
9
src/test/ui/consts/const_arg_promotable2.rs
Normal 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() {}
|
8
src/test/ui/consts/const_arg_promotable2.stderr
Normal file
8
src/test/ui/consts/const_arg_promotable2.stderr
Normal 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
|
||||||
|
|
Loading…
Reference in a new issue