894: Rename Type => TypeAlias r=matklad a=flodiebold



Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2019-02-24 20:39:27 +00:00
commit dfca3cbeb0
12 changed files with 57 additions and 43 deletions

View File

@ -85,9 +85,19 @@ pub enum ModuleDef {
Const(Const),
Static(Static),
Trait(Trait),
Type(Type),
TypeAlias(TypeAlias),
}
impl_froms!(ModuleDef: Module, Function, Struct, Enum, EnumVariant, Const, Static, Trait, Type);
impl_froms!(
ModuleDef: Module,
Function,
Struct,
Enum,
EnumVariant,
Const,
Static,
Trait,
TypeAlias
);
pub enum ModuleSource {
SourceFile(TreeArc<ast::SourceFile>),
@ -604,11 +614,11 @@ fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Type {
pub struct TypeAlias {
pub(crate) id: TypeId,
}
impl Type {
impl TypeAlias {
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
self.id.source(db)
}
@ -645,7 +655,7 @@ pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
}
}
impl Docs for Type {
impl Docs for TypeAlias {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}

View File

@ -6,7 +6,7 @@
use crate::{
MacroCallId, HirFileId,
SourceFileItems, SourceItemId, Crate, Module, HirInterner,
Function, FnSignature, ExprScopes,
Function, FnSignature, ExprScopes, TypeAlias,
Struct, Enum, StructField,
macros::MacroExpansion,
module_tree::ModuleTree,
@ -15,7 +15,9 @@
adt::{StructData, EnumData},
impl_block::{ModuleImplBlocks, ImplSourceMap},
generics::{GenericParams, GenericDef},
ids::SourceFileItemId, nameres::Namespace, type_ref::TypeRef, code_model_api::Type
ids::SourceFileItemId,
nameres::Namespace,
type_ref::TypeRef,
};
#[salsa::query_group(PersistentHirDatabaseStorage)]
@ -79,7 +81,7 @@ fn impls_in_module_with_source_map(
fn fn_signature(&self, func: Function) -> Arc<FnSignature>;
#[salsa::invoke(crate::type_alias::type_alias_ref_query)]
fn type_alias_ref(&self, typ: Type) -> Arc<TypeRef>;
fn type_alias_ref(&self, typ: TypeAlias) -> Arc<TypeRef>;
}
#[salsa::query_group(HirDatabaseStorage)]

View File

@ -7,7 +7,10 @@
use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock};
use crate::{
db::PersistentHirDatabase,
Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock
};
/// Data about a generic parameter (to a function, struct, impl, ...).
#[derive(Clone, PartialEq, Eq, Debug)]
@ -30,10 +33,10 @@ pub enum GenericDef {
Struct(Struct),
Enum(Enum),
Trait(Trait),
Type(Type),
TypeAlias(TypeAlias),
ImplBlock(ImplBlock),
}
impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock);
impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock);
impl GenericParams {
pub(crate) fn generic_params_query(
@ -43,7 +46,7 @@ pub(crate) fn generic_params_query(
let mut generics = GenericParams::default();
let parent = match def {
GenericDef::Function(it) => it.impl_block(db),
GenericDef::Type(it) => it.impl_block(db),
GenericDef::TypeAlias(it) => it.impl_block(db),
GenericDef::Struct(_) | GenericDef::Enum(_) | GenericDef::Trait(_) => None,
GenericDef::ImplBlock(_) => None,
};
@ -54,7 +57,7 @@ pub(crate) fn generic_params_query(
GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start),
GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
GenericDef::Trait(it) => generics.fill(&*it.source(db).1, start),
GenericDef::Type(it) => generics.fill(&*it.source(db).1, start),
GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start),
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
}

View File

@ -7,7 +7,7 @@
ast::{self, AstNode}};
use crate::{
Const, Type, Function, HirFileId,
Const, TypeAlias, Function, HirFileId,
HirDatabase, PersistentHirDatabase,
ModuleDef, Trait, Resolution,
type_ref::TypeRef,
@ -135,13 +135,9 @@ pub(crate) fn from_ast(
item_list
.impl_items()
.map(|item_node| match item_node.kind() {
ast::ImplItemKind::FnDef(it) => {
ImplItem::Method(Function { id: ctx.to_def(it) })
}
ast::ImplItemKind::ConstDef(it) => {
ImplItem::Const(Const { id: ctx.to_def(it) })
}
ast::ImplItemKind::TypeDef(it) => ImplItem::Type(Type { id: ctx.to_def(it) }),
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(it) }.into(),
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(it) }.into(),
ast::ImplItemKind::TypeDef(it) => TypeAlias { id: ctx.to_def(it) }.into(),
})
.collect()
} else {
@ -168,10 +164,10 @@ pub fn items(&self) -> &[ImplItem] {
pub enum ImplItem {
Method(Function),
Const(Const),
Type(Type),
TypeAlias(TypeAlias),
// Existential
}
impl_froms!(ImplItem: Const, Type);
impl_froms!(ImplItem: Const, TypeAlias);
impl From<Function> for ImplItem {
fn from(func: Function) -> ImplItem {

View File

@ -72,5 +72,5 @@ fn from(it: $v) -> $e {
Function, FnSignature,
StructField, FieldSource,
Static, Const,
Trait, Type,
Trait, TypeAlias,
};

View File

@ -10,7 +10,7 @@
use crate::{
SourceItemId, Path, ModuleSource, Name,
HirFileId, MacroCallLoc, AsName, PerNs, Function,
ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type,
ModuleDef, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
ids::LocationCtx, PersistentHirDatabase,
};
@ -169,7 +169,7 @@ fn add_def_id(
}
ast::ModuleItemKind::TypeDef(it) => {
if let Some(name) = it.name() {
let t = Type { id: ctx.to_def(it) };
let t = TypeAlias { id: ctx.to_def(it) };
self.declarations.insert(name.as_name(), PerNs::types(t.into()));
}
}

View File

@ -406,7 +406,7 @@ fn infer_path_expr(&mut self, resolver: &Resolver, path: &Path) -> Option<Ty> {
crate::ImplItem::Const(_) => None,
// TODO: Resolve associated types
crate::ImplItem::Type(_) => None,
crate::ImplItem::TypeAlias(_) => None,
})?;
resolved = Resolution::Def(item.into());
}
@ -477,7 +477,7 @@ fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<VariantDef>) {
let ty = self.insert_type_vars(ty.apply_substs(substs));
(ty, Some(var.into()))
}
TypableDef::Type(_) | TypableDef::Function(_) | TypableDef::Enum(_) => {
TypableDef::TypeAlias(_) | TypableDef::Function(_) | TypableDef::Enum(_) => {
(Ty::Unknown, None)
}
}

View File

@ -10,7 +10,7 @@
use crate::{
Function, Struct, StructField, Enum, EnumVariant, Path, Name,
ModuleDef, Type,
ModuleDef, TypeAlias,
HirDatabase,
type_ref::TypeRef,
name::KnownName,
@ -124,7 +124,7 @@ pub(super) fn substs_from_path_segment(
TypableDef::Struct(s) => s.generic_params(db),
TypableDef::Enum(e) => e.generic_params(db),
TypableDef::EnumVariant(var) => var.parent_enum(db).generic_params(db),
TypableDef::Type(t) => t.generic_params(db),
TypableDef::TypeAlias(t) => t.generic_params(db),
};
let parent_param_count = def_generics.count_parent_params();
substs.extend((0..parent_param_count).map(|_| Ty::Unknown));
@ -163,7 +163,7 @@ pub(super) fn substs_from_path(
TypableDef::Function(_)
| TypableDef::Struct(_)
| TypableDef::Enum(_)
| TypableDef::Type(_) => last,
| TypableDef::TypeAlias(_) => last,
TypableDef::EnumVariant(_) => {
// the generic args for an enum variant may be either specified
// on the segment referring to the enum, or on the segment
@ -196,13 +196,13 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
(TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s),
(TypableDef::Enum(e), Namespace::Types) => type_for_enum(db, e),
(TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
(TypableDef::Type(t), Namespace::Types) => type_for_type_alias(db, t),
(TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
// 'error' cases:
(TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
(TypableDef::Enum(_), Namespace::Values) => Ty::Unknown,
(TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
(TypableDef::Type(_), Namespace::Values) => Ty::Unknown,
(TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
}
}
@ -302,7 +302,7 @@ fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty {
}
}
fn type_for_type_alias(db: &impl HirDatabase, t: Type) -> Ty {
fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
let generics = t.generic_params(db);
let resolver = t.resolver(db);
let type_ref = t.type_ref(db);
@ -317,9 +317,9 @@ pub enum TypableDef {
Struct(Struct),
Enum(Enum),
EnumVariant(EnumVariant),
Type(Type),
TypeAlias(TypeAlias),
}
impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, Type);
impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias);
impl From<ModuleDef> for Option<TypableDef> {
fn from(def: ModuleDef) -> Option<TypableDef> {
@ -328,7 +328,7 @@ fn from(def: ModuleDef) -> Option<TypableDef> {
ModuleDef::Struct(s) => s.into(),
ModuleDef::Enum(e) => e.into(),
ModuleDef::EnumVariant(v) => v.into(),
ModuleDef::Type(t) => t.into(),
ModuleDef::TypeAlias(t) => t.into(),
ModuleDef::Const(_)
| ModuleDef::Static(_)
| ModuleDef::Module(_)

View File

@ -2,9 +2,12 @@
use std::sync::Arc;
use crate::{code_model_api::Type, db::PersistentHirDatabase, type_ref::TypeRef};
use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef};
pub(crate) fn type_alias_ref_query(db: &impl PersistentHirDatabase, typ: Type) -> Arc<TypeRef> {
pub(crate) fn type_alias_ref_query(
db: &impl PersistentHirDatabase,
typ: TypeAlias,
) -> Arc<TypeRef> {
let (_, node) = typ.source(db);
Arc::new(TypeRef::from_ast_opt(node.type_ref()))
}

View File

@ -46,7 +46,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
}
}
hir::ImplItem::Const(ct) => acc.add_const(ctx, ct),
hir::ImplItem::Type(ty) => acc.add_type(ctx, ty),
hir::ImplItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
}
None::<()>
});

View File

@ -65,7 +65,7 @@ pub(crate) fn add_resolution(
Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)),
Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)),
Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)),
Resolution::Def(Type(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
Resolution::Def(TypeAlias(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None),
Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None),
Resolution::SelfType(..) => (
@ -132,7 +132,7 @@ pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const
.add_to(self);
}
pub(crate) fn add_type(&mut self, ctx: &CompletionContext, type_alias: hir::Type) {
pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
let (_file_id, type_def) = type_alias.source(ctx.db);
let name = match type_def.name() {
Some(name) => name,

View File

@ -154,7 +154,7 @@ pub(crate) fn from_def(db: &RootDatabase, module_def: hir::ModuleDef) -> Navigat
let (file_id, node) = e.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
hir::ModuleDef::Type(e) => {
hir::ModuleDef::TypeAlias(e) => {
let (file_id, node) = e.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)
}