Unnamed repository; edit this file 'description' to name the repository.
fix: Assertion failure on closure with unbound function
Previously that we asserted that callee inference always succeeded when FnOnce is defined. This isn't true when we have a closure that references an unbound function. rustc itself had a similar issue in rust-lang/rust#157951. Remove the failing assertion and add a unit test. AI disclosure: Bisected by Opus 4.8, initial implementation by GPT 5.5.
Wilfred Hughes 2 weeks ago
parent 9cc7dcf · commit 1c24114
-rw-r--r--crates/hir-ty/src/infer/callee.rs8
-rw-r--r--crates/hir-ty/src/tests/regression.rs12
2 files changed, 13 insertions, 7 deletions
diff --git a/crates/hir-ty/src/infer/callee.rs b/crates/hir-ty/src/infer/callee.rs
index a661731e60..e5304582ca 100644
--- a/crates/hir-ty/src/infer/callee.rs
+++ b/crates/hir-ty/src/infer/callee.rs
@@ -585,13 +585,7 @@ impl<'a, 'db> DeferredCallResolution<'db> {
method_callee.args,
);
}
- None => {
- assert!(
- ctx.lang_items.FnOnce.is_none(),
- "Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{:?}`",
- self.closure_ty
- )
- }
+ None => {}
}
}
}
diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs
index c5bf521d35..2ef8999817 100644
--- a/crates/hir-ty/src/tests/regression.rs
+++ b/crates/hir-ty/src/tests/regression.rs
@@ -2935,3 +2935,15 @@ impl Foo for Bar {
"#,
);
}
+
+#[test]
+fn regression_unresolved_deferred_closure_call_resolution() {
+ check_no_mismatches(
+ r#"
+//- minicore: fn
+fn caller() {
+ let _: &[u8] = &(|| encode_fn())();
+}
+"#,
+ );
+}