Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't promote function calls to nonpromotable things #58784

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -507,7 +509,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 {
Expand All @@ -520,10 +522,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))
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/consts/invalid_promotion.rs
Original file line number Diff line number Diff line change
@@ -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()`
}
}