mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 12:13:12 +00:00
Merge #7814
7814: Turn Ty::Tuple variant into a tuple-variant r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
23d7dbfa5e
@ -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<Type> {
|
||||
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()
|
||||
|
@ -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)?;
|
||||
@ -471,14 +471,9 @@ impl HirDisplay for Ty {
|
||||
projection_ty.hir_fmt(f)?;
|
||||
}
|
||||
}
|
||||
Ty::ForeignType(type_alias, parameters) => {
|
||||
Ty::ForeignType(type_alias) => {
|
||||
let type_alias = f.db.type_alias_data(*type_alias);
|
||||
write!(f, "{}", type_alias.name)?;
|
||||
if parameters.len() > 0 {
|
||||
write!(f, "<")?;
|
||||
f.write_joined(&*parameters.0, ", ")?;
|
||||
write!(f, ">")?;
|
||||
}
|
||||
}
|
||||
Ty::OpaqueType(opaque_ty_id, parameters) => {
|
||||
match opaque_ty_id {
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
@ -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),
|
||||
@ -169,7 +169,7 @@ pub enum Ty {
|
||||
Closure { def: DefWithBodyId, expr: ExprId, substs: Substs },
|
||||
|
||||
/// Represents a foreign type declared in external blocks.
|
||||
ForeignType(TypeAliasId, Substs),
|
||||
ForeignType(TypeAliasId),
|
||||
|
||||
/// A pointer to a function. Written as `fn() -> i32`.
|
||||
///
|
||||
@ -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,10 +752,9 @@ 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)
|
||||
| Ty::Closure { substs, .. } => {
|
||||
assert_eq!(substs.len(), new_substs.len());
|
||||
*substs = new_substs;
|
||||
@ -778,10 +775,9 @@ 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)
|
||||
| Ty::Closure { substs, .. } => Some(substs),
|
||||
_ => None,
|
||||
}
|
||||
@ -796,10 +792,9 @@ 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)
|
||||
| Ty::Closure { substs, .. } => Some(substs),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -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);
|
||||
@ -1100,10 +1100,10 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
|
||||
let resolver = t.resolver(db.upcast());
|
||||
let ctx =
|
||||
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
||||
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
|
||||
if db.type_alias_data(t).is_extern {
|
||||
Binders::new(substs.len(), Ty::ForeignType(t, substs))
|
||||
Binders::new(0, Ty::ForeignType(t))
|
||||
} else {
|
||||
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
|
||||
let type_ref = &db.type_alias_data(t).type_ref;
|
||||
let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
|
||||
Binders::new(substs.len(), inner)
|
||||
|
@ -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, .. } => {
|
||||
@ -235,7 +235,7 @@ impl Ty {
|
||||
Ty::Adt(def_id, _) => {
|
||||
return mod_to_crate_ids(def_id.module(db.upcast()));
|
||||
}
|
||||
Ty::ForeignType(type_alias_id, _) => {
|
||||
Ty::ForeignType(type_alias_id) => {
|
||||
return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast()));
|
||||
}
|
||||
Ty::Scalar(Scalar::Bool) => lang_item_crate!("bool"),
|
||||
|
@ -55,7 +55,7 @@ impl ToChalk for Ty {
|
||||
chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
|
||||
}
|
||||
|
||||
Ty::ForeignType(type_alias, _) => {
|
||||
Ty::ForeignType(type_alias) => {
|
||||
let foreign_type = TypeAliasAsForeignType(type_alias);
|
||||
let foreign_type_id = foreign_type.to_chalk(db);
|
||||
chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner)
|
||||
@ -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)))
|
||||
@ -221,10 +221,9 @@ impl ToChalk for Ty {
|
||||
Ty::Closure { def, expr, substs: from_chalk(db, subst) }
|
||||
}
|
||||
|
||||
chalk_ir::TyKind::Foreign(foreign_def_id) => Ty::ForeignType(
|
||||
from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0,
|
||||
Substs::empty(),
|
||||
),
|
||||
chalk_ir::TyKind::Foreign(foreign_def_id) => {
|
||||
Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
|
||||
}
|
||||
chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
|
||||
chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user