Rename name field to ctor as well
This commit is contained in:
parent
97be0e6c46
commit
cbb418ebb8
5 changed files with 29 additions and 29 deletions
|
@ -93,7 +93,7 @@ pub enum TypeCtor {
|
|||
/// several other things.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ApplicationTy {
|
||||
pub name: TypeCtor,
|
||||
pub ctor: TypeCtor,
|
||||
pub parameters: Substs,
|
||||
}
|
||||
|
||||
|
@ -201,14 +201,14 @@ impl FnSig {
|
|||
}
|
||||
|
||||
impl Ty {
|
||||
pub fn simple(name: TypeCtor) -> Ty {
|
||||
Ty::Apply(ApplicationTy { name, parameters: Substs::empty() })
|
||||
pub fn simple(ctor: TypeCtor) -> Ty {
|
||||
Ty::Apply(ApplicationTy { ctor, parameters: Substs::empty() })
|
||||
}
|
||||
pub fn apply_one(name: TypeCtor, param: Ty) -> Ty {
|
||||
Ty::Apply(ApplicationTy { name, parameters: Substs::single(param) })
|
||||
pub fn apply_one(ctor: TypeCtor, param: Ty) -> Ty {
|
||||
Ty::Apply(ApplicationTy { ctor, parameters: Substs::single(param) })
|
||||
}
|
||||
pub fn apply(name: TypeCtor, parameters: Substs) -> Ty {
|
||||
Ty::Apply(ApplicationTy { name, parameters })
|
||||
pub fn apply(ctor: TypeCtor, parameters: Substs) -> Ty {
|
||||
Ty::Apply(ApplicationTy { ctor, parameters })
|
||||
}
|
||||
pub fn unit() -> Self {
|
||||
Ty::apply(TypeCtor::Tuple, Substs::empty())
|
||||
|
@ -246,7 +246,7 @@ impl Ty {
|
|||
|
||||
pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
|
||||
match self {
|
||||
Ty::Apply(ApplicationTy { name: TypeCtor::Ref(mutability), parameters }) => {
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(mutability), parameters }) => {
|
||||
Some((parameters.as_single(), *mutability))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -255,7 +255,7 @@ impl Ty {
|
|||
|
||||
pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> {
|
||||
match self {
|
||||
Ty::Apply(ApplicationTy { name: TypeCtor::Adt(adt_def), parameters }) => {
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => {
|
||||
Some((*adt_def, parameters))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -264,14 +264,14 @@ impl Ty {
|
|||
|
||||
pub fn as_tuple(&self) -> Option<&Substs> {
|
||||
match self {
|
||||
Ty::Apply(ApplicationTy { name: TypeCtor::Tuple, parameters }) => Some(parameters),
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::Tuple, parameters }) => Some(parameters),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn builtin_deref(&self) -> Option<Ty> {
|
||||
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::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())),
|
||||
_ => None,
|
||||
|
@ -286,8 +286,8 @@ impl Ty {
|
|||
/// `Option<u32>` afterwards.)
|
||||
pub fn apply_substs(self, substs: Substs) -> Ty {
|
||||
match self {
|
||||
Ty::Apply(ApplicationTy { name, .. }) => {
|
||||
Ty::Apply(ApplicationTy { name, parameters: substs })
|
||||
Ty::Apply(ApplicationTy { ctor, .. }) => {
|
||||
Ty::Apply(ApplicationTy { ctor, parameters: substs })
|
||||
}
|
||||
_ => self,
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ impl HirDisplay for &Ty {
|
|||
|
||||
impl HirDisplay for ApplicationTy {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
|
||||
match self.name {
|
||||
match self.ctor {
|
||||
TypeCtor::Bool => write!(f, "bool")?,
|
||||
TypeCtor::Char => write!(f, "char")?,
|
||||
TypeCtor::Int(t) => write!(f, "{}", t)?,
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
match (&*ty1, &*ty2) {
|
||||
(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)
|
||||
}
|
||||
(Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2)))
|
||||
|
@ -278,11 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
match ty {
|
||||
Ty::Unknown => self.new_type_var(),
|
||||
Ty::Apply(ApplicationTy {
|
||||
name: TypeCtor::Int(primitive::UncertainIntTy::Unknown),
|
||||
ctor: TypeCtor::Int(primitive::UncertainIntTy::Unknown),
|
||||
..
|
||||
}) => self.new_integer_var(),
|
||||
Ty::Apply(ApplicationTy {
|
||||
name: TypeCtor::Float(primitive::UncertainFloatTy::Unknown),
|
||||
ctor: TypeCtor::Float(primitive::UncertainFloatTy::Unknown),
|
||||
..
|
||||
}) => self.new_float_var(),
|
||||
_ => ty,
|
||||
|
@ -776,7 +776,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
Expr::Call { callee, args } => {
|
||||
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 {
|
||||
Ty::Apply(a_ty) => match a_ty.ctor {
|
||||
TypeCtor::FnPtr => {
|
||||
let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
|
||||
(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 = 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 {
|
||||
Ty::Apply(a_ty) => match a_ty.ctor {
|
||||
TypeCtor::FnPtr => {
|
||||
let sig = FnSig::from_fn_ptr_substs(&a_ty.parameters);
|
||||
if !sig.params().is_empty() {
|
||||
|
@ -932,7 +932,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
let ty = receiver_ty
|
||||
.autoderef(self.db)
|
||||
.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 => {
|
||||
let i = name.to_string().parse::<usize>().ok();
|
||||
i.and_then(|i| a_ty.parameters.0.get(i).cloned())
|
||||
|
@ -988,7 +988,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
UnaryOp::Neg => {
|
||||
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::Signed(..))
|
||||
| TypeCtor::Float(..) => inner_ty,
|
||||
|
@ -1003,7 +1003,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
UnaryOp::Not => {
|
||||
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,
|
||||
_ => Ty::Unknown,
|
||||
},
|
||||
|
@ -1043,7 +1043,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
Expr::Array { exprs } => {
|
||||
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 => {
|
||||
Ty::clone(&a_ty.parameters.as_single())
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ impl TyFingerprint {
|
|||
/// `impl &S`. Hence, this will return `None` for reference types and such.
|
||||
fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
|
||||
match ty {
|
||||
Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.name)),
|
||||
Ty::Apply(a_ty) => Some(TyFingerprint::Apply(a_ty.ctor)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ impl CrateImplBlocks {
|
|||
|
||||
fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
|
||||
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),
|
||||
_ => None,
|
||||
},
|
||||
|
|
|
@ -32,7 +32,7 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
|
|||
| BinaryOp::BitwiseAnd
|
||||
| BinaryOp::BitwiseOr
|
||||
| BinaryOp::BitwiseXor => match rhs_ty {
|
||||
Ty::Apply(ApplicationTy { name, .. }) => match name {
|
||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||
TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
|
||||
_ => Ty::Unknown,
|
||||
},
|
||||
|
@ -47,7 +47,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
|||
match op {
|
||||
BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool),
|
||||
BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty {
|
||||
Ty::Apply(ApplicationTy { name, .. }) => match name {
|
||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||
TypeCtor::Int(..)
|
||||
| TypeCtor::Float(..)
|
||||
| TypeCtor::Str
|
||||
|
@ -82,7 +82,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
|||
| BinaryOp::BitwiseAnd
|
||||
| BinaryOp::BitwiseOr
|
||||
| BinaryOp::BitwiseXor => match lhs_ty {
|
||||
Ty::Apply(ApplicationTy { name, .. }) => match name {
|
||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
|
||||
_ => Ty::Unknown,
|
||||
},
|
||||
|
|
|
@ -24,7 +24,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
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 {
|
||||
Ty::Apply(a_ty) => match a_ty.ctor {
|
||||
TypeCtor::Adt(AdtDef::Struct(s)) => {
|
||||
for field in s.fields(ctx.db) {
|
||||
acc.add_field(ctx, field, &a_ty.parameters);
|
||||
|
|
Loading…
Add table
Reference in a new issue