{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreigx2wqyxknwoiww5q44srcq5bmlg4xlpo45qpdtwsy3tnqsh2glp4",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mmkgi32jrpx2"
},
"path": "/t/pre-rfc-make-some-feature-detected-function-to-fn-pointer-casts-safe-through-zst-token-types/24353#post_2",
"publishedAt": "2026-05-23T19:31:19.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "A possible alternative: give the ZST tokens themselves a method that casts from function item to function pointer. I suspect this alternative doesn't help improve the number of special cases compared to the original proposal (because you need some way to be generic over function item types that require a specific set of target features to be used safely, which is the sort of thing that is hard to represent using just traits), but it would be less magical than \"this value has to be in scope\" and thus might be easier to understand upon seeing it in code.\n\nThe _least_ magical version would be \"functions that require target features must be given the ZST values that represent those target features as arguments\", which would be simple both in terms of using it and in understanding how it works, but unfortunately I don't think it would be backwards-compatible (and it also wouldn't help with the problem of wanting to store pointers to functions with different target feature requirements in a variable of a single concrete type, which should in theory be sound if all the features in question are actually available at runtime and the calling convention doesn't change as a consequence).",
"title": "[Pre-RFC] Make some feature-detected function-to-fn-pointer casts safe through ZST token types"
}