1
Fork 0

Make RawPtr take Ty and Mutbl separately

This commit is contained in:
Michael Goulet 2024-03-21 17:33:10 -04:00
parent ff0c31e6b9
commit 7be0dbe772
36 changed files with 111 additions and 112 deletions

View file

@ -937,7 +937,10 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _) => (), // struct(u8, u8, u8, u8) is ok
ty::Array(t, _) if matches!(t.kind(), ty::Param(_)) => (), // pass struct<T>([T; N]) through, let monomorphization catch errors
ty::Array(t, _clen)
if matches!(t.kind(), ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _)) =>
if matches!(
t.kind(),
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_, _)
) =>
{ /* struct([f32; 4]) is ok */ }
_ => {
struct_span_code_err!(

View file

@ -195,7 +195,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
{
Ok(())
}
(&RawPtr(tm_a), &RawPtr(tm_b)) if tm_a.mutbl == tm_b.mutbl => Ok(()),
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
(&Adt(def_a, args_a), &Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => {
if def_a != def_b {
let source_path = tcx.def_path_str(def_a.did());
@ -351,14 +351,17 @@ pub fn coerce_unsized_info<'tcx>(
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
}
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => {
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
}
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
&|ty| Ty::new_imm_ptr(tcx, ty),
),
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => {
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
}
(&ty::RawPtr(ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl(
ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a },
ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b },
&|ty| Ty::new_imm_ptr(tcx, ty),
),
(&ty::Adt(def_a, args_a), &ty::Adt(def_b, args_b))
if def_a.is_struct() && def_b.is_struct() =>

View file

@ -323,7 +323,7 @@ fn emit_orphan_check_error<'tcx>(
let is_foreign =
!trait_ref.def_id.is_local() && matches!(is_target_ty, IsFirstInputType::No);
match &ty.kind() {
match *ty.kind() {
ty::Slice(_) => {
push_to_foreign_or_name(
is_foreign,
@ -354,14 +354,14 @@ fn emit_orphan_check_error<'tcx>(
ty::Alias(ty::Opaque, ..) => {
opaque.push(errors::OnlyCurrentTraitsOpaque { span })
}
ty::RawPtr(ptr_ty) => {
ty::RawPtr(ptr_ty, mutbl) => {
if !self_ty.has_param() {
let mut_key = ptr_ty.mutbl.prefix_str();
let mut_key = mutbl.prefix_str();
sugg = Some(errors::OnlyCurrentTraitsPointerSugg {
wrapper_span: self_ty_span,
struct_span: full_impl_span.shrink_to_lo(),
mut_key,
ptr_ty: ptr_ty.ty,
ptr_ty,
});
}
pointer.push(errors::OnlyCurrentTraitsPointer { span, pointer: ty });

View file

@ -253,8 +253,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_ty(current, typ, variance);
}
ty::RawPtr(ref mt) => {
self.add_constraints_from_mt(current, mt, variance);
ty::RawPtr(ty, mutbl) => {
self.add_constraints_from_mt(current, &ty::TypeAndMut { ty, mutbl }, variance);
}
ty::Tuple(subtys) => {