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
Sema: a struct field of type extern "C" fn(&T) -> R is refused as "ephemeral references cannot be stored in structs" #1833
Spec: §5 (ephemerality), §16.6 (function pointers). A struct field whose type is a C function pointer taking a reference is refused as if the field held a reference:
type Holder { f: extern "C" fn(&i32) -> i32 }
fn read(x: &i32) -> i32: *x
fn main:
let h = Holder { f: read }
let v = 5
print(f"{(h.f)(&v)}")
error: ephemeral references cannot be stored in structs
--> fnfield.w:1:18
1 | type Holder { f: extern "C" fn(&i32) -> i32 }
Expected: accepted, prints 5. An extern "C" fn(&T) -> R is a code pointer (§16.6: pointer-sized, Copy, storable in repr(C) structs); it takes a view per call and holds none, so it is not ephemeral. The struct-field check looks into the callable's parameter types.
Found by the D76 wrapper (#1779): the box a registration hands C carries the program's extern "C" fn(Context, &[Value], &U) callbacks; the rendering stores them as *mut c_void and transmutes back at the call instead (FacadeRender.w facade_render_wrapper) — remove that when this lands.
Reproduced with the installed compiler (v0.15.2.1-g99939352f) and a stage1 of 355c20b.
Activity
Sema: a fn-pointer type whose parameter is a reference is not ephemer…