Skip to main content

hir_lang/
item.rs

1//! Items (declarations), their parts, and attributes.
2
3use intern_lang::Symbol;
4use span_lang::Span;
5
6use crate::{
7    expr::DefaultEval,
8    id::{BinderId, ExprId, FieldId, ItemId, List, ParamId, PatId, PathId, TyId, VariantId},
9    lit::Lit,
10    origin::{Ident, Name},
11    ty::{Bound, Effects, GenericArg},
12};
13
14/// Visibility of an item or field.
15///
16/// # Examples
17///
18/// ```
19/// use hir_lang::Vis;
20///
21/// assert_eq!(Vis::default(), Vis::Private);
22/// ```
23#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
24pub enum Vis {
25    /// Visible in the declaring module (and, by language rule, its children).
26    #[default]
27    Private,
28    /// Visible in the declaring class and its subclasses.
29    Protected,
30    /// Visible in the declaring package/crate.
31    Package,
32    /// Visible everywhere.
33    Public,
34}
35
36/// One generic parameter: its binder, bounds, and optional type and default.
37///
38/// A parameter with a `ty` is a constant parameter (binder kind `ConstParam`);
39/// one without is a type parameter or region (`TypeParam` or `Region`).
40///
41/// # Examples
42///
43/// ```
44/// use hir_lang::{Binder, BinderKind, Builder, GenericParam, List, Name};
45/// use intern_lang::Interner;
46///
47/// let mut names = Interner::new();
48/// let mut b = Builder::new();
49/// let t = b.binder(Binder::new(Name::new(names.intern("T")), BinderKind::TypeParam));
50/// let gp = GenericParam::new(t);
51/// assert!(gp.ty.is_none() && gp.bounds.is_empty());
52/// ```
53#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
54pub struct GenericParam {
55    /// The parameter's binder.
56    pub binder: BinderId,
57    /// Interface and region bounds.
58    pub bounds: List<Bound>,
59    /// The type of a constant parameter.
60    pub ty: Option<TyId>,
61    /// The default: a type, or `GenericArg::Const` for a constant parameter.
62    pub default: Option<GenericArg>,
63}
64
65impl GenericParam {
66    /// A parameter with no bounds, type, or default.
67    ///
68    /// # Examples
69    ///
70    /// ```
71    /// use hir_lang::{Binder, BinderKind, Builder, GenericParam, Name};
72    /// use intern_lang::Interner;
73    ///
74    /// let mut names = Interner::new();
75    /// let mut b = Builder::new();
76    /// let u = b.binder(Binder::new(Name::new(names.intern("U")), BinderKind::TypeParam));
77    /// assert_eq!(GenericParam::new(u).binder, u);
78    /// ```
79    #[must_use]
80    pub const fn new(binder: BinderId) -> Self {
81        Self {
82            binder,
83            bounds: List::EMPTY,
84            ty: None,
85            default: None,
86        }
87    }
88}
89
90/// A `where` predicate: `T: A + 'r` or `'a: 'b`.
91///
92/// # Examples
93///
94/// ```
95/// use hir_lang::{Bound, Builder, List, Ty, WherePred};
96///
97/// let mut b = Builder::new();
98/// let ty = b.ty(Ty::SelfTy);
99/// let pred = WherePred { subject: Bound::Ty(ty), bounds: List::EMPTY };
100/// assert_eq!(pred.subject, Bound::Ty(ty));
101/// ```
102#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
103pub struct WherePred {
104    /// The constrained type or region.
105    pub subject: Bound,
106    /// Its bounds.
107    pub bounds: List<Bound>,
108}
109
110/// The generic parameters and predicates of an item.
111///
112/// # Examples
113///
114/// ```
115/// use hir_lang::Generics;
116///
117/// assert!(Generics::default().params.is_empty());
118/// ```
119#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
120pub struct Generics {
121    /// The parameters; each is visible in the whole item.
122    pub params: List<GenericParam>,
123    /// `where` predicates.
124    pub preds: List<WherePred>,
125}
126
127/// How a parameter receives its argument. Parameters appear in this order;
128/// `Receiver`, `Rest`, and `RestNamed` at most once each.
129///
130/// # Examples
131///
132/// ```
133/// use hir_lang::ParamKind;
134///
135/// assert_eq!(ParamKind::default(), ParamKind::Normal);
136/// assert!(ParamKind::Receiver < ParamKind::NamedOnly);
137/// ```
138#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
139pub enum ParamKind {
140    /// `self`: the first parameter of a method in an interface, impl, or class.
141    Receiver,
142    /// By position only.
143    PositionalOnly,
144    /// By position or by name.
145    #[default]
146    Normal,
147    /// Collects the remaining positional arguments (`...args`, `*args`).
148    Rest,
149    /// By name only.
150    NamedOnly,
151    /// Collects the remaining named arguments (`**kwargs`).
152    RestNamed,
153}
154
155/// A function or closure parameter.
156///
157/// # Examples
158///
159/// ```
160/// use hir_lang::{Builder, Param, ParamKind, Pat};
161///
162/// let mut b = Builder::new();
163/// let pat = b.pat(Pat::Wild);
164/// let p = Param::new(pat);
165/// assert_eq!(p.kind, ParamKind::Normal);
166/// ```
167#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
168pub struct Param {
169    /// The pattern; its binders (kind `Param`) are visible in later parameters
170    /// and the body.
171    pub pat: PatId,
172    /// The annotation.
173    pub ty: Option<TyId>,
174    /// The default, evaluated at each call with earlier parameters visible.
175    pub default: Option<ExprId>,
176    /// How the argument is received.
177    pub kind: ParamKind,
178    /// The parameter aliases the caller's place (PHP `&$x`); the matching
179    /// argument should be a place (`Arg::place`).
180    pub by_ref: bool,
181}
182
183impl Param {
184    /// A `Normal` parameter without type or default.
185    ///
186    /// # Examples
187    ///
188    /// ```
189    /// use hir_lang::{Builder, Param, Pat};
190    ///
191    /// let mut b = Builder::new();
192    /// let pat = b.pat(Pat::Wild);
193    /// assert!(Param::new(pat).default.is_none());
194    /// ```
195    #[must_use]
196    pub const fn new(pat: PatId) -> Self {
197        Self {
198            pat,
199            ty: None,
200            default: None,
201            kind: ParamKind::Normal,
202            by_ref: false,
203        }
204    }
205}
206
207/// The field layout of a record or variant.
208///
209/// # Examples
210///
211/// ```
212/// use hir_lang::Shape;
213///
214/// assert_eq!(Shape::default(), Shape::Named);
215/// ```
216#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
217pub enum Shape {
218    /// Named fields: `{ x: i32 }`.
219    #[default]
220    Named,
221    /// Positional fields: `(i32, i32)`.
222    Tuple,
223    /// No fields.
224    Unit,
225}
226
227/// A field of a record, class, or variant.
228///
229/// # Examples
230///
231/// ```
232/// use hir_lang::{FieldDef, Ident, Span};
233/// use intern_lang::Interner;
234///
235/// let mut names = Interner::new();
236/// let f = FieldDef::named(Ident::new(names.intern("x"), Span::empty(0)));
237/// assert!(f.ty.is_none());
238/// ```
239#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
240pub struct FieldDef {
241    /// The name; absent for positional fields.
242    pub name: Option<Ident>,
243    /// Visibility.
244    pub vis: Vis,
245    /// The type; absent in dynamic languages.
246    pub ty: Option<TyId>,
247    /// A default value (a constant context).
248    pub default: Option<ExprId>,
249}
250
251impl FieldDef {
252    /// A named field without type or default.
253    ///
254    /// # Examples
255    ///
256    /// ```
257    /// use hir_lang::{FieldDef, Ident, Span, Vis};
258    /// use intern_lang::Interner;
259    ///
260    /// let mut names = Interner::new();
261    /// let f = FieldDef::named(Ident::new(names.intern("y"), Span::empty(0)));
262    /// assert_eq!(f.vis, Vis::Private);
263    /// ```
264    #[must_use]
265    pub const fn named(name: Ident) -> Self {
266        Self {
267            name: Some(name),
268            vis: Vis::Private,
269            ty: None,
270            default: None,
271        }
272    }
273}
274
275/// A variant of a sum.
276///
277/// # Examples
278///
279/// ```
280/// use hir_lang::{Ident, List, Shape, Span, Variant};
281/// use intern_lang::Interner;
282///
283/// let mut names = Interner::new();
284/// let none = Variant {
285///     name: Ident::new(names.intern("None"), Span::empty(0)),
286///     shape: Shape::Unit,
287///     fields: List::EMPTY,
288///     discriminant: None,
289/// };
290/// assert_eq!(none.shape, Shape::Unit);
291/// ```
292#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
293pub struct Variant {
294    /// The name (unique per sum).
295    pub name: Ident,
296    /// The field layout.
297    pub shape: Shape,
298    /// The fields.
299    pub fields: List<FieldId>,
300    /// An explicit discriminant (a constant context).
301    pub discriminant: Option<ExprId>,
302}
303
304/// A function: signature and optional body.
305///
306/// # Examples
307///
308/// ```
309/// use hir_lang::{Effects, FnDef};
310///
311/// let decl = FnDef::default();
312/// assert!(decl.body.is_none());
313/// assert_eq!(decl.effects, Effects::NONE);
314/// ```
315#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
316pub struct FnDef {
317    /// Generic parameters.
318    pub generics: Generics,
319    /// Parameters, in kind order.
320    pub params: List<ParamId>,
321    /// The declared return type.
322    pub ret: Option<TyId>,
323    /// Declared effects.
324    pub effects: Effects,
325    /// The thrown type, if declared.
326    pub throws: Option<TyId>,
327    /// A foreign calling convention (`extern "C"`); allows a missing body.
328    pub abi: Option<Symbol>,
329    /// The body; absent for required, abstract, and foreign functions.
330    pub body: Option<ExprId>,
331    /// When parameter defaults are evaluated.
332    pub defaults: DefaultEval,
333}
334
335/// A record (struct).
336///
337/// # Examples
338///
339/// ```
340/// use hir_lang::{RecordDef, Shape};
341///
342/// assert_eq!(RecordDef::default().shape, Shape::Named);
343/// ```
344#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
345pub struct RecordDef {
346    /// Generic parameters.
347    pub generics: Generics,
348    /// The field layout.
349    pub shape: Shape,
350    /// The fields.
351    pub fields: List<FieldId>,
352    /// An untagged union: the fields overlap (Zero, Kraken); shape `Named`.
353    pub is_union: bool,
354}
355
356/// A sum (enum, tagged union).
357///
358/// # Examples
359///
360/// ```
361/// use hir_lang::SumDef;
362///
363/// assert!(SumDef::default().variants.is_empty());
364/// ```
365#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
366pub struct SumDef {
367    /// Generic parameters.
368    pub generics: Generics,
369    /// The variants (unique names).
370    pub variants: List<VariantId>,
371}
372
373/// A class: fields, base classes, interfaces, and members. Also a PHP trait
374/// (`mixin`), whose members are copied into the classes that use it.
375///
376/// # Examples
377///
378/// ```
379/// use hir_lang::ClassDef;
380///
381/// let class = ClassDef::default();
382/// assert!(class.bases.is_empty() && !class.is_abstract);
383/// ```
384#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
385pub struct ClassDef {
386    /// Generic parameters.
387    pub generics: Generics,
388    /// Base classes (one for PHP, several for Python), in resolution order.
389    pub bases: List<TyId>,
390    /// Implemented interfaces.
391    pub interfaces: List<TyId>,
392    /// Instance fields (named, unique).
393    pub fields: List<FieldId>,
394    /// Members: `Fn`, `Const`, `Global` (statics), `Alias`, `MixinUse`.
395    pub items: List<ItemId>,
396    /// Cannot be instantiated; may declare abstract methods.
397    pub is_abstract: bool,
398    /// Cannot be extended.
399    pub is_final: bool,
400    /// A PHP trait: a mixin of members, used by classes, never instantiated.
401    pub mixin: bool,
402}
403
404/// What a mixin rule does with a method.
405///
406/// # Examples
407///
408/// ```
409/// use hir_lang::{List, MixinAction};
410///
411/// assert!(matches!(MixinAction::Insteadof(List::EMPTY), MixinAction::Insteadof(_)));
412/// ```
413#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
414pub enum MixinAction {
415    /// `A::m insteadof B, C`: take `m` from this mixin, not from those.
416    Insteadof(List<TyId>),
417    /// `A::m as protected n`: also expose `m` under a new name and/or
418    /// visibility.
419    Alias {
420        /// The new name.
421        name: Option<Ident>,
422        /// The new visibility.
423        vis: Option<Vis>,
424    },
425}
426
427/// One conflict-resolution rule of a mixin use.
428///
429/// # Examples
430///
431/// ```
432/// use hir_lang::{Ident, MixinAction, MixinRule, Span};
433/// use intern_lang::Interner;
434///
435/// let mut names = Interner::new();
436/// let rule = MixinRule {
437///     method: Ident::new(names.intern("hello"), Span::empty(0)),
438///     from: None,
439///     action: MixinAction::Alias { name: None, vis: None },
440/// };
441/// assert!(rule.from.is_none());
442/// ```
443#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
444pub struct MixinRule {
445    /// The method.
446    pub method: Ident,
447    /// The mixin it comes from (`A::m`), if qualified.
448    pub from: Option<TyId>,
449    /// What to do.
450    pub action: MixinAction,
451}
452
453/// `use A, B { rules }` inside a class: copy the members of mixins (PHP
454/// traits). resolve-lang expands it after resolution.
455///
456/// # Examples
457///
458/// ```
459/// use hir_lang::MixinUseDef;
460///
461/// assert!(MixinUseDef::default().mixins.is_empty());
462/// ```
463#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
464pub struct MixinUseDef {
465    /// The mixins (paths to `mixin` classes).
466    pub mixins: List<TyId>,
467    /// Conflict-resolution rules.
468    pub rules: List<MixinRule>,
469}
470
471/// An interface (trait).
472///
473/// # Examples
474///
475/// ```
476/// use hir_lang::InterfaceDef;
477///
478/// assert!(InterfaceDef::default().supers.is_empty());
479/// ```
480#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
481pub struct InterfaceDef {
482    /// Generic parameters.
483    pub generics: Generics,
484    /// Super-interfaces.
485    pub supers: List<TyId>,
486    /// Members: `Fn` (body = default method), `Const`, `AssocType`.
487    pub items: List<ItemId>,
488}
489
490/// An implementation block.
491///
492/// # Examples
493///
494/// ```
495/// use hir_lang::{Builder, ImplDef, Ty};
496///
497/// let mut b = Builder::new();
498/// let self_ty = b.ty(Ty::SelfTy);
499/// let inherent = ImplDef::new(self_ty);
500/// assert!(inherent.interface.is_none());
501/// ```
502#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
503pub struct ImplDef {
504    /// Generic parameters.
505    pub generics: Generics,
506    /// The implemented interface; absent for an inherent impl.
507    pub interface: Option<TyId>,
508    /// The implementing type.
509    pub self_ty: TyId,
510    /// Members: `Fn`, `Const`, `Alias`.
511    pub items: List<ItemId>,
512}
513
514impl ImplDef {
515    /// An inherent impl with no generics or members.
516    ///
517    /// # Examples
518    ///
519    /// ```
520    /// use hir_lang::{Builder, ImplDef, Ty};
521    ///
522    /// let mut b = Builder::new();
523    /// let t = b.ty(Ty::Any);
524    /// assert!(ImplDef::new(t).items.is_empty());
525    /// ```
526    #[must_use]
527    pub const fn new(self_ty: TyId) -> Self {
528        Self {
529            generics: Generics {
530                params: List::EMPTY,
531                preds: List::EMPTY,
532            },
533            interface: None,
534            self_ty,
535            items: List::EMPTY,
536        }
537    }
538}
539
540/// What an item declares; see the spec, §10.
541///
542/// # Examples
543///
544/// ```
545/// use hir_lang::{ItemKind, List};
546///
547/// let module = ItemKind::Module { items: List::EMPTY, body: None, effects: hir_lang::Effects::NONE };
548/// assert!(matches!(module, ItemKind::Module { .. }));
549/// ```
550#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
551pub enum ItemKind {
552    /// A function.
553    Fn(FnDef),
554    /// A record.
555    Record(RecordDef),
556    /// A sum.
557    Sum(SumDef),
558    /// A class.
559    Class(ClassDef),
560    /// An interface.
561    Interface(InterfaceDef),
562    /// An implementation.
563    Impl(ImplDef),
564    /// A type alias, or an associated type's definition inside an impl.
565    Alias {
566        /// Generic parameters.
567        generics: Generics,
568        /// The aliased type.
569        ty: TyId,
570    },
571    /// An associated type declared by an interface.
572    AssocType {
573        /// Interface and region bounds.
574        bounds: List<Bound>,
575        /// A default.
576        default: Option<TyId>,
577    },
578    /// A compile-time constant.
579    Const {
580        /// The annotation.
581        ty: Option<TyId>,
582        /// The value; absent only in an interface.
583        value: Option<ExprId>,
584    },
585    /// A global or static variable.
586    Global {
587        /// The annotation.
588        ty: Option<TyId>,
589        /// Assignable after initialization.
590        mutable: bool,
591        /// The initializer.
592        init: Option<ExprId>,
593    },
594    /// A module; the root of every `Hir` is one.
595    Module {
596        /// The items.
597        items: List<ItemId>,
598        /// Top-level code run when the module loads (PHP and Python scripts,
599        /// NOML, REPL entries); a frame of its own that may `return`.
600        body: Option<ExprId>,
601        /// The effects the top-level code may perform (`await` at top level
602        /// needs `ASYNC`).
603        effects: Effects,
604    },
605    /// A mixin use inside a class (PHP `use T;`).
606    MixinUse(MixinUseDef),
607    /// An import: `use a::b`, `use a::b as c` (the item's name is the alias),
608    /// `use a::*` (`glob`, no name).
609    Import {
610        /// The imported path (`Import` namespace).
611        path: PathId,
612        /// A glob import.
613        glob: bool,
614    },
615    /// A declaration that failed to lower.
616    Err,
617}
618
619impl ItemKind {
620    /// Returns the kind's spelling, as the printer and errors use it.
621    ///
622    /// # Examples
623    ///
624    /// ```
625    /// use hir_lang::ItemKind;
626    ///
627    /// assert_eq!(ItemKind::Err.name(), "error");
628    /// ```
629    #[must_use]
630    pub const fn name(&self) -> &'static str {
631        match self {
632            Self::Fn(_) => "fn",
633            Self::Record(_) => "record",
634            Self::Sum(_) => "sum",
635            Self::Class(_) => "class",
636            Self::Interface(_) => "interface",
637            Self::Impl(_) => "impl",
638            Self::Alias { .. } => "alias",
639            Self::AssocType { .. } => "assoc-type",
640            Self::Const { .. } => "const",
641            Self::Global { .. } => "global",
642            Self::Module { .. } => "module",
643            Self::MixinUse(_) => "mixin-use",
644            Self::Import { .. } => "import",
645            Self::Err => "error",
646        }
647    }
648}
649
650/// A declaration.
651///
652/// # Examples
653///
654/// ```
655/// use hir_lang::{Item, ItemKind, List, Name, Vis};
656/// use intern_lang::Interner;
657///
658/// let mut names = Interner::new();
659/// let m = Item::new(Some(Name::new(names.intern("app"))), ItemKind::Module { items: List::EMPTY, body: None, effects: hir_lang::Effects::NONE })
660///     .with_vis(Vis::Public);
661/// assert_eq!(m.vis, Vis::Public);
662/// ```
663#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
664pub struct Item {
665    /// The hygienic name; required for most kinds (spec §10.1).
666    pub name: Option<Name>,
667    /// The span of the name itself.
668    pub name_span: Span,
669    /// Visibility.
670    pub vis: Vis,
671    /// What it declares.
672    pub kind: ItemKind,
673}
674
675impl Item {
676    /// A private item; the name span is empty (set it with
677    /// [`with_name_span`](Self::with_name_span)).
678    ///
679    /// # Examples
680    ///
681    /// ```
682    /// use hir_lang::{Item, ItemKind};
683    ///
684    /// let broken = Item::new(None, ItemKind::Err);
685    /// assert!(broken.name.is_none());
686    /// ```
687    #[must_use]
688    pub const fn new(name: Option<Name>, kind: ItemKind) -> Self {
689        Self {
690            name,
691            name_span: Span::empty(0),
692            vis: Vis::Private,
693            kind,
694        }
695    }
696
697    /// Returns the item with its visibility set.
698    ///
699    /// # Examples
700    ///
701    /// ```
702    /// use hir_lang::{Item, ItemKind, Vis};
703    ///
704    /// assert_eq!(Item::new(None, ItemKind::Err).with_vis(Vis::Package).vis, Vis::Package);
705    /// ```
706    #[must_use]
707    pub const fn with_vis(mut self, vis: Vis) -> Self {
708        self.vis = vis;
709        self
710    }
711
712    /// Returns the item with its name span set.
713    ///
714    /// # Examples
715    ///
716    /// ```
717    /// use hir_lang::{Item, ItemKind, Span};
718    ///
719    /// let item = Item::new(None, ItemKind::Err).with_name_span(Span::new(3, 7));
720    /// assert_eq!(item.name_span, Span::new(3, 7));
721    /// ```
722    #[must_use]
723    pub const fn with_name_span(mut self, span: Span) -> Self {
724        self.name_span = span;
725        self
726    }
727}
728
729/// An attribute value.
730///
731/// # Examples
732///
733/// ```
734/// use hir_lang::{AttrValue, IntLit, Lit};
735///
736/// let v = AttrValue::Lit(Lit::Int(IntLit::new(10)));
737/// assert!(matches!(v, AttrValue::Lit(_)));
738/// ```
739#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
740pub enum AttrValue {
741    /// A literal: `budget(cpu = 10)`.
742    Lit(Lit),
743    /// A bare name: `repr(C)`.
744    Name(Ident),
745}
746
747/// One attribute argument: `key = value`, `key`, or `value`.
748///
749/// # Examples
750///
751/// ```
752/// use hir_lang::{AttrArg, AttrValue, Ident, Span};
753/// use intern_lang::Interner;
754///
755/// let mut names = Interner::new();
756/// let c = AttrArg { key: None, value: Some(AttrValue::Name(Ident::new(names.intern("C"), Span::empty(0)))) };
757/// assert!(c.key.is_none());
758/// ```
759#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
760pub struct AttrArg {
761    /// The key, if any.
762    pub key: Option<Ident>,
763    /// The value, if any (not both absent).
764    pub value: Option<AttrValue>,
765}
766
767/// An attribute: `@inline`, `#[repr(C)]`, `@budget(cpu = 10, heat = 3)`.
768///
769/// Attributes are data, never code. They attach to any node with
770/// [`Builder::attach`](crate::Builder::attach).
771///
772/// # Examples
773///
774/// ```
775/// use hir_lang::{Attr, Ident, List, Span};
776/// use intern_lang::Interner;
777///
778/// let mut names = Interner::new();
779/// let inline = Attr { name: Ident::new(names.intern("inline"), Span::empty(0)), args: List::EMPTY };
780/// assert!(inline.args.is_empty());
781/// ```
782#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
783pub struct Attr {
784    /// The attribute's name.
785    pub name: Ident,
786    /// Its arguments.
787    pub args: List<AttrArg>,
788}