You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid MIR: closure literal as a facade callback method's userdata is passed by value (missing borrow) #1904
Spec: §16.2b.9 (callback userdata), §12.4 (closures). Post-Sema invalid MIR is a compiler bug (D65).
Repro (place in test/compile_errors/ so the header path resolves):
use c_import("../behavior/c_facade_callbacks.h")
c facade dbc:
resource Database wraps *mut db
from db_new
drop db_close
fn db_exec
callback param 1 userdata param 2
fn invoke(f: &fn(c_int) -> c_int, n: c_int) -> c_int: f(n)
fn main:
let l = log_new()
let d = Database.new(l, 1).unwrap()
d.exec(invoke, n => n + 1, 1)
log_free(l)
Expected: the check passes (a captureless closure is a valid &U userdata), as it does for a free facade callback bridge (each(invoke, value => value)) and for let f = n => n + 1; d.exec(invoke, f, 1).
Actual (installed v0.15.3.0-g173d8aa4d, and impl-d75 stage1):
error: invalid MIR before codegen: call argument 2 is a value where the callee parameter is a reference to it (a missing borrow)
--> ...:20:32
20 | d.exec(invoke, n => n + 1, 1)
So a closure literal given directly as a receiver callback method's &U userdata is not auto-borrowed in MIR. Workaround: bind the closure first. Found while fixing the call-once regression on impl-d75 (stack #1898).
Fixed on main by 792351b (stack #2007, battery green on 0f13a62). A closure literal to a &U parameter of a generic method is auto-borrowed like lower_call_arg does.
Activity
A closure literal passed to a `&U` parameter of a generic method is a…
Sema/MIR: CK_FN loud on a missing fn (#1859); atomics default SeqCst (#…
ehartford commentedon Oct 3, 2026
Fixed on main by 792351b (stack #2007, battery green on 0f13a62). A closure literal to a &U parameter of a generic method is auto-borrowed like lower_call_arg does.