Skip to content

Enable to call Fn closures via FnMut and FnOnce - #48

Merged
coord-e merged 4 commits into
mainfrom
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 into
mainfrom
coord-e/fix-closure-param-match

Conversation

@coord-e

Copy link
Copy Markdown
Owner

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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
src/analyze/basic_block.rsUpdates function resolution for calls and runs the new RustCallVisitor before ReborrowVisitor; adds immut_borrow_place.
src/analyze/basic_block/visitor/rust_call.rsNew MIR mut visitor that adjusts closure receiver operands for Rust-call ABI Fn* trait calls.
src/analyze/basic_block/visitor/reborrow.rsMoves existing ReborrowVisitor into its own module (no functional change intended).
src/analyze/basic_block/visitor.rsRe-exports visitors from submodules.
src/analyze.rsAdds helper is_fn_trait_method for identifying Fn-trait methods.
tests/ui/pass/closure_param_weaken_1.rsNew passing test for FnOnce closure parameter weakening scenario.
tests/ui/pass/closure_param_weaken_2.rsNew passing test for FnMut closure parameter weakening scenario.
tests/ui/fail/closure_param_weaken_1.rsNew failing test variant expecting Unsat for incorrect assertion.
tests/ui/fail/closure_param_weaken_2.rsNew failing test variant expecting Unsat for incorrect assertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/analyze/basic_block.rs
Comment threadsrc/analyze/basic_block/visitor/rust_call.rs
Comment threadsrc/analyze/basic_block/visitor/rust_call.rs Outdated
Comment threadsrc/analyze/basic_block/visitor/rust_call.rs
@coord-e
coord-e merged commit f26313e into mainFeb 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 freeto 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

2 participants

@coord-e