about summary refs log tree commit diff
path: root/compiler/rustc_index_macros/src/lib.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-10-24 00:16:14 +0000
committerMichael Goulet <michael@errs.io>2023-11-18 00:20:00 +0000
commit4506681e2f53e17df0d74cd230948dc40f7d0e8d (patch)
tree30f5887e9c39e750fd89e72b7007075a11c81be3 /compiler/rustc_index_macros/src/lib.rs
parent2831701757eb7b3105eda26a306c2f3a97e2664b (diff)
downloadrust-4506681e2f53e17df0d74cd230948dc40f7d0e8d.tar.gz
rust-4506681e2f53e17df0d74cd230948dc40f7d0e8d.zip
Begin nightly-ifying rustc_type_ir
Diffstat (limited to 'compiler/rustc_index_macros/src/lib.rs')
-rw-r--r--compiler/rustc_index_macros/src/lib.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_index_macros/src/lib.rs b/compiler/rustc_index_macros/src/lib.rs
new file mode 100644
index 00000000000..f6a6175374a
--- /dev/null
+++ b/compiler/rustc_index_macros/src/lib.rs
@@ -0,0 +1,30 @@
+#![cfg_attr(feature = "nightly", feature(allow_internal_unstable))]
+#![cfg_attr(feature = "nightly", allow(internal_features))]
+
+use proc_macro::TokenStream;
+
+mod newtype;
+
+/// Creates a struct type `S` that can be used as an index with
+/// `IndexVec` and so on.
+///
+/// There are two ways of interacting with these indices:
+///
+/// - The `From` impls are the preferred way. So you can do
+///   `S::from(v)` with a `usize` or `u32`. And you can convert back
+///   to an integer with `u32::from(s)`.
+///
+/// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
+///   to create/return a value.
+///
+/// Internally, the index uses a u32, so the index must not exceed
+/// `u32::MAX`. You can also customize things like the `Debug` impl,
+/// what traits are derived, and so forth via the macro.
+#[proc_macro]
+#[cfg_attr(
+    feature = "nightly",
+    allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
+)]
+pub fn newtype_index(input: TokenStream) -> TokenStream {
+    newtype::newtype(input)
+}