From e67050e8b6cbf48d041eb5f3993d620402073a7a Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 27 Feb 2019 17:41:25 +0100 Subject: [PATCH 1/2] Don't promote function calls to nonpromotable things --- src/librustc_mir/transform/qualify_consts.rs | 7 ++----- src/test/ui/consts/invalid_promotion.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/consts/invalid_promotion.rs diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 285c674643f2e..73ac68c4ac3b4 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -507,7 +507,7 @@ impl Qualif for IsNotPromotable { fn in_call( cx: &ConstCx<'_, 'tcx>, callee: &Operand<'tcx>, - _args: &[Operand<'tcx>], + args: &[Operand<'tcx>], _return_ty: Ty<'tcx>, ) -> bool { if cx.mode == Mode::Fn { @@ -520,10 +520,7 @@ impl Qualif for IsNotPromotable { } } - // FIXME(eddyb) do we need "not promotable" in anything - // other than `Mode::Fn` by any chance? - - false + Self::in_operand(cx, callee) || args.iter().any(|arg| Self::in_operand(cx, arg)) } } diff --git a/src/test/ui/consts/invalid_promotion.rs b/src/test/ui/consts/invalid_promotion.rs new file mode 100644 index 0000000000000..f98406e50e9ae --- /dev/null +++ b/src/test/ui/consts/invalid_promotion.rs @@ -0,0 +1,18 @@ +// compile-pass +// note this was only reproducible with lib crates +// compile-flags: --crate-type=lib + +pub struct Hz; + +impl Hz { + pub const fn num(&self) -> u32 { + 42 + } + pub const fn normalized(&self) -> Hz { + Hz + } + + pub const fn as_u32(&self) -> u32 { + self.normalized().num() // this used to promote the `self.normalized()` + } +} From 8c16507045a76ef616533ec29626f6ce6be40a6c Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 1 Mar 2019 17:10:29 +0100 Subject: [PATCH 2/2] Schedule the demolition of `IsNotPromotable` --- src/librustc_mir/transform/qualify_consts.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 73ac68c4ac3b4..f7b7754cea7bc 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -499,6 +499,8 @@ impl Qualif for IsNotConst { // Refers to temporaries which cannot be promoted as // promote_consts decided they weren't simple enough. +// FIXME(oli-obk,eddyb): Remove this flag entirely and +// solely process this information via `IsNotConst`. struct IsNotPromotable; impl Qualif for IsNotPromotable {