Enable to call Fn closures via FnMut and FnOnce#48
Merged
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
partially fix #46