Can only const prop temporaries

Variables might error in branches that are not reachable due to the variable value.
This commit is contained in:
Oliver Schneider 2018-01-30 16:38:14 +01:00
parent 05a03d7537
commit dde68dcfe5
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9

View file

@ -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