)]}'
{
  "commit": "b62edc350cd01cedbb7e79cf0b2aba99d244c409",
  "tree": "11c15f88ee9e79d97f1c45afa0b7354725cd33e5",
  "parents": [
    "7ad6ec0536c3d9b73b708e2f2a2d671510229704",
    "28e3ea56a8de3d74f2150516e503ee62f1235065"
  ],
  "author": {
    "name": "Jonathan Brouwer",
    "email": "jonathantbrouwer@gmail.com",
    "time": "Sat Feb 28 12:52:52 2026 +0100"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Sat Feb 28 12:52:52 2026 +0100"
  },
  "message": "Rollup merge of #152730 - BennoLossin:field-projections-lang-item, r\u003doli-obk\n\nadd field representing types\n\n*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152730)*\n\n\u003e [!NOTE]\n\u003e This is a rewrite of #146307 by using a lang item instead of a custom `TyKind`. We still need a `hir::TyKind::FieldOf` variant, because resolving the field name cannot be done before HIR construction. The advantage of doing it this way is that we don\u0027t need to make any changes to types after HIR (including symbol mangling). At the very beginning of this feature implementation, I tried to do it using a lang item, but then quickly abandoned the approach, because at that time I was still intending to support nested fields.\n\nHere is a [range-diff](https://triagebot.infra.rust-lang.org/gh-range-diff/rust-lang/rust/605f49b27444a738ea4032cb77e3bdc4eb811bab..d15f5052095b3549111854a2555dd7026b0a729e/605f49b27444a738ea4032cb77e3bdc4eb811bab..f5f42d1e03495dbaa23671c46b15fccddeb3492f) between the two PRs\n\n---\n\n# Add Field Representing Types (FRTs)\n\nThis PR implements the first step of the field projection lang experiment (Tracking Issue: rust-lang/rust#145383). Field representing types (FRTs) are a new kind of type. They can be named through the use of the `field_of!` macro with the first argument being the type and the second the name of the field (or variant and field in the case of an enum). No nested fields are supported.\n\nFRTs natively implement the `Field` trait that\u0027s also added in this PR. It exposes information about the field such as the type of the field, the type of the base (i.e. the type that contains the field) and the offset within that base type. Only fields of non-packed structs are supported, fields of enums an unions have unique types for each field, but those do not implement the `Field` trait.\n\nThis PR was created in collaboration with @dingxiangfei2009, it wouldn\u0027t have been possible without him, so huge thanks for mentoring me!\n\nI updated my library solution for field projections to use the FRTs from `core` instead of creating my own using the hash of the name of the field. See the [Rust-for-Linux/field-projection `lang-experiment` branch](https://github.com/Rust-for-Linux/field-projection/tree/lang-experiment).\n\n## API added to `core::field`\n\n```rust\npub unsafe trait Field {\n    type Base;\n\n    type Type;\n\n    const OFFSET: usize;\n}\n\npub macro field_of($Container:ty, $($fields:expr)+ $(,)?);\n```\n\nAlong with a perma-unstable type that the compiler uses in the expansion of the macro:\n\n```rust\n#[unstable(feature \u003d \"field_representing_type_raw\", issue \u003d \"none\")]\npub struct FieldRepresentingType\u003cT: ?Sized, const VARIANT: u32, const FIELD: u32\u003e {\n    _phantom: PhantomData\u003cT\u003e,\n}\n```\n\n## Explanation of Field Representing Types (FRTs)\n\nFRTs are used for compile-time \u0026 trait-level reflection for fields of structs \u0026 tuples. Each struct \u0026 tuple has a unique compiler-generated type nameable through the `field_of!` macro. This type natively contains information about the field such as the outermost container, type of the field and its offset. Users may implement additional traits on these types in order to record custom information (for example a crate may define a [`PinnableField` trait](https://github.com/Rust-for-Linux/field-projection/blob/lang-experiment/src/marker.rs#L9-L23) that records whether the field is structurally pinned).\n\nThey are the foundation of field projections, a general operation that\u0027s generic over the fields of a struct. This genericism needs to be expressible in the trait system. FRTs make this possible, since an operation generic over fields can just be a function with a generic parameter `F: Field`.\n\n\u003e [!NOTE]\n\u003e The approach of field projections has changed considerably since this PR was opened. In the end we might not need FRTs, so this API is highly experimental.\n\nFRTs should act as though they were defined as `struct MyStruct_my_field\u003cStructGenerics\u003e;` next to the struct. So it should be local to the crate defining the struct so that one can implement any trait for the FRT from that crate. The `Field` traits should be implemented by the compiler \u0026 populated with correct information (`unsafe` code needs to be able to rely on them being correct).\n\n## TODOs\n\nThere are some `FIXME(FRTs)` scattered around the code:\n- Diagnostics for `field_of!` can be improved\n  - `tests/ui/field_representing_types/nonexistent.rs`\n  - `tests/ui/field_representing_types/non-struct.rs`\n  - `tests/ui/field_representing_types/offset.rs`\n  - `tests/ui/field_representing_types/not-field-if-packed.rs`\n  - `tests/ui/field_representing_types/invalid.rs`\n- Simple type alias already seem to work, but might need some extra work in `compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs`\n\nr? @oli-obk\n",
  "tree_diff": []
}
