From f10f5a81b326d161d9ed1fba263de972b89de2bf Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 21 Mar 2019 22:20:03 +0100 Subject: TypeName => TypeCtor --- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/ty.rs | 48 +++++++-------- crates/ra_hir/src/ty/infer.rs | 78 ++++++++++++------------ crates/ra_hir/src/ty/lower.rs | 36 +++++------ crates/ra_hir/src/ty/method_resolution.rs | 6 +- crates/ra_hir/src/ty/op.rs | 20 +++--- crates/ra_ide_api/src/completion/complete_dot.rs | 6 +- 7 files changed, 98 insertions(+), 98 deletions(-) diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 6219402d4..5926b5758 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -53,7 +53,7 @@ pub use self::{ name::Name, ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner}, nameres::{PerNs, Namespace}, - ty::{Ty, ApplicationTy, TypeName, Substs, display::HirDisplay}, + ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay}, impl_block::{ImplBlock, ImplItem}, docs::{Docs, Documentation}, adt::AdtDef, diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 0bb716569..1d9e7b76c 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -21,7 +21,7 @@ pub(crate) use infer::{infer, InferenceResult, InferTy}; use display::{HirDisplay, HirFormatter}; #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub enum TypeName { +pub enum TypeCtor { /// The primitive boolean type. Written as `bool`. Bool, @@ -87,7 +87,7 @@ pub enum TypeName { #[derive(Clone, PartialEq, Eq, Debug)] pub struct ApplicationTy { - pub name: TypeName, + pub name: TypeCtor, pub parameters: Substs, } @@ -191,17 +191,17 @@ impl FnSig { } impl Ty { - pub fn simple(name: TypeName) -> Ty { + pub fn simple(name: TypeCtor) -> Ty { Ty::Apply(ApplicationTy { name, parameters: Substs::empty() }) } - pub fn apply_one(name: TypeName, param: Ty) -> Ty { + pub fn apply_one(name: TypeCtor, param: Ty) -> Ty { Ty::Apply(ApplicationTy { name, parameters: Substs::single(param) }) } - pub fn apply(name: TypeName, parameters: Substs) -> Ty { + pub fn apply(name: TypeCtor, parameters: Substs) -> Ty { Ty::Apply(ApplicationTy { name, parameters }) } pub fn unit() -> Self { - Ty::apply(TypeName::Tuple, Substs::empty()) + Ty::apply(TypeCtor::Tuple, Substs::empty()) } pub fn walk(&self, f: &mut impl FnMut(&Ty)) { @@ -236,7 +236,7 @@ impl Ty { pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { match self { - Ty::Apply(ApplicationTy { name: TypeName::Ref(mutability), parameters }) => { + Ty::Apply(ApplicationTy { name: TypeCtor::Ref(mutability), parameters }) => { Some((parameters.as_single(), *mutability)) } _ => None, @@ -245,7 +245,7 @@ impl Ty { pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> { match self { - Ty::Apply(ApplicationTy { name: TypeName::Adt(adt_def), parameters }) => { + Ty::Apply(ApplicationTy { name: TypeCtor::Adt(adt_def), parameters }) => { Some((*adt_def, parameters)) } _ => None, @@ -254,7 +254,7 @@ impl Ty { pub fn as_tuple(&self) -> Option<&Substs> { match self { - Ty::Apply(ApplicationTy { name: TypeName::Tuple, parameters }) => Some(parameters), + Ty::Apply(ApplicationTy { name: TypeCtor::Tuple, parameters }) => Some(parameters), _ => None, } } @@ -262,8 +262,8 @@ impl Ty { fn builtin_deref(&self) -> Option { match self { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Ref(..) => Some(Ty::clone(a_ty.parameters.as_single())), - TypeName::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())), + TypeCtor::Ref(..) => Some(Ty::clone(a_ty.parameters.as_single())), + TypeCtor::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())), _ => None, }, _ => None, @@ -318,25 +318,25 @@ impl HirDisplay for &Ty { impl HirDisplay for ApplicationTy { fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { match self.name { - TypeName::Bool => write!(f, "bool")?, - TypeName::Char => write!(f, "char")?, - TypeName::Int(t) => write!(f, "{}", t)?, - TypeName::Float(t) => write!(f, "{}", t)?, - TypeName::Str => write!(f, "str")?, - TypeName::Slice | TypeName::Array => { + TypeCtor::Bool => write!(f, "bool")?, + TypeCtor::Char => write!(f, "char")?, + TypeCtor::Int(t) => write!(f, "{}", t)?, + TypeCtor::Float(t) => write!(f, "{}", t)?, + TypeCtor::Str => write!(f, "str")?, + TypeCtor::Slice | TypeCtor::Array => { let t = self.parameters.as_single(); write!(f, "[{}]", t.display(f.db))?; } - TypeName::RawPtr(m) => { + TypeCtor::RawPtr(m) => { let t = self.parameters.as_single(); write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?; } - TypeName::Ref(m) => { + TypeCtor::Ref(m) => { let t = self.parameters.as_single(); write!(f, "&{}{}", m.as_keyword_for_ref(), t.display(f.db))?; } - TypeName::Never => write!(f, "!")?, - TypeName::Tuple => { + TypeCtor::Never => write!(f, "!")?, + TypeCtor::Tuple => { let ts = &self.parameters; if ts.0.len() == 1 { write!(f, "({},)", ts.0[0].display(f.db))?; @@ -346,13 +346,13 @@ impl HirDisplay for ApplicationTy { write!(f, ")")?; } } - TypeName::FnPtr => { + TypeCtor::FnPtr => { let sig = FnSig::from_fn_ptr_substs(&self.parameters); write!(f, "fn(")?; f.write_joined(sig.params(), ", ")?; write!(f, ") -> {}", sig.ret().display(f.db))?; } - TypeName::FnDef(def) => { + TypeCtor::FnDef(def) => { let sig = f.db.callable_item_signature(def); let name = match def { CallableDef::Function(ff) => ff.name(f.db), @@ -372,7 +372,7 @@ impl HirDisplay for ApplicationTy { f.write_joined(sig.params(), ", ")?; write!(f, ") -> {}", sig.ret().display(f.db))?; } - TypeName::Adt(def_id) => { + TypeCtor::Adt(def_id) => { let name = match def_id { AdtDef::Struct(s) => s.name(f.db), AdtDef::Enum(e) => e.name(f.db), diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 0dafd8cbd..e975f9217 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -38,7 +38,7 @@ use crate::{ resolve::{Resolver, Resolution}, nameres::Namespace }; -use super::{Ty, TypableDef, Substs, primitive, op, FnSig, ApplicationTy, TypeName}; +use super::{Ty, TypableDef, Substs, primitive, op, FnSig, ApplicationTy, TypeCtor}; /// The entry point of type inference. pub fn infer(db: &impl HirDatabase, func: Function) -> Arc { @@ -278,11 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { match ty { Ty::Unknown => self.new_type_var(), Ty::Apply(ApplicationTy { - name: TypeName::Int(primitive::UncertainIntTy::Unknown), + name: TypeCtor::Int(primitive::UncertainIntTy::Unknown), .. }) => self.new_integer_var(), Ty::Apply(ApplicationTy { - name: TypeName::Float(primitive::UncertainFloatTy::Unknown), + name: TypeCtor::Float(primitive::UncertainFloatTy::Unknown), .. }) => self.new_float_var(), _ => ty, @@ -629,7 +629,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .collect::>() .into(); - Ty::apply(TypeName::Tuple, Substs(inner_tys)) + Ty::apply(TypeCtor::Tuple, Substs(inner_tys)) } Pat::Ref { pat, mutability } => { let expectation = match expected.as_reference() { @@ -642,7 +642,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => &Ty::Unknown, }; let subty = self.infer_pat(*pat, expectation, default_bm); - Ty::apply_one(TypeName::Ref(*mutability), subty.into()) + Ty::apply_one(TypeCtor::Ref(*mutability), subty.into()) } Pat::TupleStruct { path: ref p, args: ref subpats } => { self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) @@ -670,7 +670,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let bound_ty = match mode { BindingMode::Ref(mutability) => { - Ty::apply_one(TypeName::Ref(mutability), inner_ty.clone().into()) + Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone().into()) } BindingMode::Move => inner_ty.clone(), }; @@ -725,7 +725,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::Missing => Ty::Unknown, Expr::If { condition, then_branch, else_branch } => { // if let is desugared to match, so this is always simple if - self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeName::Bool))); + self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeCtor::Bool))); let then_ty = self.infer_expr(*then_branch, expected); match else_branch { Some(else_branch) => { @@ -742,11 +742,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::Loop { body } => { self.infer_expr(*body, &Expectation::has_type(Ty::unit())); // TODO handle break with value - Ty::simple(TypeName::Never) + Ty::simple(TypeCtor::Never) } Expr::While { condition, body } => { // while let is desugared to a match loop, so this is always simple while - self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeName::Bool))); + self.infer_expr(*condition, &Expectation::has_type(Ty::simple(TypeCtor::Bool))); self.infer_expr(*body, &Expectation::has_type(Ty::unit())); Ty::unit() } @@ -777,11 +777,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let callee_ty = self.infer_expr(*callee, &Expectation::none()); let (param_tys, ret_ty) = match &callee_ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::FnPtr => { + TypeCtor::FnPtr => { let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); (sig.params().to_vec(), sig.ret().clone()) } - TypeName::FnDef(def) => { + TypeCtor::FnDef(def) => { let sig = self.db.callable_item_signature(def); let ret_ty = sig.ret().clone().subst(&a_ty.parameters); let param_tys = sig @@ -824,7 +824,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let method_ty = self.insert_type_vars(method_ty); let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::FnPtr => { + TypeCtor::FnPtr => { let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); if !sig.params().is_empty() { ( @@ -836,7 +836,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (Ty::Unknown, Vec::new(), sig.ret().clone()) } } - TypeName::FnDef(def) => { + TypeCtor::FnDef(def) => { let sig = self.db.callable_item_signature(def); let ret_ty = sig.ret().clone().subst(&a_ty.parameters); @@ -858,7 +858,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Apply autoref so the below unification works correctly let actual_receiver_ty = match expected_receiver_ty.as_reference() { Some((_, mutability)) => { - Ty::apply_one(TypeName::Ref(mutability), derefed_receiver_ty) + Ty::apply_one(TypeCtor::Ref(mutability), derefed_receiver_ty) } _ => derefed_receiver_ty, }; @@ -885,7 +885,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let Some(guard_expr) = arm.guard { self.infer_expr( guard_expr, - &Expectation::has_type(Ty::simple(TypeName::Bool)), + &Expectation::has_type(Ty::simple(TypeCtor::Bool)), ); } self.infer_expr(arm.expr, &expected); @@ -898,19 +898,19 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) } - Expr::Continue => Ty::simple(TypeName::Never), + Expr::Continue => Ty::simple(TypeCtor::Never), Expr::Break { expr } => { if let Some(expr) = expr { // TODO handle break with value self.infer_expr(*expr, &Expectation::none()); } - Ty::simple(TypeName::Never) + Ty::simple(TypeCtor::Never) } Expr::Return { expr } => { if let Some(expr) = expr { self.infer_expr(*expr, &Expectation::has_type(self.return_ty.clone())); } - Ty::simple(TypeName::Never) + Ty::simple(TypeCtor::Never) } Expr::StructLit { path, fields, spread } => { let (ty, def_id) = self.resolve_variant(path.as_ref()); @@ -933,11 +933,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .autoderef(self.db) .find_map(|derefed_ty| match derefed_ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Tuple => { + TypeCtor::Tuple => { let i = name.to_string().parse::().ok(); i.and_then(|i| a_ty.parameters.0.get(i).cloned()) } - TypeName::Adt(AdtDef::Struct(s)) => { + TypeCtor::Adt(AdtDef::Struct(s)) => { s.field(self.db, name).map(|field| { self.write_field_resolution(tgt_expr, field); field.ty(self.db).subst(&a_ty.parameters) @@ -973,7 +973,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { }; // TODO reference coercions etc. let inner_ty = self.infer_expr(*expr, &expectation); - Ty::apply_one(TypeName::Ref(*mutability), inner_ty) + Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) } Expr::UnaryOp { expr, op } => { let inner_ty = self.infer_expr(*expr, &Expectation::none()); @@ -989,9 +989,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { UnaryOp::Neg => { match &inner_ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Int(primitive::UncertainIntTy::Unknown) - | TypeName::Int(primitive::UncertainIntTy::Signed(..)) - | TypeName::Float(..) => inner_ty, + TypeCtor::Int(primitive::UncertainIntTy::Unknown) + | TypeCtor::Int(primitive::UncertainIntTy::Signed(..)) + | TypeCtor::Float(..) => inner_ty, _ => Ty::Unknown, }, Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { @@ -1004,7 +1004,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { UnaryOp::Not => { match &inner_ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Bool | TypeName::Int(_) => inner_ty, + TypeCtor::Bool | TypeCtor::Int(_) => inner_ty, _ => Ty::Unknown, }, Ty::Infer(InferTy::IntVar(..)) => inner_ty, @@ -1018,7 +1018,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Some(op) => { let lhs_expectation = match op { BinaryOp::BooleanAnd | BinaryOp::BooleanOr => { - Expectation::has_type(Ty::simple(TypeName::Bool)) + Expectation::has_type(Ty::simple(TypeCtor::Bool)) } _ => Expectation::none(), }; @@ -1039,12 +1039,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ty_vec.push(self.infer_expr(*arg, &Expectation::none())); } - Ty::apply(TypeName::Tuple, Substs(ty_vec.into())) + Ty::apply(TypeCtor::Tuple, Substs(ty_vec.into())) } Expr::Array { exprs } => { let elem_ty = match &expected.ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Slice | TypeName::Array => { + TypeCtor::Slice | TypeCtor::Array => { Ty::clone(&a_ty.parameters.as_single()) } _ => self.new_type_var(), @@ -1056,23 +1056,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); } - Ty::apply_one(TypeName::Array, elem_ty) + Ty::apply_one(TypeCtor::Array, elem_ty) } Expr::Literal(lit) => match lit { - Literal::Bool(..) => Ty::simple(TypeName::Bool), + Literal::Bool(..) => Ty::simple(TypeCtor::Bool), Literal::String(..) => { - Ty::apply_one(TypeName::Ref(Mutability::Shared), Ty::simple(TypeName::Str)) + Ty::apply_one(TypeCtor::Ref(Mutability::Shared), Ty::simple(TypeCtor::Str)) } Literal::ByteString(..) => { - let byte_type = Ty::simple(TypeName::Int(primitive::UncertainIntTy::Unsigned( + let byte_type = Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Unsigned( primitive::UintTy::U8, ))); - let slice_type = Ty::apply_one(TypeName::Slice, byte_type); - Ty::apply_one(TypeName::Ref(Mutability::Shared), slice_type) + let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type); + Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) } - Literal::Char(..) => Ty::simple(TypeName::Char), - Literal::Int(_v, ty) => Ty::simple(TypeName::Int(*ty)), - Literal::Float(_v, ty) => Ty::simple(TypeName::Float(*ty)), + Literal::Char(..) => Ty::simple(TypeCtor::Char), + Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int(*ty)), + Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float(*ty)), }, }; // use a new type variable if we got Ty::Unknown here @@ -1208,9 +1208,9 @@ impl InferTy { match self { InferTy::TypeVar(..) => Ty::Unknown, InferTy::IntVar(..) => { - Ty::simple(TypeName::Int(primitive::UncertainIntTy::Signed(primitive::IntTy::I32))) + Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Signed(primitive::IntTy::I32))) } - InferTy::FloatVar(..) => Ty::simple(TypeName::Float( + InferTy::FloatVar(..) => Ty::simple(TypeCtor::Float( primitive::UncertainFloatTy::Known(primitive::FloatTy::F64), )), } diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index a346879d8..72b1234bf 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -19,40 +19,40 @@ use crate::{ generics::GenericParams, adt::VariantDef, }; -use super::{Ty, primitive, FnSig, Substs, TypeName}; +use super::{Ty, primitive, FnSig, Substs, TypeCtor}; impl Ty { pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { match type_ref { - TypeRef::Never => Ty::simple(TypeName::Never), + TypeRef::Never => Ty::simple(TypeCtor::Never), TypeRef::Tuple(inner) => { let inner_tys = inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::>(); - Ty::apply(TypeName::Tuple, Substs(inner_tys.into())) + Ty::apply(TypeCtor::Tuple, Substs(inner_tys.into())) } TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path), TypeRef::RawPtr(inner, mutability) => { let inner_ty = Ty::from_hir(db, resolver, inner); - Ty::apply_one(TypeName::RawPtr(*mutability), inner_ty) + Ty::apply_one(TypeCtor::RawPtr(*mutability), inner_ty) } TypeRef::Array(inner) => { let inner_ty = Ty::from_hir(db, resolver, inner); - Ty::apply_one(TypeName::Array, inner_ty) + Ty::apply_one(TypeCtor::Array, inner_ty) } TypeRef::Slice(inner) => { let inner_ty = Ty::from_hir(db, resolver, inner); - Ty::apply_one(TypeName::Slice, inner_ty) + Ty::apply_one(TypeCtor::Slice, inner_ty) } TypeRef::Reference(inner, mutability) => { let inner_ty = Ty::from_hir(db, resolver, inner); - Ty::apply_one(TypeName::Ref(*mutability), inner_ty) + Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) } TypeRef::Placeholder => Ty::Unknown, TypeRef::Fn(params) => { let inner_tys = params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::>(); let sig = Substs(inner_tys.into()); - Ty::apply(TypeName::FnPtr, sig) + Ty::apply(TypeCtor::FnPtr, sig) } TypeRef::Error => Ty::Unknown, } @@ -62,14 +62,14 @@ impl Ty { if let Some(name) = path.as_ident() { // TODO handle primitive type names in resolver as well? if let Some(int_ty) = primitive::UncertainIntTy::from_type_name(name) { - return Ty::simple(TypeName::Int(int_ty)); + return Ty::simple(TypeCtor::Int(int_ty)); } else if let Some(float_ty) = primitive::UncertainFloatTy::from_type_name(name) { - return Ty::simple(TypeName::Float(float_ty)); + return Ty::simple(TypeCtor::Float(float_ty)); } else if let Some(known) = name.as_known_name() { match known { - KnownName::Bool => return Ty::simple(TypeName::Bool), - KnownName::Char => return Ty::simple(TypeName::Char), - KnownName::Str => return Ty::simple(TypeName::Str), + KnownName::Bool => return Ty::simple(TypeCtor::Bool), + KnownName::Char => return Ty::simple(TypeCtor::Char), + KnownName::Str => return Ty::simple(TypeCtor::Str), _ => {} } } @@ -245,7 +245,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { let generics = def.generic_params(db); let substs = make_substs(&generics); - Ty::apply(TypeName::FnDef(def.into()), substs) + Ty::apply(TypeCtor::FnDef(def.into()), substs) } /// Build the declared type of a const. @@ -287,7 +287,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { } let generics = def.generic_params(db); let substs = make_substs(&generics); - Ty::apply(TypeName::FnDef(def.into()), substs) + Ty::apply(TypeCtor::FnDef(def.into()), substs) } fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { @@ -315,7 +315,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> } let generics = def.parent_enum(db).generic_params(db); let substs = make_substs(&generics); - Ty::apply(TypeName::FnDef(def.into()), substs) + Ty::apply(TypeCtor::FnDef(def.into()), substs) } fn make_substs(generics: &GenericParams) -> Substs { @@ -331,12 +331,12 @@ fn make_substs(generics: &GenericParams) -> Substs { fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty { let generics = s.generic_params(db); - Ty::apply(TypeName::Adt(s.into()), make_substs(&generics)) + Ty::apply(TypeCtor::Adt(s.into()), make_substs(&generics)) } fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty { let generics = s.generic_params(db); - Ty::apply(TypeName::Adt(s.into()), make_substs(&generics)) + Ty::apply(TypeCtor::Adt(s.into()), make_substs(&generics)) } fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 06bfe85cd..9422bad84 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -10,7 +10,7 @@ use crate::{ HirDatabase, Module, Crate, Name, Function, Trait, ids::TraitId, impl_block::{ImplId, ImplBlock, ImplItem}, - ty::{Ty, TypeName}, + ty::{Ty, TypeCtor}, nameres::CrateModuleId, }; @@ -18,7 +18,7 @@ use crate::{ /// This is used as a key for indexing impls. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TyFingerprint { - Apply(TypeName), + Apply(TypeCtor), } impl TyFingerprint { @@ -112,7 +112,7 @@ impl CrateImplBlocks { fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option { match ty { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Adt(def_id) => def_id.krate(db), + TypeCtor::Adt(def_id) => def_id.krate(db), _ => None, }, _ => None, diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs index f581004d2..1d230140b 100644 --- a/crates/ra_hir/src/ty/op.rs +++ b/crates/ra_hir/src/ty/op.rs @@ -1,5 +1,5 @@ use crate::{ ty::ApplicationTy, expr::BinaryOp}; -use super::{Ty, TypeName, InferTy}; +use super::{Ty, TypeCtor, InferTy}; pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { match op { @@ -10,7 +10,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { | BinaryOp::LesserEqualTest | BinaryOp::GreaterEqualTest | BinaryOp::LesserTest - | BinaryOp::GreaterTest => Ty::simple(TypeName::Bool), + | BinaryOp::GreaterTest => Ty::simple(TypeCtor::Bool), BinaryOp::Assignment | BinaryOp::AddAssign | BinaryOp::SubAssign @@ -33,7 +33,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { | BinaryOp::BitwiseOr | BinaryOp::BitwiseXor => match rhs_ty { Ty::Apply(ApplicationTy { name, .. }) => match name { - TypeName::Int(..) | TypeName::Float(..) => rhs_ty, + TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, _ => Ty::Unknown, }, Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, @@ -45,14 +45,14 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { match op { - BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeName::Bool), + BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool), BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { Ty::Apply(ApplicationTy { name, .. }) => match name { - TypeName::Int(..) - | TypeName::Float(..) - | TypeName::Str - | TypeName::Char - | TypeName::Bool => lhs_ty, + TypeCtor::Int(..) + | TypeCtor::Float(..) + | TypeCtor::Str + | TypeCtor::Char + | TypeCtor::Bool => lhs_ty, _ => Ty::Unknown, }, Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, @@ -83,7 +83,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | BinaryOp::BitwiseOr | BinaryOp::BitwiseXor => match lhs_ty { Ty::Apply(ApplicationTy { name, .. }) => match name { - TypeName::Int(..) | TypeName::Float(..) => lhs_ty, + TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, _ => Ty::Unknown, }, Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index dc5206a64..f975214e9 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{Ty, AdtDef, TypeName}; +use hir::{Ty, AdtDef, TypeCtor}; use crate::completion::{CompletionContext, Completions}; @@ -25,13 +25,13 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) for receiver in receiver.autoderef(ctx.db) { match receiver { Ty::Apply(a_ty) => match a_ty.name { - TypeName::Adt(AdtDef::Struct(s)) => { + TypeCtor::Adt(AdtDef::Struct(s)) => { for field in s.fields(ctx.db) { acc.add_field(ctx, field, &a_ty.parameters); } } // TODO unions - TypeName::Tuple => { + TypeCtor::Tuple => { for (i, ty) in a_ty.parameters.iter().enumerate() { acc.add_pos_field(ctx, i, ty); } -- cgit v1.2.3