Try to fold a collection of constant expressions into a single ConstantData::Tuple. Returns None if any element cannot be folded.
(
&mut self,
elts: &[ast::Expr],
)
| 9447 | /// Try to fold a collection of constant expressions into a single ConstantData::Tuple. |
| 9448 | /// Returns None if any element cannot be folded. |
| 9449 | fn try_fold_constant_collection( |
| 9450 | &mut self, |
| 9451 | elts: &[ast::Expr], |
| 9452 | ) -> CompileResult<Option<ConstantData>> { |
| 9453 | let mut constants = Vec::with_capacity(elts.len()); |
| 9454 | for elt in elts { |
| 9455 | let Some(constant) = self.try_fold_constant_expr(elt)? else { |
| 9456 | return Ok(None); |
| 9457 | }; |
| 9458 | constants.push(constant); |
| 9459 | } |
| 9460 | Ok(Some(ConstantData::Tuple { |
| 9461 | elements: constants, |
| 9462 | })) |
| 9463 | } |
| 9464 | |
| 9465 | fn try_fold_constant_expr(&mut self, expr: &ast::Expr) -> CompileResult<Option<ConstantData>> { |
| 9466 | Ok(Some(match expr { |
no test coverage detected