Rename name field to ctor as well

This commit is contained in:
Florian Diebold 2019-03-21 22:29:12 +01:00
parent 97be0e6c46
commit cbb418ebb8
5 changed files with 29 additions and 29 deletions

View file

@ -93,7 +93,7 @@ pub enum TypeCtor {
/// several other things. /// several other things.
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct ApplicationTy { pub struct ApplicationTy {
pub name: TypeCtor, pub ctor: TypeCtor,
pub parameters: Substs, pub parameters: Substs,
} }
@ -201,14 +201,14 @@ impl FnSig {
} }
impl Ty { impl Ty {
pub fn simple(name: TypeCtor) -> Ty { pub fn simple(ctor: TypeCtor) -> Ty {
Ty::Apply(ApplicationTy { name, parameters: Substs::empty() }) Ty::Apply(ApplicationTy { ctor, parameters: Substs::empty() })
} }
pub fn apply_one(name: TypeCtor, param: Ty) -> Ty { pub fn apply_one(ctor: TypeCtor, param: Ty) -> Ty {
Ty::Apply(ApplicationTy { name, parameters: Substs::single(param) }) Ty::Apply(ApplicationTy { ctor, parameters: Substs::single(param) })
} }
pub fn apply(name: TypeCtor, parameters: Substs) -> Ty { pub fn apply(ctor: TypeCtor, parameters: Substs) -> Ty {
Ty::Apply(ApplicationTy { name, parameters }) Ty::Apply(ApplicationTy { ctor, parameters })
} }
pub fn unit() -> Self { pub fn unit() -> Self {
Ty::apply(TypeCtor::Tuple, Substs::empty()) Ty::apply(TypeCtor::Tuple, Substs::empty())
@ -246,7 +246,7 @@ impl Ty {
pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
match self { match self {
Ty::Apply(ApplicationTy { name: TypeCtor::Ref(mutability), parameters }) => { Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(mutability), parameters }) => {
Some((parameters.as_single(), *mutability)) Some((parameters.as_single(), *mutability))
} }
_ => None, _ => None,
@ -255,7 +255,7 @@ impl Ty {
pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> { pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> {
match self { match self {
Ty::Apply(ApplicationTy { name: TypeCtor::Adt(adt_def), parameters }) => { Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => {
Some((*adt_def, parameters)) Some((*adt_def, parameters))
} }
_ => None, _ => None,
@ -264,14 +264,14 @@ impl Ty {
pub fn as_tuple(&self) -> Option<&Substs> { pub fn as_tuple(&self) -> Option<&Substs> {
match self { match self {
Ty::Apply(ApplicationTy { name: TypeCtor::Tuple, parameters }) => Some(parameters), Ty::Apply(ApplicationTy { ctor: TypeCtor::Tuple, parameters }) => Some(parameters),
_ => None, _ => None,
} }
} }
fn builtin_deref(&self) -> Option<Ty> { fn builtin_deref(&self) -> Option<Ty> {
match self { match self {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Ref(..) => 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())), TypeCtor::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())),
_ => None, _ => None,
@ -286,8 +286,8 @@ impl Ty {
/// `Option<u32>` afterwards.) /// `Option<u32>` afterwards.)
pub fn apply_substs(self, substs: Substs) -> Ty { pub fn apply_substs(self, substs: Substs) -> Ty {
match self { match self {
Ty::Apply(ApplicationTy { name, .. }) => { Ty::Apply(ApplicationTy { ctor, .. }) => {
Ty::Apply(ApplicationTy { name, parameters: substs }) Ty::Apply(ApplicationTy { ctor, parameters: substs })
} }
_ => self, _ => self,
} }
@ -327,7 +327,7 @@ impl HirDisplay for &Ty {
impl HirDisplay for ApplicationTy { impl HirDisplay for ApplicationTy {
fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
match self.name { match self.ctor {
TypeCtor::Bool => write!(f, "bool")?, TypeCtor::Bool => write!(f, "bool")?,
TypeCtor::Char => write!(f, "char")?, TypeCtor::Char => write!(f, "char")?,
TypeCtor::Int(t) => write!(f, "{}", t)?, TypeCtor::Int(t) => write!(f, "{}", t)?,

View file

@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
match (&*ty1, &*ty2) { match (&*ty1, &*ty2) {
(Ty::Unknown, ..) => true, (Ty::Unknown, ..) => true,
(.., Ty::Unknown) => true, (.., Ty::Unknown) => true,
(Ty::Apply(a_ty1), Ty::Apply(a_ty2)) if a_ty1.name == a_ty2.name => { (Ty::Apply(a_ty1), Ty::Apply(a_ty2)) if a_ty1.ctor == a_ty2.ctor => {
self.unify_substs(&a_ty1.parameters, &a_ty2.parameters, depth + 1) self.unify_substs(&a_ty1.parameters, &a_ty2.parameters, depth + 1)
} }
(Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2))) (Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2)))
@ -278,11 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
match ty { match ty {
Ty::Unknown => self.new_type_var(), Ty::Unknown => self.new_type_var(),
Ty::Apply(ApplicationTy { Ty::Apply(ApplicationTy {
name: TypeCtor::Int(primitive::UncertainIntTy::Unknown), ctor: TypeCtor::Int(primitive::UncertainIntTy::Unknown),
.. ..
}) => self.new_integer_var(), }) => self.new_integer_var(),
Ty::Apply(ApplicationTy { Ty::Apply(ApplicationTy {
name: TypeCtor::Float(primitive::UncertainFloatTy::Unknown), ctor: TypeCtor::Float(primitive::UncertainFloatTy::Unknown),
.. ..
}) => self.new_float_var(), }) => self.new_float_var(),
_ => ty, _ => ty,
@ -776,7 +776,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
Expr::Call { callee, args } => { Expr::Call { callee, args } => {
let callee_ty = self.infer_expr(*callee, &Expectation::none()); let callee_ty = self.infer_expr(*callee, &Expectation::none());
let (param_tys, ret_ty) = match &callee_ty { let (param_tys, ret_ty) = match &callee_ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::FnPtr => { TypeCtor::FnPtr => {
let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
(sig.params().to_vec(), sig.ret().clone()) (sig.params().to_vec(), sig.ret().clone())
@ -823,7 +823,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
let method_ty = method_ty.apply_substs(substs); let method_ty = method_ty.apply_substs(substs);
let method_ty = self.insert_type_vars(method_ty); let method_ty = self.insert_type_vars(method_ty);
let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty { let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::FnPtr => { TypeCtor::FnPtr => {
let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters); let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
if !sig.params().is_empty() { if !sig.params().is_empty() {
@ -932,7 +932,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
let ty = receiver_ty let ty = receiver_ty
.autoderef(self.db) .autoderef(self.db)
.find_map(|derefed_ty| match derefed_ty { .find_map(|derefed_ty| match derefed_ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Tuple => { TypeCtor::Tuple => {
let i = name.to_string().parse::<usize>().ok(); let i = name.to_string().parse::<usize>().ok();
i.and_then(|i| a_ty.parameters.0.get(i).cloned()) i.and_then(|i| a_ty.parameters.0.get(i).cloned())
@ -988,7 +988,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
} }
UnaryOp::Neg => { UnaryOp::Neg => {
match &inner_ty { match &inner_ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Int(primitive::UncertainIntTy::Unknown) TypeCtor::Int(primitive::UncertainIntTy::Unknown)
| TypeCtor::Int(primitive::UncertainIntTy::Signed(..)) | TypeCtor::Int(primitive::UncertainIntTy::Signed(..))
| TypeCtor::Float(..) => inner_ty, | TypeCtor::Float(..) => inner_ty,
@ -1003,7 +1003,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
} }
UnaryOp::Not => { UnaryOp::Not => {
match &inner_ty { match &inner_ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Bool | TypeCtor::Int(_) => inner_ty, TypeCtor::Bool | TypeCtor::Int(_) => inner_ty,
_ => Ty::Unknown, _ => Ty::Unknown,
}, },
@ -1043,7 +1043,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
} }
Expr::Array { exprs } => { Expr::Array { exprs } => {
let elem_ty = match &expected.ty { let elem_ty = match &expected.ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Slice | TypeCtor::Array => { TypeCtor::Slice | TypeCtor::Array => {
Ty::clone(&a_ty.parameters.as_single()) Ty::clone(&a_ty.parameters.as_single())
} }

View file

@ -27,7 +27,7 @@ impl TyFingerprint {
/// `impl &S`. Hence, this will return `None` for reference types and such. /// `impl &S`. Hence, this will return `None` for reference types and such.
fn for_impl(ty: &Ty) -> Option<TyFingerprint> { fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
match ty { match ty {
Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.name)), Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.ctor)),
_ => None, _ => None,
} }
} }
@ -111,7 +111,7 @@ impl CrateImplBlocks {
fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> { fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
match ty { match ty {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Adt(def_id) => def_id.krate(db), TypeCtor::Adt(def_id) => def_id.krate(db),
_ => None, _ => None,
}, },

View file

@ -32,7 +32,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
| BinaryOp::BitwiseAnd | BinaryOp::BitwiseAnd
| BinaryOp::BitwiseOr | BinaryOp::BitwiseOr
| BinaryOp::BitwiseXor => match rhs_ty { | BinaryOp::BitwiseXor => match rhs_ty {
Ty::Apply(ApplicationTy { name, .. }) => match name { Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
_ => Ty::Unknown, _ => Ty::Unknown,
}, },
@ -47,7 +47,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
match op { match op {
BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool), BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool),
BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty {
Ty::Apply(ApplicationTy { name, .. }) => match name { Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
TypeCtor::Int(..) TypeCtor::Int(..)
| TypeCtor::Float(..) | TypeCtor::Float(..)
| TypeCtor::Str | TypeCtor::Str
@ -82,7 +82,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
| BinaryOp::BitwiseAnd | BinaryOp::BitwiseAnd
| BinaryOp::BitwiseOr | BinaryOp::BitwiseOr
| BinaryOp::BitwiseXor => match lhs_ty { | BinaryOp::BitwiseXor => match lhs_ty {
Ty::Apply(ApplicationTy { name, .. }) => match name { Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
_ => Ty::Unknown, _ => Ty::Unknown,
}, },

View file

@ -24,7 +24,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
for receiver in receiver.autoderef(ctx.db) { for receiver in receiver.autoderef(ctx.db) {
match receiver { match receiver {
Ty::Apply(a_ty) => match a_ty.name { Ty::Apply(a_ty) => match a_ty.ctor {
TypeCtor::Adt(AdtDef::Struct(s)) => { TypeCtor::Adt(AdtDef::Struct(s)) => {
for field in s.fields(ctx.db) { for field in s.fields(ctx.db) {
acc.add_field(ctx, field, &a_ty.parameters); acc.add_field(ctx, field, &a_ty.parameters);