]> git.lizzy.rs Git - rust.git/commitdiff
Don't promote function calls to nonpromotable things
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 27 Feb 2019 16:41:25 +0000 (17:41 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 27 Feb 2019 16:41:25 +0000 (17:41 +0100)
src/librustc_mir/transform/qualify_consts.rs
src/test/ui/consts/invalid_promotion.rs [new file with mode: 0644]

index 285c674643f2e58cdcd2be4b45b1454a7b77f5bb..73ac68c4ac3b41fdc556e15a41613d93d5241beb 100644 (file)
@@ -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 @@ fn in_call(
             }
         }
 
-        // 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 (file)
index 0000000..f98406e
--- /dev/null
@@ -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()`
+    }
+}