Skip to main content

rustc_hir/
target.rs

1//! This module lists attribute targets, with conversions from other types.
2
3use std::fmt::{self, Display};
4
5use rustc_ast::visit::AssocCtxt;
6use rustc_ast::{AssocItemKind, ForeignItemKind, ast};
7use rustc_macros::StableHash;
8
9use crate::def::DefKind;
10use crate::{Item, ItemKind, TraitItem, TraitItemKind, hir};
11
12#[derive(#[automatically_derived]
impl ::core::marker::Copy for GenericParamKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for GenericParamKind {
    #[inline]
    fn clone(&self) -> GenericParamKind { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for GenericParamKind {
    #[inline]
    fn eq(&self, other: &GenericParamKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for GenericParamKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                GenericParamKind::Type => "Type",
                GenericParamKind::Lifetime => "Lifetime",
                GenericParamKind::Const => "Const",
            })
    }
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for GenericParamKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            GenericParamKind {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    GenericParamKind::Type => {}
                    GenericParamKind::Lifetime => {}
                    GenericParamKind::Const => {}
                }
            }
        }
    };StableHash)]
13pub enum GenericParamKind {
14    Type,
15    Lifetime,
16    Const,
17}
18
19#[derive(#[automatically_derived]
impl ::core::marker::Copy for MethodKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for MethodKind {
    #[inline]
    fn clone(&self) -> MethodKind {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for MethodKind {
    #[inline]
    fn eq(&self, other: &MethodKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (MethodKind::Trait { body: __self_0 }, MethodKind::Trait {
                    body: __arg1_0 }) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for MethodKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            MethodKind::Trait { body: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Trait",
                    "body", &__self_0),
            MethodKind::TraitImpl =>
                ::core::fmt::Formatter::write_str(f, "TraitImpl"),
            MethodKind::Inherent =>
                ::core::fmt::Formatter::write_str(f, "Inherent"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for MethodKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for MethodKind {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    MethodKind::Trait { body: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    MethodKind::TraitImpl => {}
                    MethodKind::Inherent => {}
                }
            }
        }
    };StableHash)]
20pub enum MethodKind {
21    /// Method in a `trait Trait` block
22    Trait {
23        /// Whether a default is provided for this method
24        body: bool,
25    },
26    /// Method in a `impl Trait for Type` block
27    TraitImpl,
28    /// Method in a `impl Type` block
29    Inherent,
30}
31
32#[derive(#[automatically_derived]
impl ::core::marker::Copy for Target { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Target {
    #[inline]
    fn clone(&self) -> Target {
        let _: ::core::clone::AssertParamIsClone<bool>;
        let _: ::core::clone::AssertParamIsClone<MethodKind>;
        let _: ::core::clone::AssertParamIsClone<GenericParamKind>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Target {
    #[inline]
    fn eq(&self, other: &Target) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Target::Impl { of_trait: __self_0 }, Target::Impl {
                    of_trait: __arg1_0 }) => __self_0 == __arg1_0,
                (Target::Method(__self_0), Target::Method(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Target::GenericParam { kind: __self_0, has_default: __self_1
                    }, Target::GenericParam {
                    kind: __arg1_0, has_default: __arg1_1 }) =>
                    __self_1 == __arg1_1 && __self_0 == __arg1_0,
                (Target::Delegation { mac: __self_0 }, Target::Delegation {
                    mac: __arg1_0 }) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for Target {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Target::ExternCrate =>
                ::core::fmt::Formatter::write_str(f, "ExternCrate"),
            Target::Use => ::core::fmt::Formatter::write_str(f, "Use"),
            Target::Static => ::core::fmt::Formatter::write_str(f, "Static"),
            Target::Const => ::core::fmt::Formatter::write_str(f, "Const"),
            Target::Fn => ::core::fmt::Formatter::write_str(f, "Fn"),
            Target::Closure =>
                ::core::fmt::Formatter::write_str(f, "Closure"),
            Target::Mod => ::core::fmt::Formatter::write_str(f, "Mod"),
            Target::ForeignMod =>
                ::core::fmt::Formatter::write_str(f, "ForeignMod"),
            Target::GlobalAsm =>
                ::core::fmt::Formatter::write_str(f, "GlobalAsm"),
            Target::TyAlias =>
                ::core::fmt::Formatter::write_str(f, "TyAlias"),
            Target::Enum => ::core::fmt::Formatter::write_str(f, "Enum"),
            Target::Variant =>
                ::core::fmt::Formatter::write_str(f, "Variant"),
            Target::Struct => ::core::fmt::Formatter::write_str(f, "Struct"),
            Target::Field => ::core::fmt::Formatter::write_str(f, "Field"),
            Target::Union => ::core::fmt::Formatter::write_str(f, "Union"),
            Target::Trait => ::core::fmt::Formatter::write_str(f, "Trait"),
            Target::TraitAlias =>
                ::core::fmt::Formatter::write_str(f, "TraitAlias"),
            Target::Impl { of_trait: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Impl",
                    "of_trait", &__self_0),
            Target::Expression =>
                ::core::fmt::Formatter::write_str(f, "Expression"),
            Target::Statement =>
                ::core::fmt::Formatter::write_str(f, "Statement"),
            Target::Arm => ::core::fmt::Formatter::write_str(f, "Arm"),
            Target::AssocConst =>
                ::core::fmt::Formatter::write_str(f, "AssocConst"),
            Target::Method(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Method",
                    &__self_0),
            Target::AssocTy =>
                ::core::fmt::Formatter::write_str(f, "AssocTy"),
            Target::ForeignFn =>
                ::core::fmt::Formatter::write_str(f, "ForeignFn"),
            Target::ForeignStatic =>
                ::core::fmt::Formatter::write_str(f, "ForeignStatic"),
            Target::ForeignTy =>
                ::core::fmt::Formatter::write_str(f, "ForeignTy"),
            Target::GenericParam { kind: __self_0, has_default: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "GenericParam", "kind", __self_0, "has_default", &__self_1),
            Target::MacroDef =>
                ::core::fmt::Formatter::write_str(f, "MacroDef"),
            Target::Param => ::core::fmt::Formatter::write_str(f, "Param"),
            Target::PatField =>
                ::core::fmt::Formatter::write_str(f, "PatField"),
            Target::ExprField =>
                ::core::fmt::Formatter::write_str(f, "ExprField"),
            Target::WherePredicate =>
                ::core::fmt::Formatter::write_str(f, "WherePredicate"),
            Target::MacroCall =>
                ::core::fmt::Formatter::write_str(f, "MacroCall"),
            Target::Crate => ::core::fmt::Formatter::write_str(f, "Crate"),
            Target::Delegation { mac: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "Delegation", "mac", &__self_0),
            Target::ForLoop =>
                ::core::fmt::Formatter::write_str(f, "ForLoop"),
            Target::While => ::core::fmt::Formatter::write_str(f, "While"),
            Target::Loop => ::core::fmt::Formatter::write_str(f, "Loop"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for Target {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<MethodKind>;
        let _: ::core::cmp::AssertParamIsEq<GenericParamKind>;
    }
}Eq, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Target {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Target::ExternCrate => {}
                    Target::Use => {}
                    Target::Static => {}
                    Target::Const => {}
                    Target::Fn => {}
                    Target::Closure => {}
                    Target::Mod => {}
                    Target::ForeignMod => {}
                    Target::GlobalAsm => {}
                    Target::TyAlias => {}
                    Target::Enum => {}
                    Target::Variant => {}
                    Target::Struct => {}
                    Target::Field => {}
                    Target::Union => {}
                    Target::Trait => {}
                    Target::TraitAlias => {}
                    Target::Impl { of_trait: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Target::Expression => {}
                    Target::Statement => {}
                    Target::Arm => {}
                    Target::AssocConst => {}
                    Target::Method(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Target::AssocTy => {}
                    Target::ForeignFn => {}
                    Target::ForeignStatic => {}
                    Target::ForeignTy => {}
                    Target::GenericParam {
                        kind: ref __binding_0, has_default: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    Target::MacroDef => {}
                    Target::Param => {}
                    Target::PatField => {}
                    Target::ExprField => {}
                    Target::WherePredicate => {}
                    Target::MacroCall => {}
                    Target::Crate => {}
                    Target::Delegation { mac: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Target::ForLoop => {}
                    Target::While => {}
                    Target::Loop => {}
                }
            }
        }
    };StableHash)]
33pub enum Target {
34    ExternCrate,
35    Use,
36    Static,
37    Const,
38    Fn,
39    Closure,
40    Mod,
41    ForeignMod,
42    GlobalAsm,
43    TyAlias,
44    Enum,
45    Variant,
46    Struct,
47    Field,
48    Union,
49    Trait,
50    TraitAlias,
51    Impl { of_trait: bool },
52    Expression,
53    Statement,
54    Arm,
55    AssocConst,
56    Method(MethodKind),
57    AssocTy,
58    ForeignFn,
59    ForeignStatic,
60    ForeignTy,
61    GenericParam { kind: GenericParamKind, has_default: bool },
62    MacroDef,
63    Param,
64    PatField,
65    ExprField,
66    WherePredicate,
67    MacroCall,
68    Crate,
69    Delegation { mac: bool },
70    ForLoop,
71    While,
72    Loop,
73}
74
75impl Display for Target {
76    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77        f.write_fmt(format_args!("{0}", Self::name(*self)))write!(f, "{}", Self::name(*self))
78    }
79}
80
81impl ::rustc_error_messages::IntoDiagArg for Target {
    fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>)
        -> ::rustc_error_messages::DiagArgValue {
        self.to_string().into_diag_arg(path)
    }
}rustc_error_messages::into_diag_arg_using_display!(Target);
82
83impl Target {
84    pub fn is_associated_item(self) -> bool {
85        match self {
86            Target::AssocConst | Target::AssocTy | Target::Method(_) => true,
87            Target::ExternCrate
88            | Target::Use
89            | Target::Static
90            | Target::Const
91            | Target::Fn
92            | Target::Closure
93            | Target::Mod
94            | Target::ForeignMod
95            | Target::GlobalAsm
96            | Target::TyAlias
97            | Target::Enum
98            | Target::Variant
99            | Target::Struct
100            | Target::Field
101            | Target::Union
102            | Target::Trait
103            | Target::TraitAlias
104            | Target::Impl { .. }
105            | Target::Expression
106            | Target::Statement
107            | Target::Arm
108            | Target::ForeignFn
109            | Target::ForeignStatic
110            | Target::ForeignTy
111            | Target::GenericParam { .. }
112            | Target::MacroDef
113            | Target::Param
114            | Target::PatField
115            | Target::ExprField
116            | Target::MacroCall
117            | Target::Crate
118            | Target::WherePredicate
119            | Target::Delegation { .. }
120            | Target::Loop
121            | Target::While
122            | Target::ForLoop => false,
123        }
124    }
125
126    pub fn from_item(item: &Item<'_>) -> Target {
127        match item.kind {
128            ItemKind::ExternCrate(..) => Target::ExternCrate,
129            ItemKind::Use(..) => Target::Use,
130            ItemKind::Static { .. } => Target::Static,
131            ItemKind::Const(..) => Target::Const,
132            ItemKind::Fn { .. } => Target::Fn,
133            ItemKind::Macro(..) => Target::MacroDef,
134            ItemKind::Mod(..) => Target::Mod,
135            ItemKind::ForeignMod { .. } => Target::ForeignMod,
136            ItemKind::GlobalAsm { .. } => Target::GlobalAsm,
137            ItemKind::TyAlias(..) => Target::TyAlias,
138            ItemKind::Enum(..) => Target::Enum,
139            ItemKind::Struct(..) => Target::Struct,
140            ItemKind::Union(..) => Target::Union,
141            ItemKind::Trait { .. } => Target::Trait,
142            ItemKind::TraitAlias(..) => Target::TraitAlias,
143            ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
144        }
145    }
146
147    // FIXME: For now, should only be used with def_kinds from ItemIds
148    pub fn from_def_kind(def_kind: DefKind) -> Target {
149        match def_kind {
150            DefKind::ExternCrate => Target::ExternCrate,
151            DefKind::Use => Target::Use,
152            DefKind::Static { .. } => Target::Static,
153            DefKind::Const { .. } => Target::Const,
154            DefKind::Fn => Target::Fn,
155            DefKind::Macro(..) => Target::MacroDef,
156            DefKind::Mod => Target::Mod,
157            DefKind::ForeignMod => Target::ForeignMod,
158            DefKind::GlobalAsm => Target::GlobalAsm,
159            DefKind::TyAlias => Target::TyAlias,
160            DefKind::Enum => Target::Enum,
161            DefKind::Struct => Target::Struct,
162            DefKind::Union => Target::Union,
163            DefKind::Trait => Target::Trait,
164            DefKind::TraitAlias => Target::TraitAlias,
165            DefKind::Impl { of_trait } => Target::Impl { of_trait },
166            _ => { ::core::panicking::panic_fmt(format_args!("impossible case reached")); }panic!("impossible case reached"),
167        }
168    }
169
170    pub fn from_ast_item(item: &ast::Item) -> Target {
171        match item.kind {
172            ast::ItemKind::ExternCrate(..) => Target::ExternCrate,
173            ast::ItemKind::Use(..) => Target::Use,
174            ast::ItemKind::Static { .. } => Target::Static,
175            ast::ItemKind::Const(..) => Target::Const,
176            ast::ItemKind::ConstBlock(..) => Target::Const,
177            ast::ItemKind::Fn { .. } => Target::Fn,
178            ast::ItemKind::Mod(..) => Target::Mod,
179            ast::ItemKind::ForeignMod { .. } => Target::ForeignMod,
180            ast::ItemKind::GlobalAsm { .. } => Target::GlobalAsm,
181            ast::ItemKind::TyAlias(..) => Target::TyAlias,
182            ast::ItemKind::Enum(..) => Target::Enum,
183            ast::ItemKind::Struct(..) => Target::Struct,
184            ast::ItemKind::Union(..) => Target::Union,
185            ast::ItemKind::Trait(..) => Target::Trait,
186            ast::ItemKind::TraitAlias(..) => Target::TraitAlias,
187            ast::ItemKind::Impl(ref i) => Target::Impl { of_trait: i.of_trait.is_some() },
188            ast::ItemKind::MacCall(..) => Target::MacroCall,
189            ast::ItemKind::MacroDef(..) => Target::MacroDef,
190            ast::ItemKind::Delegation(..) => Target::Delegation { mac: false },
191            ast::ItemKind::DelegationMac(..) => Target::Delegation { mac: true },
192        }
193    }
194
195    pub fn from_foreign_item_kind(kind: &ast::ForeignItemKind) -> Target {
196        match kind {
197            ForeignItemKind::Static(_) => Target::ForeignStatic,
198            ForeignItemKind::Fn(_) => Target::ForeignFn,
199            ForeignItemKind::TyAlias(_) => Target::ForeignTy,
200            ForeignItemKind::MacCall(_) => Target::MacroCall,
201        }
202    }
203
204    pub fn from_trait_item(trait_item: &TraitItem<'_>) -> Target {
205        match trait_item.kind {
206            TraitItemKind::Const(..) => Target::AssocConst,
207            TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => {
208                Target::Method(MethodKind::Trait { body: false })
209            }
210            TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
211                Target::Method(MethodKind::Trait { body: true })
212            }
213            TraitItemKind::Type(..) => Target::AssocTy,
214        }
215    }
216
217    pub fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target {
218        match foreign_item.kind {
219            hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
220            hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
221            hir::ForeignItemKind::Type => Target::ForeignTy,
222        }
223    }
224
225    pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
226        match generic_param.kind {
227            hir::GenericParamKind::Type { default, .. } => Target::GenericParam {
228                kind: GenericParamKind::Type,
229                has_default: default.is_some(),
230            },
231            hir::GenericParamKind::Lifetime { .. } => {
232                Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }
233            }
234            hir::GenericParamKind::Const { default, .. } => Target::GenericParam {
235                kind: GenericParamKind::Const,
236                has_default: default.is_some(),
237            },
238        }
239    }
240
241    pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, assoc_ctxt: AssocCtxt) -> Target {
242        match kind {
243            AssocItemKind::Const(_) => Target::AssocConst,
244            AssocItemKind::Fn(f) => Target::Method(match assoc_ctxt {
245                AssocCtxt::Trait => MethodKind::Trait { body: f.body.is_some() },
246                AssocCtxt::Impl { of_trait, .. } => {
247                    if of_trait {
248                        MethodKind::TraitImpl
249                    } else {
250                        MethodKind::Inherent
251                    }
252                }
253            }),
254            AssocItemKind::Type(_) => Target::AssocTy,
255            AssocItemKind::Delegation(_) => Target::Delegation { mac: false },
256            AssocItemKind::DelegationMac(_) => Target::Delegation { mac: true },
257            AssocItemKind::MacCall(_) => Target::MacroCall,
258        }
259    }
260
261    pub fn from_expr(expr: &ast::Expr) -> Self {
262        match &expr.kind {
263            ast::ExprKind::Closure(..) | ast::ExprKind::Gen(..) => Self::Closure,
264            ast::ExprKind::Paren(e) => Self::from_expr(&e),
265            ast::ExprKind::ForLoop { .. } => Self::ForLoop,
266            ast::ExprKind::Loop(..) => Self::Loop,
267            ast::ExprKind::While(..) => Self::While,
268            _ => Self::Expression,
269        }
270    }
271
272    pub fn name(self) -> &'static str {
273        match self {
274            Target::ExternCrate => "extern crate",
275            Target::Use => "use",
276            Target::Static => "static",
277            Target::Const => "constant",
278            Target::Fn => "function",
279            Target::Closure => "closure",
280            Target::Mod => "module",
281            Target::ForeignMod => "foreign module",
282            Target::GlobalAsm => "global asm",
283            Target::TyAlias => "type alias",
284            Target::Enum => "enum",
285            Target::Variant => "enum variant",
286            Target::Struct => "struct",
287            Target::Field => "struct field",
288            Target::Union => "union",
289            Target::Trait => "trait",
290            Target::TraitAlias => "trait alias",
291            Target::Impl { .. } => "implementation block",
292            Target::Expression => "expression",
293            Target::Statement => "statement",
294            Target::Arm => "match arm",
295            Target::AssocConst => "associated const",
296            Target::Method(kind) => match kind {
297                MethodKind::Inherent => "inherent method",
298                MethodKind::Trait { body: false } => "required trait method",
299                MethodKind::Trait { body: true } => "provided trait method",
300                MethodKind::TraitImpl => "trait method in an impl block",
301            },
302            Target::AssocTy => "associated type",
303            Target::ForeignFn => "foreign function",
304            Target::ForeignStatic => "foreign static item",
305            Target::ForeignTy => "foreign type",
306            Target::GenericParam { kind, .. } => match kind {
307                GenericParamKind::Type => "type parameter",
308                GenericParamKind::Lifetime => "lifetime parameter",
309                GenericParamKind::Const => "const parameter",
310            },
311            Target::MacroDef => "macro def",
312            Target::Param => "function param",
313            Target::PatField => "pattern field",
314            Target::ExprField => "struct field",
315            Target::WherePredicate => "where predicate",
316            Target::MacroCall => "macro call",
317            Target::Crate => "crate",
318            Target::Delegation { .. } => "delegation",
319            Target::Loop => "loop",
320            Target::ForLoop => "for loop",
321            Target::While => "while loop",
322        }
323    }
324
325    pub fn plural_name(self) -> &'static str {
326        match self {
327            Target::ExternCrate => "extern crates",
328            Target::Use => "use statements",
329            Target::Static => "statics",
330            Target::Const => "constants",
331            Target::Fn => "functions",
332            Target::Closure => "closures",
333            Target::Mod => "modules",
334            Target::ForeignMod => "foreign modules",
335            Target::GlobalAsm => "global asms",
336            Target::TyAlias => "type aliases",
337            Target::Enum => "enums",
338            Target::Variant => "enum variants",
339            Target::Struct => "structs",
340            Target::Field => "struct fields",
341            Target::Union => "unions",
342            Target::Trait => "traits",
343            Target::TraitAlias => "trait aliases",
344            Target::Impl { of_trait: false } => "inherent impl blocks",
345            Target::Impl { of_trait: true } => "trait impl blocks",
346            Target::Expression => "expressions",
347            Target::Statement => "statements",
348            Target::Arm => "match arms",
349            Target::AssocConst => "associated consts",
350            Target::Method(kind) => match kind {
351                MethodKind::Inherent => "inherent methods",
352                MethodKind::Trait { body: false } => "required trait methods",
353                MethodKind::Trait { body: true } => "provided trait methods",
354                MethodKind::TraitImpl => "trait methods in impl blocks",
355            },
356            Target::AssocTy => "associated types",
357            Target::ForeignFn => "foreign functions",
358            Target::ForeignStatic => "foreign statics",
359            Target::ForeignTy => "foreign types",
360            Target::GenericParam { kind, has_default: _ } => match kind {
361                GenericParamKind::Type => "type parameters",
362                GenericParamKind::Lifetime => "lifetime parameters",
363                GenericParamKind::Const => "const parameters",
364            },
365            Target::MacroDef => "macro defs",
366            Target::Param => "function params",
367            Target::PatField => "pattern fields",
368            Target::ExprField => "struct fields",
369            Target::WherePredicate => "where predicates",
370            Target::MacroCall => "macro calls",
371            Target::Crate => "crates",
372            Target::Delegation { .. } => "delegations",
373            Target::ForLoop => "for loops",
374            Target::Loop => "loops",
375            Target::While => "while loops",
376        }
377    }
378}