Enable to call Fn closures via FnMut and FnOnce - #48
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the MIR call-typing logic to better handle Rust-call ABI closure invocations through Fn/FnMut/FnOnce, addressing issue #46 by resolving to the “real” closure DefId and adjusting the effective receiver type at call sites.
Changes:
- Adjust
Analyzer::type_callto resolveFn*trait calls to the closure DefId directly (bypassing some shims) and normalizeParamEnvfor instance resolution. - Introduce
RustCallVisitorto rewrite closure call receiver operands (e.g., insert implicit immutable borrows/reborrows) to match the resolved closure function signature. - Add new UI pass/fail tests covering closure parameter weakening for
FnOnceandFnMutcall patterns.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/analyze/basic_block.rs | Updates function resolution for calls and runs the new RustCallVisitor before ReborrowVisitor; adds immut_borrow_place. |
src/analyze/basic_block/visitor/rust_call.rs | New MIR mut visitor that adjusts closure receiver operands for Rust-call ABI Fn* trait calls. |
src/analyze/basic_block/visitor/reborrow.rs | Moves existing ReborrowVisitor into its own module (no functional change intended). |
src/analyze/basic_block/visitor.rs | Re-exports visitors from submodules. |
src/analyze.rs | Adds helper is_fn_trait_method for identifying Fn-trait methods. |
tests/ui/pass/closure_param_weaken_1.rs | New passing test for FnOnce closure parameter weakening scenario. |
tests/ui/pass/closure_param_weaken_2.rs | New passing test for FnMut closure parameter weakening scenario. |
tests/ui/fail/closure_param_weaken_1.rs | New failing test variant expecting Unsat for incorrect assertion. |
tests/ui/fail/closure_param_weaken_2.rs | New failing test variant expecting Unsat for incorrect assertion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
partially fix#46