diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-06-05 09:37:16 +0200 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-06-05 09:49:04 +0200 |
| commit | dcd46d6b67710b4991aebdb4d6e53b15fe26479a (patch) | |
| tree | bf64bbea71b363916599daac650a03dccd8ed2ae | |
| parent | acda261de83475cf6cbc607d570153bb864ee7be (diff) | |
| download | rust-dcd46d6b67710b4991aebdb4d6e53b15fe26479a.tar.gz rust-dcd46d6b67710b4991aebdb4d6e53b15fe26479a.zip | |
Don't allow using const fn arguments as "args_required_const"
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/consts/const_arg_promotable2.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/consts/const_arg_promotable2.stderr | 8 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index fe94181047f..8696291e058 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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(); diff --git a/src/test/ui/consts/const_arg_promotable2.rs b/src/test/ui/consts/const_arg_promotable2.rs new file mode 100644 index 00000000000..5d9400a907b --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable2.rs @@ -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() {} diff --git a/src/test/ui/consts/const_arg_promotable2.stderr b/src/test/ui/consts/const_arg_promotable2.stderr new file mode 100644 index 00000000000..67a1132f830 --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable2.stderr @@ -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 + |
