Remove TypeAndMut from relate
This commit is contained in:
parent
1447f9d38c
commit
24db8eaefd
@ -94,28 +94,6 @@ fn relate<R: TypeRelation<'tcx>>(
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Relate impls
|
// Relate impls
|
||||||
|
|
||||||
pub fn relate_type_and_mut<'tcx, R: TypeRelation<'tcx>>(
|
|
||||||
relation: &mut R,
|
|
||||||
a: ty::TypeAndMut<'tcx>,
|
|
||||||
b: ty::TypeAndMut<'tcx>,
|
|
||||||
base_ty: Ty<'tcx>,
|
|
||||||
) -> RelateResult<'tcx, ty::TypeAndMut<'tcx>> {
|
|
||||||
debug!("{}.mts({:?}, {:?})", relation.tag(), a, b);
|
|
||||||
if a.mutbl != b.mutbl {
|
|
||||||
Err(TypeError::Mutability)
|
|
||||||
} else {
|
|
||||||
let mutbl = a.mutbl;
|
|
||||||
let (variance, info) = match mutbl {
|
|
||||||
hir::Mutability::Not => (ty::Covariant, ty::VarianceDiagInfo::None),
|
|
||||||
hir::Mutability::Mut => {
|
|
||||||
(ty::Invariant, ty::VarianceDiagInfo::Invariant { ty: base_ty, param_index: 0 })
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let ty = relation.relate_with_variance(variance, info, a.ty, b.ty)?;
|
|
||||||
Ok(ty::TypeAndMut { ty, mutbl })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn relate_args_invariantly<'tcx, R: TypeRelation<'tcx>>(
|
pub fn relate_args_invariantly<'tcx, R: TypeRelation<'tcx>>(
|
||||||
relation: &mut R,
|
relation: &mut R,
|
||||||
@ -465,17 +443,42 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||||||
Ok(Ty::new_coroutine_closure(tcx, a_id, args))
|
Ok(Ty::new_coroutine_closure(tcx, a_id, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::RawPtr(a_mt), &ty::RawPtr(b_mt)) => {
|
(
|
||||||
let mt = relate_type_and_mut(relation, a_mt, b_mt, a)?;
|
&ty::RawPtr(ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl }),
|
||||||
Ok(Ty::new_ptr(tcx, mt))
|
&ty::RawPtr(ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl }),
|
||||||
|
) => {
|
||||||
|
if a_mutbl != b_mutbl {
|
||||||
|
return Err(TypeError::Mutability);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (variance, info) = match a_mutbl {
|
||||||
|
hir::Mutability::Not => (ty::Covariant, ty::VarianceDiagInfo::None),
|
||||||
|
hir::Mutability::Mut => {
|
||||||
|
(ty::Invariant, ty::VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
||||||
|
|
||||||
|
Ok(Ty::new_ptr(tcx, ty::TypeAndMut { mutbl: a_mutbl, ty }))
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
|
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
|
||||||
|
if a_mutbl != b_mutbl {
|
||||||
|
return Err(TypeError::Mutability);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (variance, info) = match a_mutbl {
|
||||||
|
hir::Mutability::Not => (ty::Covariant, ty::VarianceDiagInfo::None),
|
||||||
|
hir::Mutability::Mut => {
|
||||||
|
(ty::Invariant, ty::VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let r = relation.relate(a_r, b_r)?;
|
let r = relation.relate(a_r, b_r)?;
|
||||||
let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl };
|
let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?;
|
||||||
let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl };
|
|
||||||
let mt = relate_type_and_mut(relation, a_mt, b_mt, a)?;
|
Ok(Ty::new_ref(tcx, r, ty::TypeAndMut { mutbl: a_mutbl, ty }))
|
||||||
Ok(Ty::new_ref(tcx, r, mt))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user