mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
move adt to adt
This commit is contained in:
parent
a03c109f50
commit
31d3a56b18
3 changed files with 23 additions and 24 deletions
|
@ -3,17 +3,32 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_syntax::{
|
use ra_syntax::ast::{self, NameOwner, StructFlavor};
|
||||||
ast::{self, NameOwner, StructFlavor}
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Name, AsName, Struct, Enum, EnumVariant,
|
Name, AsName, Struct, Enum, EnumVariant, Crate,
|
||||||
HirDatabase,
|
HirDatabase,
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
ids::LocationCtx,
|
ids::LocationCtx,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum AdtDef {
|
||||||
|
Struct(Struct),
|
||||||
|
Enum(Enum),
|
||||||
|
}
|
||||||
|
impl_froms!(AdtDef: Struct, Enum);
|
||||||
|
|
||||||
|
impl AdtDef {
|
||||||
|
pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
|
||||||
|
match self {
|
||||||
|
AdtDef::Struct(s) => s.module(db),
|
||||||
|
AdtDef::Enum(e) => e.module(db),
|
||||||
|
}
|
||||||
|
.krate(db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Struct {
|
impl Struct {
|
||||||
pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
|
pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
|
||||||
db.struct_data((*self).into()).variant_data.clone()
|
db.struct_data((*self).into()).variant_data.clone()
|
||||||
|
|
|
@ -55,10 +55,11 @@ pub use self::{
|
||||||
ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
|
ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
|
||||||
macros::{MacroDef, MacroInput, MacroExpansion},
|
macros::{MacroDef, MacroInput, MacroExpansion},
|
||||||
nameres::{ItemMap, PerNs, Namespace, Resolution},
|
nameres::{ItemMap, PerNs, Namespace, Resolution},
|
||||||
ty::{Ty, AdtDef},
|
ty::Ty,
|
||||||
impl_block::{ImplBlock, ImplItem},
|
impl_block::{ImplBlock, ImplItem},
|
||||||
code_model_impl::function::{FnScopes, ScopesWithSyntaxMapping},
|
code_model_impl::function::{FnScopes, ScopesWithSyntaxMapping},
|
||||||
docs::{Docs, Documentation}
|
docs::{Docs, Documentation},
|
||||||
|
adt::AdtDef,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::code_model_api::{
|
pub use self::code_model_api::{
|
||||||
|
|
|
@ -31,7 +31,7 @@ use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock,
|
Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock,
|
||||||
FnSignature, FnScopes, ModuleDef, Crate,
|
FnSignature, FnScopes, ModuleDef, AdtDef,
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
type_ref::{TypeRef, Mutability},
|
type_ref::{TypeRef, Mutability},
|
||||||
name::KnownName,
|
name::KnownName,
|
||||||
|
@ -162,23 +162,6 @@ impl Substs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum AdtDef {
|
|
||||||
Struct(Struct),
|
|
||||||
Enum(Enum),
|
|
||||||
}
|
|
||||||
impl_froms!(AdtDef: Struct, Enum);
|
|
||||||
|
|
||||||
impl AdtDef {
|
|
||||||
fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
|
|
||||||
match self {
|
|
||||||
AdtDef::Struct(s) => s.module(db),
|
|
||||||
AdtDef::Enum(e) => e.module(db),
|
|
||||||
}
|
|
||||||
.krate(db)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A type. This is based on the `TyKind` enum in rustc (librustc/ty/sty.rs).
|
/// A type. This is based on the `TyKind` enum in rustc (librustc/ty/sty.rs).
|
||||||
///
|
///
|
||||||
/// This should be cheap to clone.
|
/// This should be cheap to clone.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue