From dde68dcfe536189ddde835299b59830d9f97b1f0 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 30 Jan 2018 16:38:14 +0100 Subject: [PATCH] Can only const prop temporaries Variables might error in branches that are not reachable due to the variable value. --- src/librustc_mir/transform/const_prop.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index fc2a149cfe9..09c72c4bf93 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -286,7 +286,12 @@ impl CanConstProp { found_assignment: IndexVec::from_elem(false, &mir.local_decls), }; for (local, val) in cpv.can_const_prop.iter_enumerated_mut() { - *val = mir.local_kind(local) != LocalKind::Arg; + // cannot use args at all + // cannot use locals because if x < y { y - x } else { x - y } would + // lint for x != y + // FIXME(oli-obk): lint variables until they are used in a condition + // FIXME(oli-obk): lint if return value is constant + *val = mir.local_kind(local) == LocalKind::Temp; } cpv.visit_mir(mir); cpv.can_const_prop