clippy enum_glob_use#8121
Conversation
📝 WalkthroughWalkthroughAdds Changesenum_glob_use Clippy lint enforcement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/codegen/src/compile.rs (1)
7009-7046: ⚡ Quick winExtract the operator mapping to eliminate duplication. Per the coding guidelines ("When branches differ only in a value but share common logic, extract the differing value first"), the six match arms are identical except for the
ComparisonOperatorvariant and the input pattern. Extract the mapping into a single inner match, then emit once.♻️ Proposed refactor to reduce duplication
fn compile_addcompare(&mut self, op: &ast::CmpOp) { - match op { - ast::CmpOp::Eq => emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::Equal - } - ), - ast::CmpOp::NotEq => emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::NotEqual - } - ), - ast::CmpOp::Lt => emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::Less - } - ), - ast::CmpOp::LtE => emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::LessOrEqual - } - ), - ast::CmpOp::Gt => emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::Greater - } - ), - ast::CmpOp::GtE => { - emit!( - self, - Instruction::CompareOp { - opname: ComparisonOperator::GreaterOrEqual - } - ) - } - } + let opname = match op { + ast::CmpOp::Eq => ComparisonOperator::Equal, + ast::CmpOp::NotEq => ComparisonOperator::NotEqual, + ast::CmpOp::Lt => ComparisonOperator::Less, + ast::CmpOp::LtE => ComparisonOperator::LessOrEqual, + ast::CmpOp::Gt => ComparisonOperator::Greater, + ast::CmpOp::GtE => ComparisonOperator::GreaterOrEqual, + }; + emit!( + self, + Instruction::CompareOp { opname } + ); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/codegen/src/compile.rs` around lines 7009 - 7046, The match arms for ast::CmpOp variants (Eq, NotEq, Lt, LtE, Gt, GtE) contain duplicated logic with only the ComparisonOperator variant differing. Extract the operator mapping into an inner match statement that converts the ast::CmpOp to its corresponding ComparisonOperator, then emit the CompareOp instruction once using the result of that mapping, eliminating the six repetitive emit! calls.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/codegen/src/compile.rs`:
- Around line 7009-7046: The match arms for ast::CmpOp variants (Eq, NotEq, Lt,
LtE, Gt, GtE) contain duplicated logic with only the ComparisonOperator variant
differing. Extract the operator mapping into an inner match statement that
converts the ast::CmpOp to its corresponding ComparisonOperator, then emit the
CompareOp instruction once using the result of that mapping, eliminating the six
repetitive emit! calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 4094b456-50fe-48e6-ada7-a78eada8aa48
📒 Files selected for processing (19)
Cargo.tomlcrates/codegen/src/compile.rscrates/codegen/src/symboltable.rscrates/common/src/cformat.rscrates/common/src/str.rscrates/compiler-core/src/bytecode.rscrates/compiler-core/src/marshal.rscrates/derive-impl/src/pyclass.rscrates/derive-impl/src/util.rscrates/stdlib/src/array.rscrates/stdlib/src/binascii.rscrates/stdlib/src/unicodedata.rscrates/vm/src/buffer.rscrates/vm/src/builtins/dict.rscrates/vm/src/builtins/float.rscrates/vm/src/codecs.rscrates/vm/src/protocol/callable.rscrates/vm/src/stdlib/_imp.rscrates/vm/src/stdlib/marshal.rs
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/vm/src/stdlib/winsound.rs (1)
71-83: ⚡ Quick winConsider simplifying the generic signature to
impl Trait.The generic type parameter
Fis not necessary here. The function could use the simpler and more idiomaticimpl FnOnce(PlaySoundError) -> PyBaseExceptionRef + '_return type, which would work equally well at all call sites (lines 91, 99, 154) while reducing complexity.♻️ Proposed simplification
-fn map_play_err<F>(vm: &VirtualMachine) -> F -where - F: FnOnce(PlaySoundError) -> PyBaseExceptionRef + '_, -{ +fn map_play_err(vm: &VirtualMachine) -> impl FnOnce(PlaySoundError) -> PyBaseExceptionRef + '_ { |err| match err { PlaySoundError::MemoryAsyncRejected => { vm.new_runtime_error("Cannot play asynchronously from memory") } PlaySoundError::MemoryFlagWithoutBuffer | PlaySoundError::CallFailed => { vm.new_runtime_error("Failed to play sound") } } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/vm/src/stdlib/winsound.rs` around lines 71 - 83, Simplify the generic signature of the map_play_err function by removing the explicit generic type parameter F and using impl Trait syntax instead. Change the return type to use impl FnOnce(PlaySoundError) -> PyBaseExceptionRef + '_ directly, which is more idiomatic and achieves the same result at all call sites while reducing unnecessary complexity.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/vm/src/stdlib/winsound.rs`:
- Around line 71-83: Simplify the generic signature of the map_play_err function
by removing the explicit generic type parameter F and using impl Trait syntax
instead. Change the return type to use impl FnOnce(PlaySoundError) ->
PyBaseExceptionRef + '_ directly, which is more idiomatic and achieves the same
result at all call sites while reducing unnecessary complexity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: bcf065b2-8e98-448f-acb5-86c4c4104562
📒 Files selected for processing (1)
crates/vm/src/stdlib/winsound.rs
Summary
Summary by CodeRabbit
Release Notes
enum_glob_use) to the workspace lint configuration to encourage clearer enum usage.