Skip to content
Permalink
Browse files

Don't promote function calls to nonpromotable things

  • Loading branch information...
oli-obk committed Feb 27, 2019
1 parent ea43c3c commit e67050e8b6cbf48d041eb5f3993d620402073a7a
Showing with 20 additions and 5 deletions.
  1. +2 −5 src/librustc_mir/transform/qualify_consts.rs
  2. +18 −0 src/test/ui/consts/invalid_promotion.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))
}
}

@@ -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()`
}
}

0 comments on commit e67050e

Please sign in to comment.
You can’t perform that action at this time.