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
201/// implement the same trait at two different lifetimes: two such impls overlap, and coherence
202/// rejects them, so there is never more than one candidate to disambiguate. `#[sealed(Plain)]`
203/// under `trait Foo<'a>` is therefore accepted *and* checked: an entry implementing no `Foo` at all
204/// is still caught.
205///
206/// # The seal is as precise as the list
207///
208/// The marker carries the same type and const parameters the trait does, so `Plain: Store<i32>`
209/// permits `Plain` to implement `Store<i32>` and nothing else: an unlisted `impl Store<f64> for
210/// Plain` is rejected:
211///
212/// ```compile_fail
213/// # use closed_trait::sealed;
214/// struct Plain;
215///
216/// #[sealed(Plain: Store<i32>)]
217/// trait Store<T> {}
218///
219/// impl Store<i32> for Plain {}
220/// impl Store<f64> for Plain {} // error: not permitted to implement `Store` here
221/// # fn main() {}
222/// ```
223///
224/// An entry naming the parameters instead, like `Boxed<T>`, permits every instantiation, which is
225/// what naming them says. Lifetimes are not on the marker, for the reason above: they could never
226/// tell two entries apart.
227///
228/// # What the seal is worth
229///
230/// The marker trait is private to the module the attribute is written in, and carries a supertrait
231/// private one level deeper. Naming the marker is therefore not enough to satisfy it: the only
232/// place both can be implemented is inside the generated module, which nothing but this macro
233/// writes. Code sitting directly beside the sealed trait cannot opt a type in, which a single level
234/// of privacy would have allowed.
235///
236/// The cost is that permitted types must be nameable from that module, so they have to live at
237/// module level. **A type declared inside a function body cannot be sealed**, because no module
238/// nested in a function can refer to it.
239#[proc_macro_attribute]
240pub fn sealed(args: TokenStream, item: TokenStream) -> TokenStream {
241 sealed::sealed(args, item)
242}
243
244/// Generates enums holding the types a trait is sealed to and macros rules to work with these
245/// enums.
246///
247/// Reads its type list from the `#[sealed(..)]` attribute below it, so it must be written **above**;
248/// attribute macros run top down, and `#[sealed]` consumes itself when it expands.
249///
250/// ```
251/// # use closed_trait::{enumerate, sealed};
252/// // on a concrete type `into_enum` needs the trait in scope; a generic
253/// // `S: Shape` gets it from the supertrait bound
254/// use closed_trait::Enumerable;
255///
256/// struct Square;
257/// struct Circle;
258///
259/// #[enumerate]
260/// #[sealed(Square, Circle)]
261/// trait Shape {}
262///
263/// impl Shape for Square {}
264/// impl Shape for Circle {}
265///
266/// fn main() {
267/// let shape: AnyShape = Square.into_enum();
268/// match shape {
269/// AnyShape::Square(_) => {},
270/// AnyShape::Circle(_) => {},
271/// }
272/// }
273/// ```
274///
275/// # The three enums
276///
277/// All three are generated by default, each with one variant per entry named after the type's last
278/// path segment, and each taking the trait's visibility. A type not in upper camel case therefore
279/// gives a variant that is not either (`i32` yields an `i32` variant), so the enums carry
280/// `#[allow(non_camel_case_types)]`: the name came from a type, not from a choice the caller made.
281/// `as Name` is there for anyone who would rather write `I32`. Given the base `Shape` sealed
282/// trait:
283///
284/// | enum | holds | reached from |
285/// | ----------------- | ---------------- | ------------------------------------------ |
286/// | `AnyShape` | `Square` | `into_enum`, or `From` |
287/// | `AnyShapeRef<'a>` | `&'a Square` | `as_enum_ref`, `From`, or `owned.as_ref()` |
288/// | `AnyShapeMut<'a>` | `&'a mut Square` | `as_enum_mut`, `From`, or `owned.as_mut()` |
289///
290/// Each brings a supertrait with it: `Enumerable<AnyShape>` and the higher-ranked `for<'a>
291/// EnumerableRef<'a, AnyShapeRef<'a>>` and its `Mut` counterpart, which is what makes the enums
292/// reachable from a generic `S: Shape` without naming them.
293///
294/// The borrowing pair is what `into_enum` cannot give you: taking `self`, it needs the value moved
295/// in, so a `&S` has no route to the owned enum at all. They are also cheaper to pass, being a
296/// pointer and a discriminant rather than as wide as the largest permitted type. The shared one
297/// derives `Clone` and `Copy`.
298///
299/// Conversions *between* the three (`as_ref` and `as_mut` on the owned enum, and `as_ref` on the
300/// unique one, which reborrows) come as inherent methods. `no_bridge` leaves them out.
301///
302/// # Options
303///
304/// Written bare, an option applies to all three enums. Written inside `owned(..)`, `ref(..)` or
305/// `mut(..)` it applies to that one, and a specific option beats a grouped one.
306///
307/// ## `name = ..`
308///
309/// Names the enums, which are `Any{Trait}`, `Any{Trait}Ref` and `Any{Trait}Mut` by default.
310///
311/// Grouped, it is a **base** that each kind extends, so `name = Shapes` gives `Shapes`, `ShapesRef`
312/// and `ShapesMut`. Specific, it is the name itself: `ref(name = ShapeView)` gives exactly
313/// `ShapeView`.
314///
315/// ```
316/// # use closed_trait::{enumerate, sealed};
317/// # struct Square;
318///
319/// #[enumerate(name = Shapes, ref(name = ShapeView))]
320/// #[sealed(Square)]
321/// trait Shape {}
322///
323/// impl Shape for Square {}
324///
325/// fn main() {
326/// let mut owned: Shapes = Shapes::Square(Square);
327/// let mutable: ShapesMut<'_> = owned.as_mut();
328/// let reference: ShapeView<'_> = mutable.as_ref();
329/// }
330/// ```
331///
332/// ## `no_bridge`
333///
334/// Prevents generating the conversion methods written *on* an enum. `owned(no_bridge)` drops
335/// `as_ref(&self)` and `as_mut(&mut self)`; `mut(no_bridge)` drops the reborrowing `as_ref(&self)`;
336/// a bare `no_bridge` drops all three. Nothing is written on the shared enum, so `ref(no_bridge)`
337/// is refused rather than silently doing nothing.
338///
339/// ## `attrs = ".."`
340///
341/// Attributes to put on a generated enum, verbatim: derives, `#[non_exhaustive]`, `#[repr(..)]`,
342/// anything. It is the one option that **must** be specific. What is valid differs between
343/// the three: the shared enum already derives `Copy`, and the unique one cannot derive `Clone` at
344/// all, so one spelling spread across them would be a trap. A bare `attrs` is an error saying so.
345///
346/// ```
347/// # use closed_trait::{enumerate, sealed};
348/// # #[derive(Clone, Debug, PartialEq)] pub struct Square;
349///
350/// #[enumerate(owned(attrs = "#[derive(Clone, Debug, PartialEq)] #[non_exhaustive]"))]
351/// #[sealed(Square)]
352/// trait Shape {}
353///
354/// # impl Shape for Square {}
355/// # fn main() {}
356/// ```
357///
358/// Documentation is the exception: the enum's docs are generated and identical for every sealed
359/// trait, so a `///` or `#[doc = ".."]` here is an error.
360///
361/// ## `crate = ".."`
362///
363/// Where the generated code should look for `Enumerable`. Defaults to `::closed_trait`, which is
364/// right whenever `closed-trait` is a direct dependency under its own name.
365///
366/// It is wrong in two cases, and both fail with `cannot find `closed_trait` in the crate root` even
367/// though nothing in the caller's source names it:
368///
369/// - the dependency was renamed, as in `st = { package = "closed-trait" }`;
370/// - the macros are reached through a re-export, so the caller does not depend
371/// on `closed-trait` at all.
372///
373/// Point it at whatever crate re-exports `Enumerable`:
374///
375/// ```
376/// # use closed_trait::{enumerate, sealed};
377/// # pub struct Square;
378/// #[enumerate(crate = "::closed_trait")]
379/// #[sealed(Square)]
380/// trait Shape {}
381///
382/// # impl Shape for Square {}
383/// # fn main() {}
384/// ```
385///
386/// ## `match_any`
387///
388/// Generates `match_any_{trait}!`, a macro that expands to a `match` over every variant. A `match`
389/// on the enum already tells the variants apart; what this adds is one body that runs against the
390/// *concrete* type, which a closure cannot express because Rust has no generic closures.
391///
392/// ```
393/// # use closed_trait::{enumerate, sealed};
394///
395/// struct Square { side: i32 }
396/// struct Circle { radius: i32 }
397///
398/// #[enumerate(match_any)]
399/// #[sealed(Square, Circle)]
400/// trait Shape { fn area(&self) -> i32; }
401///
402/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
403/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
404///
405/// fn main() {
406/// let shape = AnyShape::from(Square { side: 3 });
407/// let area = match_any_shape!(shape, s => s.area());
408/// assert_eq!(9, area);
409/// }
410/// ```
411///
412/// The value may be given by `&`, by `&mut` or by value; match ergonomics make
413/// the binding follow it, so one macro covers all three. The binding has to be
414/// named by the caller.
415///
416/// It is a `match`, not a closure, and the difference is the point:
417///
418/// ```
419/// # use closed_trait::{enumerate, sealed};
420/// # pub struct Square { pub side: i32 }
421/// # pub struct Circle { pub radius: i32 }
422/// # #[enumerate(match_any)]
423/// # #[sealed(Square, Circle)]
424/// # pub trait Shape { fn area(&self) -> i32; }
425/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
426/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
427/// fn first_greater(shapes: &[AnyShape], value: i32) -> Option<i32> {
428/// for shape in shapes {
429/// // `return` leaves `first_big`, which a method taking the body could
430/// // never do
431/// match_any_shape!(shape, s => if s.area() > value { return Some(s.area()) });
432/// }
433/// None
434/// }
435///
436/// # fn main() {}
437/// ```
438///
439/// The body may also move anything it owns, since only one arm ever runs, and it can be `async`.
440/// To handle some variants differently, match first and let the last arm fall through:
441///
442/// ```
443/// # use closed_trait::{enumerate, sealed};
444/// # pub struct Square { pub side: i32 }
445/// # pub struct Circle { pub radius: i32 }
446/// # #[enumerate(match_any)]
447/// # #[sealed(Square, Circle)]
448/// # pub trait Shape { fn area(&self) -> i32; }
449/// # impl Shape for Square { fn area(&self) -> i32 { self.side * self.side } }
450/// # impl Shape for Circle { fn area(&self) -> i32 { 3 * self.radius * self.radius } }
451/// # fn main() {
452/// # let shape = AnyShape::from(Square { side: 3 });
453/// let cost = match &shape {
454/// AnyShape::Square(_) => 0,
455/// other => match_any_shape!(other, s => s.area()),
456/// };
457/// # assert_eq!(cost, 0);
458/// # }
459/// ```
460///
461/// Two things follow from it being a macro. The enum and the trait must be in scope where it is
462/// called, because a `macro_rules!` body resolves paths at the call site. And the body is *copied*
463/// into every arm.
464///
465/// That copying is worth being deliberate about. It costs compile time in proportion to the number
466/// of variants, since the body is type-checked once per arm, and one mistake in it is reported once
467/// per arm too. Nesting one of these inside another squares the count.
468///
469/// The option takes an optional name, so `match_any(match_shape)` generates `match_shape!` instead.
470/// Whether the macro can leave the crate depends on the trait's visibility, and so does whether
471/// it can collide, see [Visibility](#visibility).
472///
473/// # Visibility
474///
475/// Everything generated takes the trait's own visibility: the three enums, the conversions between
476/// them, and the names the match macros are reached through. There is no option to change it: the
477/// enums appear in the trait's supertrait bounds, so anything narrower would put a private type in
478/// a public interface.
479///
480/// It decides one thing beyond reach, though. A `macro_rules!` cannot leave the crate that defines
481/// it without `#[macro_export]`, and that always plants it at the crate root. So a macro generated
482/// for a `pub` trait goes there under a hidden name and is aliased beside the enum, while one for
483/// any narrower trait simply stays where it was written:
484///
485/// | the trait is | the macro is | usable from another crate | can collide |
486/// | ----------------- | ------------------------------------------ | ------------------------- | ----------- |
487/// | `pub` | at the crate root, aliased beside the enum | yes | yes |
488/// | anything narrower | where it was written | no | no |
489///
490/// Colliding means two traits of the same name, in different modules, both asking for `match_any`:
491/// their hidden root names would be the same, and one of them needs `match_any(other_name)`.
492///
493/// # Generics
494///
495/// The enum takes the trait's parameters that at least one entry names, with their bounds. Those
496/// parameters have to be nameable in the supertrait bound that pins the enum, and only the
497/// trait's own are in scope there, so an entry must be generic *solely* over parameters the trait
498/// declares.
499///
500/// ```
501/// # use closed_trait::{enumerate, sealed};
502///
503/// struct Boxed<T>(T);
504/// struct Listed<T>(Vec<T>);
505///
506/// #[enumerate(match_any)]
507/// #[sealed(Boxed<T>, Listed<T>)]
508/// pub trait Store<T> {}
509///
510/// impl<T> Store<T> for Boxed<T> {}
511/// impl<T> Store<T> for Listed<T> {}
512///
513/// fn main() {
514/// let _: AnyStore<u8> = Listed(vec![]).into();
515/// }
516/// ```
517///
518/// The enum is generic over the parameters its *variants* use, not over the trait's. An enum
519/// declaring one that no variant uses is `E0392`, so a list whose every entry fixes its arguments
520/// produces a plain enum rather than a generic one.
521///
522/// ```
523/// # use closed_trait::{enumerate, sealed};
524///
525/// // every entry fixes its argument, so `AnyValue` is a plain enum
526/// #[enumerate]
527/// #[sealed(i32: Value<i32>, f64: Value<f64>)]
528/// trait Value<T> {}
529///
530/// impl Value<i32> for i32 {}
531/// impl Value<f64> for f64 {}
532///
533/// fn main() {
534/// let _: AnyValue = AnyValue::i32(6);
535/// }
536/// ```
537///
538/// An entry that names no parameter the enum is generic over cannot produce a single enum type, and
539/// is rejected with a message naming the fix: annotate it in `#[sealed(..)]` with the
540/// instantiation it implements.
541///
542/// ## Pinned entries and `match_any`
543///
544/// An entry *pins* its arguments when it names a concrete instantiation instead of the trait's
545/// parameters. Such an entry becomes a variant like any other, and the enum does not record which
546/// instantiation that variant belongs to.
547///
548/// On the way *in* that costs nothing: `into_enum` and `From` exist only at the instantiations the
549/// entry named, so nothing ever builds a variant that does not belong.
550///
551/// ```
552/// # use closed_trait::{enumerate, sealed};
553/// # use closed_trait::Enumerable;
554/// struct Plain;
555///
556/// #[enumerate]
557/// #[sealed(Plain: Store<i32>)]
558/// pub trait Store<T> {}
559///
560/// impl Store<i32> for Plain {}
561///
562/// fn main() {
563/// let _: AnyStore = Plain.into_enum();
564/// }
565/// ```
566///
567/// On the way *out* it costs the macro. Nothing stops the trait from being *named* at an
568/// instantiation no permitted type implements, and that is precisely where a body may ask the
569/// macro to expand. This is what `match_any` would become there, written out by hand:
570///
571/// ```compile_fail
572/// # use closed_trait::{enumerate, sealed};
573/// #[enumerate]
574/// #[sealed(i32: Value<i32>)]
575/// trait Value<T> {}
576///
577/// impl Value<i32> for i32 {}
578///
579/// fn describe(value: impl Value<String>) {
580/// // what `match_any_value!(value.into_enum(), v => takes(v))` becomes
581/// match value.into_enum() {
582/// // error: the trait bound `i32: Value<String>` is not satisfied
583/// AnyValue::i32(v) => takes(v),
584/// }
585/// }
586///
587/// fn takes<V: Value<String>>(_: V) {}
588/// # fn main() {}
589/// ```
590///
591/// The enum is fine, and so is the signature: `Value<String>` is a legal bound, merely one that
592/// nothing satisfies. Drop the `match` and it compiles on its own:
593///
594/// ```
595/// # use closed_trait::{enumerate, sealed};
596/// # #[enumerate]
597/// # #[sealed(i32: Value<i32>)]
598/// # trait Value<T> {}
599/// # impl Value<i32> for i32 {}
600/// fn describe(_: impl Value<String>) {}
601/// # fn main() {}
602/// ```
603///
604/// What cannot hold is the `match`. `AnyValue::i32` hands back an `i32`, which is a `Value<i32>`
605/// and nothing else, so a body written against `Value<String>` cannot use it. Rather than generate
606/// that and let it fail inside the caller's code, `#[enumerate]` refuses it where the list is
607/// written.
608///
609/// None of this is a trade you elect. Pinning is the only way to put such a type in the enum at
610/// all: an entry that neither names the trait's parameters nor fixes them is refused outright, so
611/// the macro is not something you give up in exchange, it is simply unavailable once a variant
612/// exists that is not valid at every instantiation. `match_any` needs every entry to name the
613/// trait's parameters rather than fix them, which is exactly the case where every variant is valid
614/// everywhere.
615///
616/// A permitted type that is not `Sized` cannot be held in a variant. That one is rustc's to
617/// report rather than this macro's, since sizedness is not visible in the tokens.
618#[proc_macro_attribute]
619pub fn enumerate(args: TokenStream, item: TokenStream) -> TokenStream {
620 enumerate::enumerate(args, item)
621}