Skip to content

Commit b46ac03

Browse files
committed
Can only const prop temporaries
Variables might error in branches that are not reachable due to the variable value.
1 parent e3e09cc commit b46ac03

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,12 @@ impl CanConstProp {
286286
found_assignment: IndexVec::from_elem(false, &mir.local_decls),
287287
};
288288
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
289-
*val = mir.local_kind(local) != LocalKind::Arg;
289+
// cannot use args at all
290+
// cannot use locals because if x < y { y - x } else { x - y } would
291+
// lint for x != y
292+
// FIXME(oli-obk): lint variables until they are used in a condition
293+
// FIXME(oli-obk): lint if return value is constant
294+
*val = mir.local_kind(local) == LocalKind::Temp;
290295
}
291296
cpv.visit_mir(mir);
292297
cpv.can_const_prop

0 commit comments

Comments
 (0)