mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
generalize impl_froms to nested enums
This commit is contained in:
parent
45117c6388
commit
bcf30d389c
4 changed files with 26 additions and 58 deletions
|
@ -139,7 +139,7 @@ pub enum ModuleDef {
|
||||||
impl_froms!(
|
impl_froms!(
|
||||||
ModuleDef: Module,
|
ModuleDef: Module,
|
||||||
Function,
|
Function,
|
||||||
AdtDef,
|
AdtDef(Struct, Enum, Union),
|
||||||
EnumVariant,
|
EnumVariant,
|
||||||
Const,
|
Const,
|
||||||
Static,
|
Static,
|
||||||
|
@ -148,24 +148,6 @@ impl_froms!(
|
||||||
BuiltinType
|
BuiltinType
|
||||||
);
|
);
|
||||||
|
|
||||||
impl From<Struct> for ModuleDef {
|
|
||||||
fn from(it: Struct) -> ModuleDef {
|
|
||||||
ModuleDef::AdtDef(AdtDef::Struct(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Enum> for ModuleDef {
|
|
||||||
fn from(it: Enum) -> ModuleDef {
|
|
||||||
ModuleDef::AdtDef(AdtDef::Enum(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Union> for ModuleDef {
|
|
||||||
fn from(it: Union) -> ModuleDef {
|
|
||||||
ModuleDef::AdtDef(AdtDef::Union(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ModuleSource {
|
pub enum ModuleSource {
|
||||||
SourceFile(ast::SourceFile),
|
SourceFile(ast::SourceFile),
|
||||||
Module(ast::Module),
|
Module(ast::Module),
|
||||||
|
|
|
@ -55,25 +55,14 @@ pub enum GenericDef {
|
||||||
// can, and this makes some code easier to write
|
// can, and this makes some code easier to write
|
||||||
EnumVariant(EnumVariant),
|
EnumVariant(EnumVariant),
|
||||||
}
|
}
|
||||||
impl_froms!(GenericDef: Function, AdtDef, Trait, TypeAlias, ImplBlock, EnumVariant);
|
impl_froms!(
|
||||||
|
GenericDef: Function,
|
||||||
impl From<Struct> for GenericDef {
|
AdtDef(Struct, Enum, Union),
|
||||||
fn from(it: Struct) -> GenericDef {
|
Trait,
|
||||||
GenericDef::AdtDef(AdtDef::Struct(it))
|
TypeAlias,
|
||||||
}
|
ImplBlock,
|
||||||
}
|
EnumVariant
|
||||||
|
);
|
||||||
impl From<Enum> for GenericDef {
|
|
||||||
fn from(it: Enum) -> GenericDef {
|
|
||||||
GenericDef::AdtDef(AdtDef::Enum(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Union> for GenericDef {
|
|
||||||
fn from(it: Union) -> GenericDef {
|
|
||||||
GenericDef::AdtDef(AdtDef::Union(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GenericParams {
|
impl GenericParams {
|
||||||
pub(crate) fn generic_params_query(
|
pub(crate) fn generic_params_query(
|
||||||
|
|
|
@ -8,13 +8,20 @@
|
||||||
//! applied. So, the relation between syntax and HIR is many-to-one.
|
//! applied. So, the relation between syntax and HIR is many-to-one.
|
||||||
|
|
||||||
macro_rules! impl_froms {
|
macro_rules! impl_froms {
|
||||||
($e:ident: $($v:ident),*) => {
|
($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
|
||||||
$(
|
$(
|
||||||
impl From<$v> for $e {
|
impl From<$v> for $e {
|
||||||
fn from(it: $v) -> $e {
|
fn from(it: $v) -> $e {
|
||||||
$e::$v(it)
|
$e::$v(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$($(
|
||||||
|
impl From<$sv> for $e {
|
||||||
|
fn from(it: $sv) -> $e {
|
||||||
|
$e::$v($v::$sv(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*)?
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,25 +611,15 @@ pub enum TypableDef {
|
||||||
Static(Static),
|
Static(Static),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
}
|
}
|
||||||
impl_froms!(TypableDef: Function, AdtDef, EnumVariant, TypeAlias, Const, Static, BuiltinType);
|
impl_froms!(
|
||||||
|
TypableDef: Function,
|
||||||
impl From<Struct> for TypableDef {
|
AdtDef(Struct, Enum, Union),
|
||||||
fn from(it: Struct) -> TypableDef {
|
EnumVariant,
|
||||||
TypableDef::AdtDef(AdtDef::Struct(it))
|
TypeAlias,
|
||||||
}
|
Const,
|
||||||
}
|
Static,
|
||||||
|
BuiltinType
|
||||||
impl From<Enum> for TypableDef {
|
);
|
||||||
fn from(it: Enum) -> TypableDef {
|
|
||||||
TypableDef::AdtDef(AdtDef::Enum(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Union> for TypableDef {
|
|
||||||
fn from(it: Union) -> TypableDef {
|
|
||||||
TypableDef::AdtDef(AdtDef::Union(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ModuleDef> for Option<TypableDef> {
|
impl From<ModuleDef> for Option<TypableDef> {
|
||||||
fn from(def: ModuleDef) -> Option<TypableDef> {
|
fn from(def: ModuleDef) -> Option<TypableDef> {
|
||||||
|
|
Loading…
Reference in a new issue