Skip to content

Commit c2ddf5a

Browse files
committed
Auto merge of #58784 - oli-obk:accidental_promotion, r=eddyb
Don't promote function calls to nonpromotable things fixes #58767 and fixes #58634 r? @eddyb should we additionally check the function call return type? It might be a promotable function (or any `const fn` inside a `const fn`), but its return type might contain interior mutability.
2 parents 9d71ec1 + 8c16507 commit c2ddf5a

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/librustc_mir/transform/qualify_consts.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ impl Qualif for IsNotConst {
499499

500500
// Refers to temporaries which cannot be promoted as
501501
// promote_consts decided they weren't simple enough.
502+
// FIXME(oli-obk,eddyb): Remove this flag entirely and
503+
// solely process this information via `IsNotConst`.
502504
struct IsNotPromotable;
503505

504506
impl Qualif for IsNotPromotable {
@@ -507,7 +509,7 @@ impl Qualif for IsNotPromotable {
507509
fn in_call(
508510
cx: &ConstCx<'_, 'tcx>,
509511
callee: &Operand<'tcx>,
510-
_args: &[Operand<'tcx>],
512+
args: &[Operand<'tcx>],
511513
_return_ty: Ty<'tcx>,
512514
) -> bool {
513515
if cx.mode == Mode::Fn {
@@ -520,10 +522,7 @@ impl Qualif for IsNotPromotable {
520522
}
521523
}
522524

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

+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)