Skip to main content

closed_trait_macros/
lib.rs

1//! Attribute macros for the [`closed-trait`] crate. Use them through that crate,
2//! which re-exports both and provides the items the generated code refers to.
3//!
4//! [`closed-trait`]: https://docs.rs/closed-trait
5mod enumerate;
6mod sealed;
7mod util;
8
9use proc_macro::TokenStream;
10
11/// Seals a trait so that only the listed types can implement it, and every listed type must
12/// implement it.
13///
14/// ```compile_fail
15/// # use closed_trait::sealed;
16/// #[sealed(Circle, Square)] // error: Square does not implement Shape
17/// trait Shape {}
18///
19/// struct Circle;
20/// impl Shape for Circle {}
21///
22/// struct Square;
23///
24/// impl Shape for i32 {} // error: i32 is not permitted
25/// # fn main() {}
26/// ```
27///
28/// # Entries
29///
30/// Each entry is a type, and can further say how that type implements the trait.
31///
32/// ## Generic traits and types
33///
34/// One rule governs everything in this section:
35///
36/// **A bare name is a parameter only if the trait or a `for<..>` declares it** — otherwise it is
37/// whatever concrete type or const is in scope. The three cases below are the three ways an entry
38/// can answer that, and each takes lifetimes, types and const parameters alike.
39///
40/// ### Parameters the trait declares
41///
42/// A generic type implementing a generic trait at the same parameters names them as the trait
43/// declares them:
44///
45/// ```
46/// # use closed_trait::sealed;
47/// #[sealed(Boxed<'a, T>)] // `'a` and `T` are declared by the `Store` trait
48/// trait Store<'a, T> {}
49///
50/// struct Boxed<'t, X>(&'t X);
51///
52/// impl<'t, X> Store<'t, X> for Boxed<'t, X> {}
53/// # fn main() {}
54/// ```
55///
56/// Note which names the entry uses: `Boxed` declares `'t` and `X`, and the entry still writes `'a`
57/// and `T`. A bare name in an entry is read against the *trait*, never against the type it belongs
58/// to. A const parameter is named the same way, so `Row<N>` under `trait Width<const N: usize>`
59/// means every `Row`.
60///
61/// ### One instantiation
62///
63/// An implementor may implement a generic trait at one instantiation rather than generically. The
64/// `Entry: Trait<..>` syntax says which:
65///
66/// ```
67/// # use closed_trait::sealed;
68/// struct Plain;
69/// struct Boxed<T>(pub T);
70/// struct Keyed<T>(pub T);
71///
72/// #[sealed(
73///   Plain: Store<i32>,        // implements the trait at one instantiation
74///   Boxed<T>,                 // the identity mapping needs no annotation
75///   Keyed<T>: Store<Vec<T>>,  // generic, but not the identity mapping
76/// )]
77/// trait Store<T> {}
78///
79/// impl Store<i32> for Plain {}
80/// impl<T> Store<T> for Boxed<T> {}
81/// impl<T> Store<Vec<T>> for Keyed<T> {}
82/// # fn main() {}
83/// ```
84///
85/// ### Parameters the trait does not declare
86///
87/// A type may be generic over parameters the trait knows nothing about. The entry declares them
88/// itself, with `for<..>`:
89///
90/// ```
91/// # use closed_trait::sealed;
92/// struct Boxed<T>(T);
93///
94/// #[sealed(for<T> Boxed<T>)]
95/// trait Shape {}
96///
97/// impl<T> Shape for Boxed<T> {}
98/// # fn main() {}
99/// ```
100///
101/// Lifetimes work the same way, except that for them the binder is not optional. Left out, the
102/// same spelling would mean the trait's lifetime or every lifetime depending on what the trait
103/// happened to call its parameter — so renaming that parameter would quietly change what is
104/// sealed:
105///
106/// ```
107/// # use closed_trait::sealed;
108/// struct Str<'a>(&'a str);
109///
110/// #[sealed(for<'a> Str<'a>)]
111/// trait Shape {}
112///
113/// impl<'a> Shape for Str<'a> {}
114/// # fn main() {}
115/// ```
116///
117/// Lifetimes, types and const parameters can be declared together, lifetimes first — as in
118/// `for<'a, T: Clone, const N: usize>` — and each is written exactly as it would be on an `impl`,
119/// so a const parameter carries its type.
120///
121/// ## `as Name`
122///
123/// Names the entry. The seal itself does not care — it is [`enumerate`][macro@enumerate] that reads
124/// the name, giving each variant the type's last path segment unless one is written here. Two
125/// entries collide over that in two ways.
126///
127/// **Different types whose last segment matches.** Here the name settles which is which:
128///
129/// ```
130/// # use closed_trait::{enumerate, sealed};
131/// mod a { pub struct Foo; }
132/// mod b { pub struct Foo; }
133///
134/// #[enumerate]
135/// #[sealed(a::Foo as Left, b::Foo as Right)]
136/// trait Shape {}
137///
138/// impl Shape for a::Foo {}
139/// impl Shape for b::Foo {}
140/// fn main() {
141///   let _ = AnyShape::Left(a::Foo); // see enumerate
142/// }
143/// ```
144///
145/// **The same type listed twice**, which is how one type reaches the enum at more than one
146/// instantiation. There the name is not a nicety but required, since both entries would otherwise
147/// be the `Plain` variant:
148///
149/// ```
150/// # use closed_trait::{enumerate, sealed};
151/// # use closed_trait::Enumerable;
152/// struct Plain;
153/// struct Boxed<T>(pub T);
154///
155/// #[enumerate]
156/// #[sealed(Plain: Store<i32>, Plain as PlainF64: Store<f64>, Boxed<T>)]
157/// trait Store<T> {}
158///
159/// impl Store<i32> for Plain {}
160/// impl Store<f64> for Plain {}
161/// impl<T> Store<T> for Boxed<T> {}
162///
163/// fn main() {
164///     // the one type reaching two different enum instantiations
165///     assert!(matches!(Plain.into_enum(), AnyStore::<i32>::Plain(_)));
166///     assert!(matches!(Plain.into_enum(), AnyStore::<f64>::PlainF64(_)));
167/// }
168/// ```
169///
170/// The name settles the *variant* only. The two entries must also pin different arguments, and
171/// some entry — `Boxed<T>` here — has to *mention* `T`. The enum is generic over the parameters
172/// its variants use, not over the trait's: an enum declaring one no variant uses is `E0392`. With
173/// every entry pinned there would be no `AnyStore<T>` at all, both entries would land in the same
174/// `AnyStore`, and `enumerate` would refuse it.
175///
176/// ## All of it at once
177///
178/// A binder, the type, a name and the instantiation it implements, in that order:
179///
180/// ```
181/// # use closed_trait::sealed;
182/// struct Foo<'a, T>(&'a T);
183///
184/// #[sealed(
185///   for<'a, T> Foo<'a, T> as Bar: Dummy<i32>
186/// )]
187/// trait Dummy<X> {}
188///
189/// impl<'a, T> Dummy<i32> for Foo<'a, T> {}
190/// # fn main() {}
191/// ```
192///
193/// # The list is checked in both directions
194///
195/// Every entry is checked, which is why the trait's type and const parameters have to be supplied
196/// for it: either the type names them itself, as `Boxed<T>` does under `trait Store<T>`, or the
197/// entry annotates its instantiation, as in `Plain: Store<i32>`. An entry that does neither is
198/// refused, since nothing could then tell whether it implements the trait at all.
199///
200/// A lifetime is never asked for, and not merely because inference usually copes. A type cannot implement the same trait at two different lifetimes — two such
201/// impls overlap, and coherence rejects them — so there is never more than one candidate to
202/// disambiguate. `#[sealed(Plain)]` under `trait Foo<'a>` is therefore accepted *and* checked: an
203/// entry implementing no `Foo` at all is still caught.
204///
205/// # The seal is as precise as the list
206///
207/// The marker carries the same type and const parameters the trait does, so `Plain: Store<i32>`
208/// permits `Plain` to implement `Store<i32>` and nothing else — an unlisted `impl Store<f64> for
209/// Plain` is rejected:
210///
211/// ```compile_fail
212/// # use closed_trait::sealed;
213/// struct Plain;
214///
215/// #[sealed(Plain: Store<i32>)]
216/// trait Store<T> {}
217///
218/// impl Store<i32> for Plain {}
219/// impl Store<f64> for Plain {} // error: not permitted to implement `Store` here
220/// # fn main() {}
221/// ```
222///
223/// An entry naming the parameters instead, like `Boxed<T>`, permits every instantiation — which is
224/// what naming them says. Lifetimes are not on the marker, for the reason above: they could never
225/// tell two entries apart.
226///
227/// # What the seal is worth
228///
229/// The marker trait is private to the module the attribute is written in, and carries a supertrait
230/// private one level deeper. Naming the marker is therefore not enough to satisfy it — the only
231/// place both can be implemented is inside the generated module, which nothing but this macro
232/// writes. Code sitting directly beside the sealed trait cannot opt a type in, which a single level
233/// of privacy would have allowed.
234///
235/// The cost is that permitted types must be nameable from that module, so they have to live at
236/// module level. **A type declared inside a function body cannot be sealed**, because no module
237/// nested in a function can refer to it.
238#[proc_macro_attribute]
239pub fn sealed(args: TokenStream, item: TokenStream) -> TokenStream {
240    sealed::sealed(args, item)
241}
242
243/// Generates enums holding the types a trait is sealed to and macros rules to work with these
244/// enums.
245///
246/// Reads its type list from the `#[sealed(..)]` attribute below it, so it must be written **above**
247/// — attribute macros run top down, and `#[sealed]` consumes itself when it expands.
248///
249/// ```
250/// # use closed_trait::{enumerate, sealed};
251/// // on a concrete type `into_enum` needs the trait in scope; a generic
252/// // `S: Shape` gets it from the supertrait bound
253/// use closed_trait::Enumerable;
254///
255/// struct Square;
256/// struct Circle;
257///
258/// #[enumerate]
259/// #[sealed(Square, Circle)]
260/// trait Shape {}
261///
262/// impl Shape for Square {}
263/// impl Shape for Circle {}
264///
265/// fn  main() {
266///  let shape: AnyShape = Square.into_enum();
267///  match shape {
268///    AnyShape::Square(_) => {},
269///    AnyShape::Circle(_) => {},
270///  }
271/// }
272/// ```
273///
274/// # The three enums
275///
276/// All three are generated by default, each with one variant per entry named after the type's last
277/// path segment, and each taking the trait's visibility. A type not in upper camel case therefore
278/// gives a variant that is not either — `i32` yields an `i32` variant — so the enums carry
279/// `#[allow(non_camel_case_types)]`: the name came from a type, not from a choice the caller made.
280/// `as Name` is there for anyone who would rather write `I32`. Given the base `Shape` sealed
281/// trait:
282///
283/// | enum              | holds            | reached from                               |
284/// | ----------------- | ---------------- | ------------------------------------------ |
285/// | `AnyShape`        | `Square`         | `into_enum`, or `From`                     |
286/// | `AnyShapeRef<'a>` | `&'a Square`     | `as_enum_ref`, `From`, or `owned.as_ref()` |
287/// | `AnyShapeMut<'a>` | `&'a mut Square` | `as_enum_mut`, `From`, or `owned.as_mut()` |
288///
289/// Each brings a supertrait with it — `Enumerable<AnyShape>` and the higher-ranked `for<'a>
290/// EnumerableRef<'a, AnyShapeRef<'a>>` and its `Mut` counterpart — which is what makes the enums
291/// reachable from a generic `S: Shape` without naming them.
292///
293/// The borrowing pair is what `into_enum` cannot give you: taking `self`, it needs the value moved
294/// in, so a `&S` has no route to the owned enum at all. They are also cheaper to pass, being a
295/// pointer and a discriminant rather than as wide as the largest permitted type. The shared one
296/// derives `Clone` and `Copy`.
297///
298/// Conversions *between* the three — `as_ref` and `as_mut` on the owned enum, and `as_ref` on the
299/// unique one, which reborrows — come as inherent methods. `no_bridge` leaves them out.
300///
301/// # Options
302///
303/// Written bare, an option applies to all three enums. Written inside `owned(..)`, `ref(..)` or
304/// `mut(..)` it applies to that one, and a specific option beats a grouped one.
305///
306/// ## `name = ..`
307///
308/// Names the enums, which are `Any{Trait}`, `Any{Trait}Ref` and `Any{Trait}Mut` by default.
309///
310/// Grouped, it is a **base** that each kind extends, so `name = Shapes` gives `Shapes`, `ShapesRef`
311/// and `ShapesMut`. Specific, it is the name itself: `ref(name = ShapeView)` gives exactly
312/// `ShapeView`.
313///
314/// ```
315/// # use closed_trait::{enumerate, sealed};
316/// # struct Square;
317///
318/// #[enumerate(name = Shapes, ref(name = ShapeView))]
319/// #[sealed(Square)]
320/// trait Shape {}
321///
322/// impl Shape for Square {}
323///
324/// fn main() {
325///   let mut owned: Shapes        = Shapes::Square(Square);
326///   let mutable:   ShapesMut<'_> = owned.as_mut();
327///   let reference: ShapeView<'_> = mutable.as_ref();
328/// }
329/// ```
330///
331/// ## `no_bridge`
332///
333/// Prevents generating the conversion methods written *on* an enum. `owned(no_bridge)` drops
334/// `as_ref(&self)` and `as_mut(&mut self)`; `mut(no_bridge)` drops the reborrowing `as_ref(&self)`;
335/// a bare `no_bridge` drops all three. Nothing is written on the shared enum, so `ref(no_bridge)`
336/// is refused rather than silently doing nothing.
337///
338/// ## `attrs = ".."`
339///
340/// Attributes to put on a generated enum, verbatim — derives, `#[non_exhaustive]`, `#[repr(..)]`,
341/// anything. It is the one option that **must** be specific. What is valid differs between
342/// the three — the shared enum already derives `Copy`, the unique one cannot derive `Clone` at all
343/// — so one spelling spread across them would be a trap. A bare `attrs` is an error saying so.
344///
345/// ```
346/// # use closed_trait::{enumerate, sealed};
347/// # #[derive(Clone, Debug, PartialEq)] pub struct Square;
348///
349/// #[enumerate(owned(attrs = "#[derive(Clone, Debug, PartialEq)] #[non_exhaustive]"))]
350/// #[sealed(Square)]
351/// trait Shape {}
352///
353/// # impl Shape for Square {}
354/// # fn main() {}
355/// ```
356///
357/// Documentation is the exception: the enum's docs are generated and identical for every sealed
358/// trait, so a `///` or `#[doc = ".."]` here is an error.
359///
360/// ## `crate = ".."`
361///
362/// Where the generated code should look for `Enumerable`. Defaults to `::closed_trait`, which is
363/// right whenever `closed-trait` is a direct dependency under its own name.
364///
365/// It is wrong in two cases, and both fail with `cannot find `closed_trait` in the crate root` even
366/// though nothing in the caller's source names it:
367///
368/// - the dependency was renamed, as in `st = { package = "closed-trait" }`;
369/// - the macros are reached through a re-export, so the caller does not depend
370///   on `closed-trait` at all.
371///
372/// Point it at whatever crate re-exports `Enumerable`:
373///
374/// ```
375/// # use closed_trait::{enumerate, sealed};
376/// # pub struct Square;
377/// #[enumerate(crate = "::closed_trait")]
378/// #[sealed(Square)]
379/// trait Shape {}
380///
381/// # impl Shape for Square {}
382/// # fn main() {}
383/// ```
384///
385/// ## `match_any`
386///
387/// Generates `match_any_{trait}!`, a macro that expands to a `match` over every variant. A `match`
388/// on the enum already tells the variants apart; what this adds is one body that runs against the
389/// *concrete* type, which a closure cannot express because Rust has no generic closures.
390///
391/// ```
392/// # use closed_trait::{enumerate, sealed};
393///
394/// struct Square { side: i32 }
395/// struct Circle { radius: i32 }
396///
397/// #[enumerate(match_any)]
398/// #[sealed(Square, Circle)]
399/// trait Shape { fn area(&self) -> i32; }
400///
401/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
402/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
403///
404/// fn main() {
405///  let shape = AnyShape::from(Square { side: 3 });
406///  let area = match_any_shape!(shape, s => s.area());
407///  assert_eq!(9, area);
408/// }
409/// ```
410///
411/// The value may be given by `&`, by `&mut` or by value; match ergonomics make
412/// the binding follow it, so one macro covers all three. The binding has to be
413/// named by the caller.
414///
415/// It is a `match`, not a closure, and the difference is the point:
416///
417/// ```
418/// # use closed_trait::{enumerate, sealed};
419/// # pub struct Square { pub side: i32 }
420/// # pub struct Circle { pub radius: i32 }
421/// # #[enumerate(match_any)]
422/// # #[sealed(Square, Circle)]
423/// # pub trait Shape { fn area(&self) -> i32; }
424/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
425/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
426/// fn first_greater(shapes: &[AnyShape], value: i32) -> Option<i32> {
427///   for shape in shapes {
428///     // `return` leaves `first_big`, which a method taking the body could
429///     // never do
430///     match_any_shape!(shape, s => if s.area() > value { return Some(s.area()) });
431///   }
432///   None
433/// }
434///
435/// # fn main() {}
436/// ```
437///
438/// The body may also move anything it owns, since only one arm ever runs, and it can be `async`.
439/// To handle some variants differently, match first and let the last arm fall through:
440///
441/// ```
442/// # use closed_trait::{enumerate, sealed};
443/// # pub struct Square { pub side: i32 }
444/// # pub struct Circle { pub radius: i32 }
445/// # #[enumerate(match_any)]
446/// # #[sealed(Square, Circle)]
447/// # pub trait Shape { fn area(&self) -> i32; }
448/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
449/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
450/// # fn main() {
451/// # let shape = AnyShape::from(Square { side: 3 });
452/// let cost = match &shape {
453///     AnyShape::Square(_) => 0,
454///     other => match_any_shape!(other, s => s.area()),
455/// };
456/// # assert_eq!(cost, 0);
457/// # }
458/// ```
459///
460/// Two things follow from it being a macro. The enum and the trait must be in scope where it is
461/// called, because a `macro_rules!` body resolves paths at the call site. And the body is *copied*
462/// into every arm.
463///
464/// That copying is worth being deliberate about. It costs compile time in proportion to the number
465/// of variants, since the body is type-checked once per arm, and one mistake in it is reported once
466/// per arm too. Nesting one of these inside another squares the count.
467///
468/// The option takes an optional name, so `match_any(match_shape)` generates `match_shape!` instead.
469/// Whether the macro can leave the crate depends on the trait's visibility, and so does whether
470/// it can collide — see [Visibility](#visibility).
471///
472/// # Visibility
473///
474/// Everything generated takes the trait's own visibility: the three enums, the conversions between
475/// them, and the names the match macros are reached through. There is no option to change it — the
476/// enums appear in the trait's supertrait bounds, so anything narrower would put a private type in
477/// a public interface.
478///
479/// It decides one thing beyond reach, though. A `macro_rules!` cannot leave the crate that defines
480/// it without `#[macro_export]`, and that always plants it at the crate root. So a macro generated
481/// for a `pub` trait goes there under a hidden name and is aliased beside the enum, while one for
482/// any narrower trait simply stays where it was written:
483///
484/// | the trait is      | the macro is                               | usable from another crate | can collide |
485/// | ----------------- | ------------------------------------------ | ------------------------- | ----------- |
486/// | `pub`             | at the crate root, aliased beside the enum | yes                       | yes         |
487/// | anything narrower | where it was written                       | no                        | no          |
488///
489/// Colliding means two traits of the same name, in different modules, both asking for `match_any`:
490/// their hidden root names would be the same, and one of them needs `match_any(other_name)`.
491///
492/// # Generics
493///
494/// The enum takes the trait's parameters that at least one entry names, with their bounds. Those
495/// parameters have to be nameable in the supertrait bound that pins the enum, and only the
496/// trait's own are in scope there — so an entry must be generic *solely* over parameters the trait
497/// declares.
498///
499/// ```
500/// # use closed_trait::{enumerate, sealed};
501///
502/// struct Boxed<T>(T);
503/// struct Listed<T>(Vec<T>);
504///
505/// #[enumerate(match_any)]
506/// #[sealed(Boxed<T>, Listed<T>)]
507/// pub trait Store<T> {}
508///
509/// impl<T> Store<T> for Boxed<T> {}
510/// impl<T> Store<T> for Listed<T> {}
511///
512/// fn main() {
513///     let _: AnyStore<u8> = Listed(vec![]).into();
514/// }
515/// ```
516///
517/// The enum is generic over the parameters its *variants* use, not over the trait's. An enum
518/// declaring one that no variant uses is `E0392`, so a list whose every entry fixes its arguments
519/// produces a plain enum rather than a generic one.
520///
521/// ```
522/// # use closed_trait::{enumerate, sealed};
523///
524/// // every entry fixes its argument, so `AnyValue` is a plain enum
525/// #[enumerate]
526/// #[sealed(i32: Value<i32>, f64: Value<f64>)]
527/// trait Value<T> {}
528///
529/// impl Value<i32> for i32 {}
530/// impl Value<f64> for f64 {}
531///
532/// fn main() {
533///     let _: AnyValue = AnyValue::i32(6);
534/// }
535/// ```
536///
537/// An entry that names no parameter the enum is generic over cannot produce a single enum type, and
538/// is rejected with a message naming the fix — annotate it in `#[sealed(..)]` with the
539/// instantiation it implements.
540///
541/// ## Pinned entries and `match_any`
542///
543/// An entry *pins* its arguments when it names a concrete instantiation instead of the trait's
544/// parameters. Such an entry becomes a variant like any other, and the enum does not record which
545/// instantiation that variant belongs to.
546///
547/// On the way *in* that costs nothing: `into_enum` and `From` exist only at the instantiations the
548/// entry named, so nothing ever builds a variant that does not belong.
549///
550/// ```
551/// # use closed_trait::{enumerate, sealed};
552/// # use closed_trait::Enumerable;
553/// struct Plain;
554///
555/// #[enumerate]
556/// #[sealed(Plain: Store<i32>)]
557/// pub trait Store<T> {}
558///
559/// impl Store<i32> for Plain {}
560///
561/// fn main() {
562///     let _: AnyStore = Plain.into_enum();
563/// }
564/// ```
565///
566/// On the way *out* it costs the macro. Nothing stops the trait from being *named* at an
567/// instantiation no permitted type implements, and that is precisely where a body may ask the
568/// macro to expand. This is what `match_any` would become there, written out by hand:
569///
570/// ```compile_fail
571/// # use closed_trait::{enumerate, sealed};
572/// #[enumerate]
573/// #[sealed(i32: Value<i32>)]
574/// trait Value<T> {}
575///
576/// impl Value<i32> for i32 {}
577///
578/// fn describe(value: impl Value<String>) {
579///     // what `match_any_value!(value.into_enum(), v => takes(v))` becomes
580///     match value.into_enum() {
581///         // error: the trait bound `i32: Value<String>` is not satisfied
582///         AnyValue::i32(v) => takes(v),
583///     }
584/// }
585///
586/// fn takes<V: Value<String>>(_: V) {}
587/// # fn main() {}
588/// ```
589///
590/// The enum is fine, and so is the signature: `Value<String>` is a legal bound, merely one that
591/// nothing satisfies. Drop the `match` and it compiles on its own:
592///
593/// ```
594/// # use closed_trait::{enumerate, sealed};
595/// # #[enumerate]
596/// # #[sealed(i32: Value<i32>)]
597/// # trait Value<T> {}
598/// # impl Value<i32> for i32 {}
599/// fn describe(_: impl Value<String>) {}
600/// # fn main() {}
601/// ```
602///
603/// What cannot hold is the `match`. `AnyValue::i32` hands back an `i32`, which is a `Value<i32>`
604/// and nothing else, so a body written against `Value<String>` cannot use it. Rather than generate
605/// that and let it fail inside the caller's code, `#[enumerate]` refuses it where the list is
606/// written.
607///
608/// None of this is a trade you elect. Pinning is the only way to put such a type in the enum at
609/// all — an entry that neither names the trait's parameters nor fixes them is refused outright — so
610/// the macro is not something you give up in exchange, it is simply unavailable once a variant
611/// exists that is not valid at every instantiation. `match_any` needs every entry to name the
612/// trait's parameters rather than fix them, which is exactly the case where every variant is valid
613/// everywhere.
614///
615/// A permitted type that is not `Sized` cannot be held in a variant. That one is rustc's to
616/// report rather than this macro's, since sizedness is not visible in the tokens.
617#[proc_macro_attribute]
618pub fn enumerate(args: TokenStream, item: TokenStream) -> TokenStream {
619    enumerate::enumerate(args, item)
620}