{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreicswryy5ju3qrurwtdlfurgq67agsz4q4qplxxl2pxvfudktk4qay",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mmm45ly5v672"
  },
  "path": "/t/pre-rfc-make-some-feature-detected-function-to-fn-pointer-casts-safe-through-zst-token-types/24353#post_4",
  "publishedAt": "2026-05-24T12:16:08.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "ais523:\n\n> A possible alternative: give the ZST tokens themselves a method that casts from function item to function pointer.\n\nI would strongly prefer that, or some other variant that explicitly requires the token to be named. Having the mere presence of an unmentioned local variable in scope unlock further operations seems way too implicit to me.\n\nAlso note that we already have something kind of similar:\n\n\n    #[target_feature(enable = \"avx2\")]\n    fn fun_with_avx2() {}\n\n    #[target_feature(enable = \"avx2\")]\n    fn make_fn_ptr() -> fn() {\n        fun_with_avx2\n    }\n\n\nIf the current function has a target feature enabled, it can coerce other function items with that target feature to safe function pointers.\n\nIs there a way to use this to achieve what you are looking for?",
  "title": "[Pre-RFC] Make some feature-detected function-to-fn-pointer casts safe through ZST token types"
}