From 0e995adcf690778739fe94fb94ae317d42b4e51b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Feb 2021 20:39:43 +0100 Subject: Turn Ty::Tuple variant into a tuple-variant --- crates/hir/src/code_model.rs | 4 ++-- crates/hir_ty/src/display.rs | 2 +- crates/hir_ty/src/infer/expr.rs | 8 ++++---- crates/hir_ty/src/infer/pat.rs | 2 +- crates/hir_ty/src/lib.rs | 16 +++++++--------- crates/hir_ty/src/lower.rs | 2 +- crates/hir_ty/src/method_resolution.rs | 4 ++-- crates/hir_ty/src/traits/chalk/mapping.rs | 4 ++-- 8 files changed, 20 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index cdb54eca2..1c31e29ac 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1547,7 +1547,7 @@ impl Type { } pub fn is_unit(&self) -> bool { - matches!(self.ty.value, Ty::Tuple { cardinality: 0, .. }) + matches!(self.ty.value, Ty::Tuple(0, ..)) } pub fn is_bool(&self) -> bool { matches!(self.ty.value, Ty::Scalar(Scalar::Bool)) @@ -1741,7 +1741,7 @@ impl Type { } pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec { - if let Ty::Tuple { substs, .. } = &self.ty.value { + if let Ty::Tuple(_, substs) = &self.ty.value { substs.iter().map(|ty| self.derived(ty.clone())).collect() } else { Vec::new() diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index cd9dcf6c0..666bb1f9d 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -330,7 +330,7 @@ impl HirDisplay for Ty { write!(f, "{}", ty_display)?; } } - Ty::Tuple { substs, .. } => { + Ty::Tuple(_, substs) => { if substs.len() == 1 { write!(f, "(")?; substs[0].hir_fmt(f)?; diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 2369c9bef..13240f790 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -82,7 +82,7 @@ impl<'a> InferenceContext<'a> { arg_tys.push(arg); } let parameters = param_builder.build(); - let arg_ty = Ty::Tuple { cardinality: num_args as u16, substs: parameters }; + let arg_ty = Ty::Tuple(num_args, parameters); let substs = Substs::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); @@ -424,7 +424,7 @@ impl<'a> InferenceContext<'a> { }, ) .find_map(|derefed_ty| match canonicalized.decanonicalize_ty(derefed_ty.value) { - Ty::Tuple { substs, .. } => { + Ty::Tuple(_, substs) => { name.as_tuple_index().and_then(|idx| substs.0.get(idx).cloned()) } Ty::Adt(AdtId::StructId(s), parameters) => { @@ -635,7 +635,7 @@ impl<'a> InferenceContext<'a> { } Expr::Tuple { exprs } => { let mut tys = match &expected.ty { - Ty::Tuple { substs, .. } => substs + Ty::Tuple(_, substs) => substs .iter() .cloned() .chain(repeat_with(|| self.table.new_type_var())) @@ -648,7 +648,7 @@ impl<'a> InferenceContext<'a> { self.infer_expr_coerce(*expr, &Expectation::has_type(ty.clone())); } - Ty::Tuple { cardinality: tys.len() as u16, substs: Substs(tys.into()) } + Ty::Tuple(tys.len(), Substs(tys.into())) } Expr::Array(array) => { let elem_ty = match &expected.ty { diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index e96e08c3c..a318e47f3 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -138,7 +138,7 @@ impl<'a> InferenceContext<'a> { inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); - Ty::Tuple { cardinality: inner_tys.len() as u16, substs: Substs(inner_tys.into()) } + Ty::Tuple(inner_tys.len(), Substs(inner_tys.into())) } Pat::Or(ref pats) => { if let Some((first_pat, rest)) = pats.split_first() { diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 117d69f01..3d134453f 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -120,7 +120,7 @@ pub enum Ty { Scalar(Scalar), /// A tuple type. For example, `(i32, bool)`. - Tuple { cardinality: u16, substs: Substs }, + Tuple(usize, Substs), /// An array with the given length. Written as `[T; n]`. Array(Substs), @@ -582,7 +582,7 @@ impl TypeWalk for FnSig { impl Ty { pub fn unit() -> Self { - Ty::Tuple { cardinality: 0, substs: Substs::empty() } + Ty::Tuple(0, Substs::empty()) } pub fn fn_ptr(sig: FnSig) -> Self { @@ -642,7 +642,7 @@ impl Ty { pub fn as_tuple(&self) -> Option<&Substs> { match self { - Ty::Tuple { substs: parameters, .. } => Some(parameters), + Ty::Tuple(_, substs) => Some(substs), _ => None, } } @@ -684,9 +684,7 @@ impl Ty { Ty::FnPtr { num_args, is_varargs, .. }, Ty::FnPtr { num_args: num_args2, is_varargs: is_varargs2, .. }, ) => num_args == num_args2 && is_varargs == is_varargs2, - (Ty::Tuple { cardinality, .. }, Ty::Tuple { cardinality: cardinality2, .. }) => { - cardinality == cardinality2 - } + (Ty::Tuple(cardinality, _), Ty::Tuple(cardinality2, _)) => cardinality == cardinality2, (Ty::Str, Ty::Str) | (Ty::Never, Ty::Never) => true, (Ty::Scalar(scalar), Ty::Scalar(scalar2)) => scalar == scalar2, _ => false, @@ -754,7 +752,7 @@ impl Ty { | Ty::Ref(_, substs) | Ty::FnDef(_, substs) | Ty::FnPtr { substs, .. } - | Ty::Tuple { substs, .. } + | Ty::Tuple(_, substs) | Ty::OpaqueType(_, substs) | Ty::AssociatedType(_, substs) | Ty::ForeignType(_, substs) @@ -778,7 +776,7 @@ impl Ty { | Ty::Ref(_, substs) | Ty::FnDef(_, substs) | Ty::FnPtr { substs, .. } - | Ty::Tuple { substs, .. } + | Ty::Tuple(_, substs) | Ty::OpaqueType(_, substs) | Ty::AssociatedType(_, substs) | Ty::ForeignType(_, substs) @@ -796,7 +794,7 @@ impl Ty { | Ty::Ref(_, substs) | Ty::FnDef(_, substs) | Ty::FnPtr { substs, .. } - | Ty::Tuple { substs, .. } + | Ty::Tuple(_, substs) | Ty::OpaqueType(_, substs) | Ty::AssociatedType(_, substs) | Ty::ForeignType(_, substs) diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 6b919a09e..8295f4c31 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -148,7 +148,7 @@ impl Ty { TypeRef::Never => Ty::Never, TypeRef::Tuple(inner) => { let inner_tys: Arc<[Ty]> = inner.iter().map(|tr| Ty::from_hir(ctx, tr)).collect(); - Ty::Tuple { cardinality: inner_tys.len() as u16, substs: Substs(inner_tys) } + Ty::Tuple(inner_tys.len(), Substs(inner_tys)) } TypeRef::Path(path) => { let (ty, res_) = Ty::from_hir_path(ctx, path); diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 087b67935..422e61f0a 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -33,7 +33,7 @@ pub enum TyFingerprint { Scalar(Scalar), Adt(AdtId), Dyn(TraitId), - Tuple { cardinality: u16 }, + Tuple(usize), ForeignType(TypeAliasId), FnPtr { num_args: u16, is_varargs: bool }, } @@ -50,7 +50,7 @@ impl TyFingerprint { &Ty::Array(..) => TyFingerprint::Array, &Ty::Scalar(scalar) => TyFingerprint::Scalar(scalar), &Ty::Adt(adt, _) => TyFingerprint::Adt(adt), - &Ty::Tuple { cardinality: u16, .. } => TyFingerprint::Tuple { cardinality: u16 }, + &Ty::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality), &Ty::RawPtr(mutability, ..) => TyFingerprint::RawPtr(mutability), &Ty::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id), &Ty::FnPtr { num_args, is_varargs, .. } => { diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 297ddeabd..09e5a82b8 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -63,7 +63,7 @@ impl ToChalk for Ty { Ty::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), - Ty::Tuple { cardinality, substs } => { + Ty::Tuple(cardinality, substs) => { let substitution = substs.to_chalk(db); chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) } @@ -199,7 +199,7 @@ impl ToChalk for Ty { chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar), chalk_ir::TyKind::Tuple(cardinality, subst) => { - Ty::Tuple { cardinality: cardinality as u16, substs: from_chalk(db, subst) } + Ty::Tuple(cardinality, from_chalk(db, subst)) } chalk_ir::TyKind::Raw(mutability, ty) => { Ty::RawPtr(from_chalk(db, mutability), Substs::single(from_chalk(db, ty))) -- cgit v1.2.3