about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2023-05-13 19:02:30 -0700
committerEric Huss <eric@huss.org>2023-06-05 11:51:37 -0700
commitb2d401f6a5959a5047176fa8398e5f27a363c7d9 (patch)
treec4393f5bd040bbadc320b3882bf93b909c817f79
parent0e66b0024cbdbc30e97c226292461e1b608a424a (diff)
downloadrust-b2d401f6a5959a5047176fa8398e5f27a363c7d9.tar.gz
rust-b2d401f6a5959a5047176fa8398e5f27a363c7d9.zip
Add an example of placeholders.
-rw-r--r--src/doc/rustc/src/symbol-mangling/v0.md36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/doc/rustc/src/symbol-mangling/v0.md b/src/doc/rustc/src/symbol-mangling/v0.md
index 2bd17cd28fe..4f130191bfa 100644
--- a/src/doc/rustc/src/symbol-mangling/v0.md
+++ b/src/doc/rustc/src/symbol-mangling/v0.md
@@ -600,7 +600,7 @@ A *const* is used to encode a const value used in generics and types.
 It has the following forms:
 
 * 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*.
-* The character `p` which represents a placeholder.
+* The character `p` which represents a [placeholder].
 * A *[backref]* to a previously encoded *const* of the same value.
 
 The encoding of the *const-data* depends on the type:
@@ -644,6 +644,38 @@ The encoding of the *const-data* depends on the type:
 >
 > Recommended demangling: `mycrate::example::<305419896>`
 
+### Placeholders
+[placeholder]: #placeholders
+
+A *placeholder* may occur in circumstances where a type or const value is not relevant.
+
+> Example:
+> ```rust
+> pub struct Example<T, const N: usize>([T; N]);
+>
+> impl<T, const N: usize> Example<T, N> {
+>     pub fn foo() -> &'static () {
+>         static EXAMPLE_STATIC: () = ();
+>         &EXAMPLE_STATIC
+>     }
+> }
+> ```
+>
+> In this example, the static `EXAMPLE_STATIC` would not be monomorphized by the type or const parameters `T` and `N`.
+> Those will use the placeholder for those generic arguments.
+> Its symbol is:
+>
+> ```text
+> _RNvNvMCsd9PVOYlP1UU_7mycrateINtB4_7ExamplepKpE3foo14EXAMPLE_STATIC
+>                              │             │││
+>                              │             ││└── const placeholder
+>                              │             │└─── const generic argument
+>                              │             └──── type placeholder
+>                              └────────────────── generic-args
+> ```
+>
+> Recommended demangling: `<mycrate::Example<_, _>>::foo::EXAMPLE_STATIC`
+
 
 ## Type
 [type]: #type
@@ -697,7 +729,7 @@ The type encodings based on the initial tag character are:
   * `x` — `i64`
   * `y` — `u64`
   * `z` — `!`
-  * `p` — placeholder `_`
+  * `p` — [placeholder] `_`
 
 * `A` — An [array][reference-array] `[T; N]`.