rust-lang / rust-lang/rust

Tracking Issue for `FnStatic` and `FnPtr::addr`/`from_ptr`/`as_ptr` and `Code`

Open
#148,768 21 comments 5 reactions 1 assignee View on GitHub

@carbotaniuman is already working on this.

Since Mar 26, 2026.

B-experimental C-tracking-issue I-lang-radar S-tracking-unimplemented T-lang T-libs T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

Feature gate: #![feature(fn_static)]

This is a tracking issue for FnStatic and FnPtr::addr/from_ptr/as_ptr and Code.

Public API
// core::ops

pub extern type Code;

// Implemented only for function pointers.
pub unsafe trait FnPtr {
    fn addr(self) -> usize;
    fn as_ptr(self) -> NonNull<Code>;
    unsafe fn from_ptr(NonNull<Code>) -> Self;
}

// Implemented for all types that coerce to function pointers.
pub unsafe trait FnStatic<Args>: Fn<Args> {
    type FnPtr: FnPtr;
    fn as_fn() -> Self::FnPtr;
    fn addr() -> usize;
    fn as_ptr() -> NonNull<Code>;
    extern "rust-call" fn call_static(args: Args) -> Self::Output;
}
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • ACP: rust-lang/libs-team#589
  • t-lang approval because FnStatic is a new builtin trait that interacts with the language, as well as discussing how to deal with new targets where code pointers are bigger than data pointers.
  • Implementation: #...
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Is it sufficient to just add type aliases whenever adding a target where code pointers are bigger than data pointers? It was proposed that NonNull<Code> is used for pointing to the code of a function, and that whenever a target where code pointers are larger than data pointers is added, then type aliases are added and APIs are changed to use those type aliases instead of directly using NonNull<Code> or usize when representing code addresses.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.