# Structural types again -- desugar to named struct in std

**URL:** <https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550>\
**Category:** language design\
**Created:** [March 21, 2023, 9:13am UTC](https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550 "2023-03-21T09:13:54Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![programmerjake](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/programmerjake/32/5893_2.png) [@programmerjake](https://internals.rust-lang.org/u/programmerjake)\
**Post date:** [March 24, 2023, 9:06pm UTC](https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550/21 "2023-03-24T21:06:01Z")

</div>

ok, so def-site hygiene can be accounted for by adding an extra field to `NAMES`:

```rust
// in std::somewhere
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct FieldName {
    pub name: &'static str,
    pub hygiene: &'static str,
}
pub struct AnonymousStruct<Fields: std::marker::Tuple, const NAMES: &'static [FieldName]>(pub Fields);

```

I'm assuming the compiler can provide a unique string for each hygiene, probably a combination of crate name, module path, path to identifier in module, and some optional disambiguator for anonymous scopes. globally nameable hygienes would just be the empty string.

---

<div class="post-metadata">

**Author:** ![digama0](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/digama0/32/6384_2.png) [@digama0](https://internals.rust-lang.org/u/digama0)\
**Post date:** [March 24, 2023, 9:57pm UTC](https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550/22 "2023-03-24T21:57:52Z")

</div>

That's roughly the structure I was intending for `Atom`, but not `pub` because I don't think there should be a public API for creating hygienic names other than copying ones handed to user code by `AnonymousStruct` instances created by the compiler on parsing a `{ a: u32 }` type. It seems like it would be a huge stability issue if you could just stick hygiene strings in there with the (current) compiler mangling scheme and being able to forge identifiers created in random macros.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [June 22, 2023, 9:58pm UTC](https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550/23 "2023-06-22T21:58:42Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/structural-types-again-desugar-to-named-struct-in-std/18550.md?page=1)
