Skip to content

Enable to call Fn closures via FnMut and FnOnce#48

Merged
coord-e merged 4 commits intomainfrom
coord-e/fix-closure-param-match
Feb 14, 2026
Merged

Enable to call Fn closures via FnMut and FnOnce#48
coord-e merged 4 commits intomainfrom
coord-e/fix-closure-param-match

Conversation

@coord-e
Copy link
Owner

@coord-e coord-e commented Feb 11, 2026

partially fix #46

  1. Instance::resolve doesn't always work for FnOnce::call_once, so use the first field of TyKind::Closure to always get the real closure DefId.
  2. Introduce RustCallVisitor to adjust the self type for closure calls, which weakens the self type according to the real closure signature.
  3. The case where FnMut closures are called via FnOnce requires more work and is implemented separately.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_call to resolve Fn* trait calls to the closure DefId directly (bypassing some shims) and normalize ParamEnv for instance resolution.
  • Introduce RustCallVisitor to 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 FnOnce and FnMut call 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.

@coord-e coord-e merged commit f26313e into main Feb 14, 2026
6 checks passed
@coord-e coord-e deleted the coord-e/fix-closure-param-match branch February 14, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weaken the closure parameters in calls using rust-call

1 participant