MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_fold_constant_collection

Method try_fold_constant_collection

crates/codegen/src/compile.rs:9449–9463  ·  view source on GitHub ↗

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],
    )

Source from the content-addressed store, hash-verified

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 {

Callers 1

starunpack_helperMethod · 0.80

Calls 4

SomeClass · 0.50
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected