Refactor Display
impl for Target
to Target::name
method
This commit is contained in:
parent
e98b0e8ee7
commit
6b37a79581
@ -60,51 +60,7 @@ pub enum Target {
|
||||
|
||||
impl Display for Target {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match *self {
|
||||
Target::ExternCrate => "extern crate",
|
||||
Target::Use => "use",
|
||||
Target::Static => "static item",
|
||||
Target::Const => "constant item",
|
||||
Target::Fn => "function",
|
||||
Target::Closure => "closure",
|
||||
Target::Mod => "module",
|
||||
Target::ForeignMod => "foreign module",
|
||||
Target::GlobalAsm => "global asm",
|
||||
Target::TyAlias => "type alias",
|
||||
Target::OpaqueTy => "opaque type",
|
||||
Target::Enum => "enum",
|
||||
Target::Variant => "enum variant",
|
||||
Target::Struct => "struct",
|
||||
Target::Field => "struct field",
|
||||
Target::Union => "union",
|
||||
Target::Trait => "trait",
|
||||
Target::TraitAlias => "trait alias",
|
||||
Target::Impl => "item",
|
||||
Target::Expression => "expression",
|
||||
Target::Statement => "statement",
|
||||
Target::Arm => "match arm",
|
||||
Target::AssocConst => "associated const",
|
||||
Target::Method(kind) => match kind {
|
||||
MethodKind::Inherent => "inherent method",
|
||||
MethodKind::Trait { body: false } => "required trait method",
|
||||
MethodKind::Trait { body: true } => "provided trait method",
|
||||
},
|
||||
Target::AssocTy => "associated type",
|
||||
Target::ForeignFn => "foreign function",
|
||||
Target::ForeignStatic => "foreign static item",
|
||||
Target::ForeignTy => "foreign type",
|
||||
Target::GenericParam(kind) => match kind {
|
||||
GenericParamKind::Type => "type parameter",
|
||||
GenericParamKind::Lifetime => "lifetime parameter",
|
||||
GenericParamKind::Const => "const parameter",
|
||||
},
|
||||
Target::MacroDef => "macro def",
|
||||
Target::Param => "function param",
|
||||
}
|
||||
)
|
||||
write!(f, "{}", Self::name(&self))
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,4 +141,48 @@ pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
|
||||
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
match *self {
|
||||
Target::ExternCrate => "extern crate",
|
||||
Target::Use => "use",
|
||||
Target::Static => "static item",
|
||||
Target::Const => "constant item",
|
||||
Target::Fn => "function",
|
||||
Target::Closure => "closure",
|
||||
Target::Mod => "module",
|
||||
Target::ForeignMod => "foreign module",
|
||||
Target::GlobalAsm => "global asm",
|
||||
Target::TyAlias => "type alias",
|
||||
Target::OpaqueTy => "opaque type",
|
||||
Target::Enum => "enum",
|
||||
Target::Variant => "enum variant",
|
||||
Target::Struct => "struct",
|
||||
Target::Field => "struct field",
|
||||
Target::Union => "union",
|
||||
Target::Trait => "trait",
|
||||
Target::TraitAlias => "trait alias",
|
||||
Target::Impl => "item",
|
||||
Target::Expression => "expression",
|
||||
Target::Statement => "statement",
|
||||
Target::Arm => "match arm",
|
||||
Target::AssocConst => "associated const",
|
||||
Target::Method(kind) => match kind {
|
||||
MethodKind::Inherent => "inherent method",
|
||||
MethodKind::Trait { body: false } => "required trait method",
|
||||
MethodKind::Trait { body: true } => "provided trait method",
|
||||
},
|
||||
Target::AssocTy => "associated type",
|
||||
Target::ForeignFn => "foreign function",
|
||||
Target::ForeignStatic => "foreign static item",
|
||||
Target::ForeignTy => "foreign type",
|
||||
Target::GenericParam(kind) => match kind {
|
||||
GenericParamKind::Type => "type parameter",
|
||||
GenericParamKind::Lifetime => "lifetime parameter",
|
||||
GenericParamKind::Const => "const parameter",
|
||||
},
|
||||
Target::MacroDef => "macro def",
|
||||
Target::Param => "function param",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user