Skip to content

Commit b2d401f

Browse files
committed
Add an example of placeholders.
1 parent 0e66b00 commit b2d401f

File tree

1 file changed

+34
-2
lines changed
  • src/doc/rustc/src/symbol-mangling

1 file changed

+34
-2
lines changed

src/doc/rustc/src/symbol-mangling/v0.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ A *const* is used to encode a const value used in generics and types.
600600
It has the following forms:
601601
602602
* A constant value encoded as a *[type]* which represents the type of the constant and *[const-data]* which is the constant value, followed by `_` to terminate the *const*.
603-
* The character `p` which represents a placeholder.
603+
* The character `p` which represents a [placeholder].
604604
* A *[backref]* to a previously encoded *const* of the same value.
605605
606606
The encoding of the *const-data* depends on the type:
@@ -644,6 +644,38 @@ The encoding of the *const-data* depends on the type:
644644
>
645645
> Recommended demangling: `mycrate::example::<305419896>`
646646
647+
### Placeholders
648+
[placeholder]: #placeholders
649+
650+
A *placeholder* may occur in circumstances where a type or const value is not relevant.
651+
652+
> Example:
653+
> ```rust
654+
> pub struct Example<T, const N: usize>([T; N]);
655+
>
656+
> impl<T, const N: usize> Example<T, N> {
657+
> pub fn foo() -> &'static () {
658+
> static EXAMPLE_STATIC: () = ();
659+
> &EXAMPLE_STATIC
660+
> }
661+
> }
662+
> ```
663+
>
664+
> In this example, the static `EXAMPLE_STATIC` would not be monomorphized by the type or const parameters `T` and `N`.
665+
> Those will use the placeholder for those generic arguments.
666+
> Its symbol is:
667+
>
668+
> ```text
669+
> _RNvNvMCsd9PVOYlP1UU_7mycrateINtB4_7ExamplepKpE3foo14EXAMPLE_STATIC
670+
> │ │││
671+
> │ ││└── const placeholder
672+
> │ │└─── const generic argument
673+
> │ └──── type placeholder
674+
> └────────────────── generic-args
675+
> ```
676+
>
677+
> Recommended demangling: `<mycrate::Example<_, _>>::foo::EXAMPLE_STATIC`
678+
647679
648680
## Type
649681
[type]: #type
@@ -697,7 +729,7 @@ The type encodings based on the initial tag character are:
697729
* `x` — `i64`
698730
* `y` — `u64`
699731
* `z` — `!`
700-
* `p` — placeholder `_`
732+
* `p` — [placeholder] `_`
701733
702734
* `A` — An [array][reference-array] `[T; N]`.
703735

0 commit comments

Comments
 (0)