const propagation: simplyfy struct access

so that `{ min: 10px, max: 20px }.min`  get optimized
This commit is contained in:
Olivier Goffart 2023-03-22 16:00:26 +01:00 committed by Olivier Goffart
parent 8f52015fe5
commit b180661ff6

View file

@ -99,6 +99,15 @@ fn simplify_expression(expr: &mut Expression) -> bool {
}
can_inline
}
Expression::StructFieldAccess { base, name } => {
if let Expression::Struct { values, .. } = &mut **base {
if let Some(e) = values.remove(name) {
*expr = e;
return simplify_expression(expr);
}
};
simplify_expression(base)
}
Expression::Cast { from, to } => {
let can_inline = simplify_expression(from);
let new = if from.ty() == *to {