diff options
| author | Michael Goulet <michael@errs.io> | 2024-03-21 17:33:10 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-03-22 11:13:29 -0400 |
| commit | 7be0dbe77292de955da02fe1de1626bdd2e4cc0a (patch) | |
| tree | be790699979e783668fcaca21d48c6982983b13e /compiler/rustc_hir_analysis | |
| parent | ff0c31e6b9bc8e847c3b1b9d61793325edfacf47 (diff) | |
| download | rust-7be0dbe77292de955da02fe1de1626bdd2e4cc0a.tar.gz rust-7be0dbe77292de955da02fe1de1626bdd2e4cc0a.zip | |
Make RawPtr take Ty and Mutbl separately
Diffstat (limited to 'compiler/rustc_hir_analysis')
4 files changed, 22 insertions, 16 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 9ea73913eb6..1286a724e95 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -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!( diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 8d8b13d6cb3..cf32b599e02 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -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::RawPtr(mt_a), &ty::RawPtr(mt_b)) => { - 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(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() => diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index b46a67d08eb..ca8a635ab5e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -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 }); diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 93a0e924099..28c86d8019e 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -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) => { |
