From 114a1b878e95c20490af574550ea0825b7a8f9d1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Sep 2019 00:34:52 +0300 Subject: rename AdtDef -> Adt --- crates/ra_hir/src/code_model.rs | 29 +++++++++++++++-------------- crates/ra_hir/src/expr/validation.rs | 6 +++--- crates/ra_hir/src/generics.rs | 18 +++++++++--------- crates/ra_hir/src/lang_item.rs | 8 +++----- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/nameres.rs | 6 +++--- crates/ra_hir/src/nameres/collector.rs | 6 +++--- crates/ra_hir/src/resolve.rs | 6 +++--- crates/ra_hir/src/ty.rs | 12 ++++++------ crates/ra_hir/src/ty/infer.rs | 14 +++++++------- crates/ra_hir/src/ty/lower.rs | 24 +++++++++++------------- 11 files changed, 64 insertions(+), 67 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a10e795ce..c1938bd86 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -127,7 +127,7 @@ impl BuiltinType { pub enum ModuleDef { Module(Module), Function(Function), - AdtDef(AdtDef), + Adt(Adt), // Can't be directly declared, but can be imported. EnumVariant(EnumVariant), Const(Const), @@ -139,7 +139,7 @@ pub enum ModuleDef { impl_froms!( ModuleDef: Module, Function, - AdtDef(Struct, Enum, Union), + Adt(Struct, Enum, Union), EnumVariant, Const, Static, @@ -496,37 +496,38 @@ impl EnumVariant { } } +/// A Data Type #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum AdtDef { +pub enum Adt { Struct(Struct), Union(Union), Enum(Enum), } -impl_froms!(AdtDef: Struct, Union, Enum); +impl_froms!(Adt: Struct, Union, Enum); -impl AdtDef { +impl Adt { pub fn ty(self, db: &impl HirDatabase) -> Ty { match self { - AdtDef::Struct(it) => it.ty(db), - AdtDef::Union(it) => it.ty(db), - AdtDef::Enum(it) => it.ty(db), + Adt::Struct(it) => it.ty(db), + Adt::Union(it) => it.ty(db), + Adt::Enum(it) => it.ty(db), } } pub(crate) fn krate(self, db: &impl HirDatabase) -> Option { match self { - AdtDef::Struct(s) => s.module(db), - AdtDef::Union(s) => s.module(db), - AdtDef::Enum(e) => e.module(db), + Adt::Struct(s) => s.module(db), + Adt::Union(s) => s.module(db), + Adt::Enum(e) => e.module(db), } .krate(db) } pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { match self { - AdtDef::Struct(it) => it.resolver(db), - AdtDef::Union(it) => it.resolver(db), - AdtDef::Enum(it) => it.resolver(db), + Adt::Struct(it) => it.resolver(db), + Adt::Union(it) => it.resolver(db), + Adt::Enum(it) => it.resolver(db), } } } diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 447b9264a..030ec53a2 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -10,7 +10,7 @@ use crate::{ name, path::{PathKind, PathSegment}, ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, - AdtDef, Function, Name, Path, + Adt, Function, Name, Path, }; use super::{Expr, ExprId, RecordLitField}; @@ -58,7 +58,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { } let struct_def = match self.infer[id].as_adt() { - Some((AdtDef::Struct(s), _)) => s, + Some((Adt::Struct(s), _)) => s, _ => return, }; @@ -123,7 +123,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { _ => return, }; - let std_result_ctor = TypeCtor::Adt(AdtDef::Enum(std_result_enum)); + let std_result_ctor = TypeCtor::Adt(Adt::Enum(std_result_enum)); let params = match &mismatch.expected { Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, _ => return, diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 74435c20a..77fb76bfc 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -12,8 +12,8 @@ use crate::{ name::SELF_TYPE, path::Path, type_ref::{TypeBound, TypeRef}, - AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, - Trait, TypeAlias, Union, + Adt, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, + TypeAlias, Union, }; /// Data about a generic parameter (to a function, struct, impl, ...). @@ -47,7 +47,7 @@ pub struct WherePredicate { #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum GenericDef { Function(Function), - AdtDef(AdtDef), + Adt(Adt), Trait(Trait), TypeAlias(TypeAlias), ImplBlock(ImplBlock), @@ -57,7 +57,7 @@ pub enum GenericDef { } impl_froms!( GenericDef: Function, - AdtDef(Struct, Enum, Union), + Adt(Struct, Enum, Union), Trait, TypeAlias, ImplBlock, @@ -74,7 +74,7 @@ impl GenericParams { GenericDef::Function(it) => it.container(db).map(GenericDef::from), GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), - GenericDef::AdtDef(_) | GenericDef::Trait(_) => None, + GenericDef::Adt(_) | GenericDef::Trait(_) => None, GenericDef::ImplBlock(_) => None, }; generics.parent_params = parent.map(|p| db.generic_params(p)); @@ -82,9 +82,9 @@ impl GenericParams { // FIXME: add `: Sized` bound for everything except for `Self` in traits match def { GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), - GenericDef::AdtDef(AdtDef::Struct(it)) => generics.fill(&it.source(db).ast, start), - GenericDef::AdtDef(AdtDef::Union(it)) => generics.fill(&it.source(db).ast, start), - GenericDef::AdtDef(AdtDef::Enum(it)) => generics.fill(&it.source(db).ast, start), + GenericDef::Adt(Adt::Struct(it)) => generics.fill(&it.source(db).ast, start), + GenericDef::Adt(Adt::Union(it)) => generics.fill(&it.source(db).ast, start), + GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), GenericDef::Trait(it) => { // traits get the Self type as an implicit first type parameter generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); @@ -188,7 +188,7 @@ impl GenericDef { pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { match self { GenericDef::Function(inner) => inner.resolver(db), - GenericDef::AdtDef(adt) => adt.resolver(db), + GenericDef::Adt(adt) => adt.resolver(db), GenericDef::Trait(inner) => inner.resolver(db), GenericDef::TypeAlias(inner) => inner.resolver(db), GenericDef::ImplBlock(inner) => inner.resolver(db), diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 87484d892..e3b71cec3 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs @@ -5,7 +5,7 @@ use ra_syntax::{ast::AttrsOwner, SmolStr}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - AdtDef, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, + Adt, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -107,10 +107,8 @@ impl LangItems { ModuleDef::Trait(trait_) => { self.collect_lang_item(db, trait_, LangItemTarget::Trait) } - ModuleDef::AdtDef(AdtDef::Enum(e)) => { - self.collect_lang_item(db, e, LangItemTarget::Enum) - } - ModuleDef::AdtDef(AdtDef::Struct(s)) => { + ModuleDef::Adt(Adt::Enum(e)) => self.collect_lang_item(db, e, LangItemTarget::Enum), + ModuleDef::Adt(Adt::Struct(s)) => { self.collect_lang_item(db, s, LangItemTarget::Struct) } ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 639e97c3d..508da3623 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -85,7 +85,7 @@ pub use self::{ pub use self::code_model::{ docs::{DocDef, Docs, Documentation}, src::{HasBodySource, HasSource, Source}, - AdtDef, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, + Adt, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 1efaad4bc..3a3bf6b5f 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -69,8 +69,8 @@ use crate::{ diagnostics::DiagnosticSink, ids::MacroDefId, nameres::diagnostics::DefDiagnostic, - AdtDef, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, - PathKind, Trait, + Adt, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, + Trait, }; pub(crate) use self::raw::{ImportSourceMap, RawItems}; @@ -426,7 +426,7 @@ impl CrateDefMap { } } } - ModuleDef::AdtDef(AdtDef::Enum(e)) => { + ModuleDef::Adt(Adt::Enum(e)) => { // enum variant tested_by!(can_import_enum_variant); match e.variant(db, &segment.name) { diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index ced1ebf1e..7d2f313c1 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -13,8 +13,8 @@ use crate::{ raw, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, - AdtDef, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, - Static, Struct, Trait, TypeAlias, Union, + Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, + Struct, Trait, TypeAlias, Union, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -314,7 +314,7 @@ where .push((module_id, import_id)); } } - Some(ModuleDef::AdtDef(AdtDef::Enum(e))) => { + Some(ModuleDef::Adt(Adt::Enum(e))) => { tested_by!(glob_enum); // glob import from enum => just import all the variants let variants = e.variants(self.db); diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 251945112..a77a9aeb1 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -15,7 +15,7 @@ use crate::{ name::{Name, SELF_PARAM, SELF_TYPE}, nameres::{CrateDefMap, CrateModuleId, PerNs}, path::Path, - AdtDef, Enum, MacroDef, ModuleDef, Struct, Trait, + Adt, Enum, MacroDef, ModuleDef, Struct, Trait, }; #[derive(Debug, Clone, Default)] @@ -143,7 +143,7 @@ impl Resolver { ) -> Option { let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; match res { - Resolution::Def(ModuleDef::AdtDef(AdtDef::Struct(it))) => Some(it), + Resolution::Def(ModuleDef::Adt(Adt::Struct(it))) => Some(it), _ => None, } } @@ -152,7 +152,7 @@ impl Resolver { pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option { let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; match res { - Resolution::Def(ModuleDef::AdtDef(AdtDef::Enum(it))) => Some(it), + Resolution::Def(ModuleDef::Adt(Adt::Enum(it))) => Some(it), _ => None, } } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index a3df08827..375850b92 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -16,7 +16,7 @@ use std::ops::Deref; use std::sync::Arc; use std::{fmt, mem}; -use crate::{db::HirDatabase, type_ref::Mutability, AdtDef, GenericParams, Name, Trait, TypeAlias}; +use crate::{db::HirDatabase, type_ref::Mutability, Adt, GenericParams, Name, Trait, TypeAlias}; use display::{HirDisplay, HirFormatter}; pub(crate) use autoderef::autoderef; @@ -47,7 +47,7 @@ pub enum TypeCtor { Float(primitive::UncertainFloatTy), /// Structures, enumerations and unions. - Adt(AdtDef), + Adt(Adt), /// The pointee of a string slice. Written as `str`. Str, @@ -458,7 +458,7 @@ impl Ty { } } - pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> { + pub fn as_adt(&self) -> Option<(Adt, &Substs)> { match self { Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => { Some((*adt_def, parameters)) @@ -726,9 +726,9 @@ impl HirDisplay for ApplicationTy { } TypeCtor::Adt(def_id) => { let name = match def_id { - AdtDef::Struct(s) => s.name(f.db), - AdtDef::Union(u) => u.name(f.db), - AdtDef::Enum(e) => e.name(f.db), + Adt::Struct(s) => s.name(f.db), + Adt::Union(u) => u.name(f.db), + Adt::Enum(e) => e.name(f.db), } .unwrap_or_else(Name::missing); write!(f, "{}", name)?; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 725eec834..540a99b15 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -48,7 +48,7 @@ use crate::{ resolve::{Resolution, Resolver}, ty::infer::diagnostics::InferenceDiagnostic, type_ref::{Mutability, TypeRef}, - AdtDef, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path, + Adt, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path, StructField, }; @@ -668,7 +668,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // FIXME remove the duplication between here and `Ty::from_path`? let substs = Ty::substs_from_path(self.db, resolver, path, def); match def { - TypableDef::AdtDef(AdtDef::Struct(s)) => { + TypableDef::Adt(Adt::Struct(s)) => { let ty = s.ty(self.db); let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(s.into())) @@ -678,8 +678,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(var.into())) } - TypableDef::AdtDef(AdtDef::Enum(_)) - | TypableDef::AdtDef(AdtDef::Union(_)) + TypableDef::Adt(Adt::Enum(_)) + | TypableDef::Adt(Adt::Union(_)) | TypableDef::TypeAlias(_) | TypableDef::Function(_) | TypableDef::Const(_) @@ -1185,7 +1185,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let i = name.to_string().parse::().ok(); i.and_then(|i| a_ty.parameters.0.get(i).cloned()) } - TypeCtor::Adt(AdtDef::Struct(s)) => s.field(self.db, name).map(|field| { + TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| { self.write_field_resolution(tgt_expr, field); field.ty(self.db).subst(&a_ty.parameters) }), @@ -1489,7 +1489,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { trait_.associated_type_by_name(self.db, &name::OUTPUT) } - fn resolve_boxed_box(&self) -> Option { + fn resolve_boxed_box(&self) -> Option { let boxed_box_path = Path { kind: PathKind::Abs, segments: vec![ @@ -1499,7 +1499,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ], }; let struct_ = self.resolver.resolve_known_struct(self.db, &boxed_box_path)?; - Some(AdtDef::Struct(struct_)) + Some(Adt::Struct(struct_)) } } diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 105c893f0..946e9e9fb 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -20,7 +20,7 @@ use crate::{ nameres::Namespace, path::{GenericArg, PathSegment}, resolve::{Resolution, Resolver}, - ty::AdtDef, + ty::Adt, type_ref::{TypeBound, TypeRef}, BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, TypeAlias, Union, @@ -172,7 +172,7 @@ impl Ty { ) -> Substs { let def_generic: Option = match resolved { TypableDef::Function(func) => Some(func.into()), - TypableDef::AdtDef(adt) => Some(adt.into()), + TypableDef::Adt(adt) => Some(adt.into()), TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), TypableDef::TypeAlias(t) => Some(t.into()), TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, @@ -191,7 +191,7 @@ impl Ty { let last = path.segments.last().expect("path should have at least one segment"); let segment = match resolved { TypableDef::Function(_) - | TypableDef::AdtDef(_) + | TypableDef::Adt(_) | TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::TypeAlias(_) @@ -406,10 +406,8 @@ fn assoc_type_bindings_from_type_bound<'a>( pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty { match (def, ns) { (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f), - (TypableDef::AdtDef(AdtDef::Struct(s)), Namespace::Values) => { - type_for_struct_constructor(db, s) - } - (TypableDef::AdtDef(adt), Namespace::Types) => type_for_adt(db, adt), + (TypableDef::Adt(Adt::Struct(s)), Namespace::Values) => type_for_struct_constructor(db, s), + (TypableDef::Adt(adt), Namespace::Types) => type_for_adt(db, adt), (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), @@ -418,8 +416,8 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace // 'error' cases: (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, - (TypableDef::AdtDef(AdtDef::Union(_)), Namespace::Values) => Ty::Unknown, - (TypableDef::AdtDef(AdtDef::Enum(_)), Namespace::Values) => Ty::Unknown, + (TypableDef::Adt(Adt::Union(_)), Namespace::Values) => Ty::Unknown, + (TypableDef::Adt(Adt::Enum(_)), Namespace::Values) => Ty::Unknown, (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, @@ -587,7 +585,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> Ty::apply(TypeCtor::FnDef(def.into()), substs) } -fn type_for_adt(db: &impl HirDatabase, adt: impl Into + HasGenericParams) -> Ty { +fn type_for_adt(db: &impl HirDatabase, adt: impl Into + HasGenericParams) -> Ty { let generics = adt.generic_params(db); Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) } @@ -604,7 +602,7 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum TypableDef { Function(Function), - AdtDef(AdtDef), + Adt(Adt), EnumVariant(EnumVariant), TypeAlias(TypeAlias), Const(Const), @@ -613,7 +611,7 @@ pub enum TypableDef { } impl_froms!( TypableDef: Function, - AdtDef(Struct, Enum, Union), + Adt(Struct, Enum, Union), EnumVariant, TypeAlias, Const, @@ -625,7 +623,7 @@ impl From for Option { fn from(def: ModuleDef) -> Option { let res = match def { ModuleDef::Function(f) => f.into(), - ModuleDef::AdtDef(adt) => adt.into(), + ModuleDef::Adt(adt) => adt.into(), ModuleDef::EnumVariant(v) => v.into(), ModuleDef::TypeAlias(t) => t.into(), ModuleDef::Const(v) => v.into(), -- cgit v1.2.3