Skip to content

Commit 73b0c9f

Browse files
authored
Remove duplicated code in compile.rs (RustPython#8141)
1 parent 94ecb56 commit 73b0c9f

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustpython_wtf8::Wtf8Buf;
3939

4040
/// Extension trait for `ast::Expr` to add constant checking methods
4141
trait ExprExt {
42-
/// Check if an expression is a constant literal
42+
/// Returns true if the expression is a constant literal with no side effects.
4343
fn is_constant(&self) -> bool;
4444

4545
/// Check if a slice expression has all constant elements
@@ -2782,7 +2782,7 @@ impl Compiler {
27822782
// In interactive mode, always compile (to print the result).
27832783
let dominated_by_interactive =
27842784
self.interactive && !self.ctx.in_func() && !self.ctx.in_class;
2785-
if !dominated_by_interactive && Self::is_const_expression(value) {
2785+
if !dominated_by_interactive && value.is_constant() {
27862786
emit!(self, Instruction::Nop);
27872787
} else {
27882788
self.compile_expression(value)?;
@@ -7881,19 +7881,6 @@ impl Compiler {
78817881
send_block
78827882
}
78837883

7884-
/// Returns true if the expression is a constant with no side effects.
7885-
fn is_const_expression(expr: &ast::Expr) -> bool {
7886-
matches!(
7887-
expr,
7888-
ast::Expr::StringLiteral(_)
7889-
| ast::Expr::BytesLiteral(_)
7890-
| ast::Expr::NumberLiteral(_)
7891-
| ast::Expr::BooleanLiteral(_)
7892-
| ast::Expr::NoneLiteral(_)
7893-
| ast::Expr::EllipsisLiteral(_)
7894-
)
7895-
}
7896-
78977884
fn compile_expression(&mut self, expression: &ast::Expr) -> CompileResult<()> {
78987885
trace!("Compiling {expression:?}");
78997886
let range = expression.range();

0 commit comments

Comments
 (0)