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