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"),
            Target::Break => ::core::fmt::Formatter::write_str(f, "Break"),
        }
    }
}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 => {}
                    Target::Break => {}
                }
            }
        }
    };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    Break,
74}
75
76impl Display for Target {
77    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78        f.write_fmt(format_args!("{0}", Self::name(*self)))write!(f, "{}", Self::name(*self))
79    }
80}
81
82impl ::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);
83
84impl Target {
85    pub fn is_associated_item(self) -> bool {
86        match self {
87            Target::AssocConst | Target::AssocTy | Target::Method(_) => true,
88            Target::ExternCrate
89            | Target::Use
90            | Target::Static
91            | Target::Const
92            | Target::Fn
93            | Target::Closure
94            | Target::Mod
95            | Target::ForeignMod
96            | Target::GlobalAsm
97            | Target::TyAlias
98            | Target::Enum
99            | Target::Variant
100            | Target::Struct
101            | Target::Field
102            | Target::Union
103            | Target::Trait
104            | Target::TraitAlias
105            | Target::Impl { .. }
106            | Target::Expression
107            | Target::Statement
108            | Target::Arm
109            | Target::ForeignFn
110            | Target::ForeignStatic
111            | Target::ForeignTy
112            | Target::GenericParam { .. }
113            | Target::MacroDef
114            | Target::Param
115            | Target::PatField
116            | Target::ExprField
117            | Target::MacroCall
118            | Target::Crate
119            | Target::WherePredicate
120            | Target::Delegation { .. }
121            | Target::Loop
122            | Target::While
123            | Target::ForLoop
124            | Target::Break => false,
125        }
126    }
127
128    pub fn from_item(item: &Item<'_>) -> Target {
129        match item.kind {
130            ItemKind::ExternCrate(..) => Target::ExternCrate,
131            ItemKind::Use(..) => Target::Use,
132            ItemKind::Static { .. } => Target::Static,
133            ItemKind::Const(..) => Target::Const,
134            ItemKind::Fn { .. } => Target::Fn,
135            ItemKind::Macro(..) => Target::MacroDef,
136            ItemKind::Mod(..) => Target::Mod,
137            ItemKind::ForeignMod { .. } => Target::ForeignMod,
138            ItemKind::GlobalAsm { .. } => Target::GlobalAsm,
139            ItemKind::TyAlias(..) => Target::TyAlias,
140            ItemKind::Enum(..) => Target::Enum,
141            ItemKind::Struct(..) => Target::Struct,
142            ItemKind::Union(..) => Target::Union,
143            ItemKind::Trait { .. } => Target::Trait,
144            ItemKind::TraitAlias(..) => Target::TraitAlias,
145            ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
146        }
147    }
148
149    // FIXME: For now, should only be used with def_kinds from ItemIds
150    pub fn from_def_kind(def_kind: DefKind) -> Target {
151        match def_kind {
152            DefKind::ExternCrate => Target::ExternCrate,
153            DefKind::Use => Target::Use,
154            DefKind::Static { .. } => Target::Static,
155            DefKind::Const { .. } => Target::Const,
156            DefKind::Fn => Target::Fn,
157            DefKind::Macro(..) => Target::MacroDef,
158            DefKind::Mod => Target::Mod,
159            DefKind::ForeignMod => Target::ForeignMod,
160            DefKind::GlobalAsm => Target::GlobalAsm,
161            DefKind::TyAlias => Target::TyAlias,
162            DefKind::Enum => Target::Enum,
163            DefKind::Struct => Target::Struct,
164            DefKind::Union => Target::Union,
165            DefKind::Trait => Target::Trait,
166            DefKind::TraitAlias => Target::TraitAlias,
167            DefKind::Impl { of_trait } => Target::Impl { of_trait },
168            _ => { ::core::panicking::panic_fmt(format_args!("impossible case reached")); }panic!("impossible case reached"),
169        }
170    }
171
172    pub fn from_ast_item(item: &ast::Item) -> Target {
173        match item.kind {
174            ast::ItemKind::ExternCrate(..) => Target::ExternCrate,
175            ast::ItemKind::Use(..) => Target::Use,
176            ast::ItemKind::Static { .. } => Target::Static,
177            ast::ItemKind::Const(..) => Target::Const,
178            ast::ItemKind::ConstBlock(..) => Target::Const,
179            ast::ItemKind::Fn { .. } => Target::Fn,
180            ast::ItemKind::Mod(..) => Target::Mod,
181            ast::ItemKind::ForeignMod { .. } => Target::ForeignMod,
182            ast::ItemKind::GlobalAsm { .. } => Target::GlobalAsm,
183            ast::ItemKind::TyAlias(..) => Target::TyAlias,
184            ast::ItemKind::Enum(..) => Target::Enum,
185            ast::ItemKind::Struct(..) => Target::Struct,
186            ast::ItemKind::Union(..) => Target::Union,
187            ast::ItemKind::Trait(..) => Target::Trait,
188            ast::ItemKind::TraitAlias(..) => Target::TraitAlias,
189            ast::ItemKind::Impl(ref i) => Target::Impl { of_trait: i.of_trait.is_some() },
190            ast::ItemKind::MacCall(..) => Target::MacroCall,
191            ast::ItemKind::MacroDef(..) => Target::MacroDef,
192            ast::ItemKind::Delegation(..) => Target::Delegation { mac: false },
193            ast::ItemKind::DelegationMac(..) => Target::Delegation { mac: true },
194        }
195    }
196
197    pub fn from_foreign_item_kind(kind: &ast::ForeignItemKind) -> Target {
198        match kind {
199            ForeignItemKind::Static(_) => Target::ForeignStatic,
200            ForeignItemKind::Fn(_) => Target::ForeignFn,
201            ForeignItemKind::TyAlias(_) => Target::ForeignTy,
202            ForeignItemKind::MacCall(_) => Target::MacroCall,
203        }
204    }
205
206    pub fn from_trait_item(trait_item: &TraitItem<'_>) -> Target {
207        match trait_item.kind {
208            TraitItemKind::Const(..) => Target::AssocConst,
209            TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => {
210                Target::Method(MethodKind::Trait { body: false })
211            }
212            TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
213                Target::Method(MethodKind::Trait { body: true })
214            }
215            TraitItemKind::Type(..) => Target::AssocTy,
216        }
217    }
218
219    pub fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target {
220        match foreign_item.kind {
221            hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
222            hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
223            hir::ForeignItemKind::Type => Target::ForeignTy,
224        }
225    }
226
227    pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
228        match generic_param.kind {
229            hir::GenericParamKind::Type { default, .. } => Target::GenericParam {
230                kind: GenericParamKind::Type,
231                has_default: default.is_some(),
232            },
233            hir::GenericParamKind::Lifetime { .. } => {
234                Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }
235            }
236            hir::GenericParamKind::Const { default, .. } => Target::GenericParam {
237                kind: GenericParamKind::Const,
238                has_default: default.is_some(),
239            },
240        }
241    }
242
243    pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, assoc_ctxt: AssocCtxt) -> Target {
244        match kind {
245            AssocItemKind::Const(_) => Target::AssocConst,
246            AssocItemKind::Fn(f) => Target::Method(match assoc_ctxt {
247                AssocCtxt::Trait => MethodKind::Trait { body: f.body.is_some() },
248                AssocCtxt::Impl { of_trait, .. } => {
249                    if of_trait {
250                        MethodKind::TraitImpl
251                    } else {
252                        MethodKind::Inherent
253                    }
254                }
255            }),
256            AssocItemKind::Type(_) => Target::AssocTy,
257            AssocItemKind::Delegation(_) => Target::Delegation { mac: false },
258            AssocItemKind::DelegationMac(_) => Target::Delegation { mac: true },
259            AssocItemKind::MacCall(_) => Target::MacroCall,
260        }
261    }
262
263    pub fn from_expr(expr: &ast::Expr) -> Self {
264        match &expr.kind {
265            ast::ExprKind::Closure(..) | ast::ExprKind::Gen(..) => Self::Closure,
266            ast::ExprKind::Paren(e) => Self::from_expr(&e),
267            ast::ExprKind::ForLoop { .. } => Self::ForLoop,
268            ast::ExprKind::Loop(..) => Self::Loop,
269            ast::ExprKind::While(..) => Self::While,
270            ast::ExprKind::Break(..) => Self::Break,
271            _ => Self::Expression,
272        }
273    }
274
275    pub fn name(self) -> &'static str {
276        match self {
277            Target::ExternCrate => "extern crate",
278            Target::Use => "use",
279            Target::Static => "static",
280            Target::Const => "constant",
281            Target::Fn => "function",
282            Target::Closure => "closure",
283            Target::Mod => "module",
284            Target::ForeignMod => "foreign module",
285            Target::GlobalAsm => "global asm",
286            Target::TyAlias => "type alias",
287            Target::Enum => "enum",
288            Target::Variant => "enum variant",
289            Target::Struct => "struct",
290            Target::Field => "struct field",
291            Target::Union => "union",
292            Target::Trait => "trait",
293            Target::TraitAlias => "trait alias",
294            Target::Impl { .. } => "implementation block",
295            Target::Expression => "expression",
296            Target::Statement => "statement",
297            Target::Arm => "match arm",
298            Target::AssocConst => "associated const",
299            Target::Method(kind) => match kind {
300                MethodKind::Inherent => "inherent method",
301                MethodKind::Trait { body: false } => "required trait method",
302                MethodKind::Trait { body: true } => "provided trait method",
303                MethodKind::TraitImpl => "trait method in an impl block",
304            },
305            Target::AssocTy => "associated type",
306            Target::ForeignFn => "foreign function",
307            Target::ForeignStatic => "foreign static item",
308            Target::ForeignTy => "foreign type",
309            Target::GenericParam { kind, .. } => match kind {
310                GenericParamKind::Type => "type parameter",
311                GenericParamKind::Lifetime => "lifetime parameter",
312                GenericParamKind::Const => "const parameter",
313            },
314            Target::MacroDef => "macro def",
315            Target::Param => "function param",
316            Target::PatField => "pattern field",
317            Target::ExprField => "struct field",
318            Target::WherePredicate => "where predicate",
319            Target::MacroCall => "macro call",
320            Target::Crate => "crate",
321            Target::Delegation { .. } => "delegation",
322            Target::Loop => "loop",
323            Target::ForLoop => "for loop",
324            Target::While => "while loop",
325            Target::Break => "break expression",
326        }
327    }
328
329    pub fn plural_name(self) -> &'static str {
330        match self {
331            Target::ExternCrate => "extern crates",
332            Target::Use => "use statements",
333            Target::Static => "statics",
334            Target::Const => "constants",
335            Target::Fn => "functions",
336            Target::Closure => "closures",
337            Target::Mod => "modules",
338            Target::ForeignMod => "foreign modules",
339            Target::GlobalAsm => "global asms",
340            Target::TyAlias => "type aliases",
341            Target::Enum => "enums",
342            Target::Variant => "enum variants",
343            Target::Struct => "structs",
344            Target::Field => "struct fields",
345            Target::Union => "unions",
346            Target::Trait => "traits",
347            Target::TraitAlias => "trait aliases",
348            Target::Impl { of_trait: false } => "inherent impl blocks",
349            Target::Impl { of_trait: true } => "trait impl blocks",
350            Target::Expression => "expressions",
351            Target::Statement => "statements",
352            Target::Arm => "match arms",
353            Target::AssocConst => "associated consts",
354            Target::Method(kind) => match kind {
355                MethodKind::Inherent => "inherent methods",
356                MethodKind::Trait { body: false } => "required trait methods",
357                MethodKind::Trait { body: true } => "provided trait methods",
358                MethodKind::TraitImpl => "trait methods in impl blocks",
359            },
360            Target::AssocTy => "associated types",
361            Target::ForeignFn => "foreign functions",
362            Target::ForeignStatic => "foreign statics",
363            Target::ForeignTy => "foreign types",
364            Target::GenericParam { kind, has_default: _ } => match kind {
365                GenericParamKind::Type => "type parameters",
366                GenericParamKind::Lifetime => "lifetime parameters",
367                GenericParamKind::Const => "const parameters",
368            },
369            Target::MacroDef => "macro defs",
370            Target::Param => "function params",
371            Target::PatField => "pattern fields",
372            Target::ExprField => "struct fields",
373            Target::WherePredicate => "where predicates",
374            Target::MacroCall => "macro calls",
375            Target::Crate => "crates",
376            Target::Delegation { .. } => "delegations",
377            Target::ForLoop => "for loops",
378            Target::Loop => "loops",
379            Target::While => "while loops",
380            Target::Break => "break expressions",
381        }
382    }
383}