Skip to content

Commit e67050e

Browse files
committed
Don't promote function calls to nonpromotable things
1 parent ea43c3c commit e67050e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/librustc_mir/transform/qualify_consts.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl Qualif for IsNotPromotable {
507507
fn in_call(
508508
cx: &ConstCx<'_, 'tcx>,
509509
callee: &Operand<'tcx>,
510-
_args: &[Operand<'tcx>],
510+
args: &[Operand<'tcx>],
511511
_return_ty: Ty<'tcx>,
512512
) -> bool {
513513
if cx.mode == Mode::Fn {
@@ -520,10 +520,7 @@ impl Qualif for IsNotPromotable {
520520
}
521521
}
522522

523-
// FIXME(eddyb) do we need "not promotable" in anything
524-
// other than `Mode::Fn` by any chance?
525-
526-
false
523+
Self::in_operand(cx, callee) || args.iter().any(|arg| Self::in_operand(cx, arg))
527524
}
528525
}
529526

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-pass
2+
// note this was only reproducible with lib crates
3+
// compile-flags: --crate-type=lib
4+
5+
pub struct Hz;
6+
7+
impl Hz {
8+
pub const fn num(&self) -> u32 {
9+
42
10+
}
11+
pub const fn normalized(&self) -> Hz {
12+
Hz
13+
}
14+
15+
pub const fn as_u32(&self) -> u32 {
16+
self.normalized().num() // this used to promote the `self.normalized()`
17+
}
18+
}

0 commit comments

Comments
 (0)