@@ -251,6 +251,18 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
251251 // in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent)
252252 // even if they do not carry that attribute.
253253 match ( source. kind ( ) , target. kind ( ) ) {
254+ ( & ty:: Pat ( _, pat_a) , & ty:: Pat ( _, pat_b) ) => {
255+ if pat_a != pat_b {
256+ return Err ( tcx. dcx ( ) . emit_err ( errors:: CoerceSamePatKind {
257+ span,
258+ trait_name,
259+ pat_a : pat_a. to_string ( ) ,
260+ pat_b : pat_b. to_string ( ) ,
261+ } ) ) ;
262+ }
263+ Ok ( ( ) )
264+ }
265+
254266 ( & ty:: Ref ( r_a, _, mutbl_a) , ty:: Ref ( r_b, _, mutbl_b) )
255267 if r_a == * r_b && mutbl_a == * mutbl_b =>
256268 {
@@ -416,6 +428,18 @@ pub(crate) fn coerce_unsized_info<'tcx>(
416428 ( mt_a. ty , mt_b. ty , unsize_trait, None , span)
417429 } ;
418430 let ( source, target, trait_def_id, kind, field_span) = match ( source. kind ( ) , target. kind ( ) ) {
431+ ( & ty:: Pat ( ty_a, pat_a) , & ty:: Pat ( ty_b, pat_b) ) => {
432+ if pat_a != pat_b {
433+ return Err ( tcx. dcx ( ) . emit_err ( errors:: CoerceSamePatKind {
434+ span,
435+ trait_name,
436+ pat_a : pat_a. to_string ( ) ,
437+ pat_b : pat_b. to_string ( ) ,
438+ } ) ) ;
439+ }
440+ ( ty_a, ty_b, coerce_unsized_trait, None , span)
441+ }
442+
419443 ( & ty:: Ref ( r_a, ty_a, mutbl_a) , & ty:: Ref ( r_b, ty_b, mutbl_b) ) => {
420444 infcx. sub_regions ( infer:: RelateObjectBound ( span) , r_b, r_a) ;
421445 let mt_a = ty:: TypeAndMut { ty : ty_a, mutbl : mutbl_a } ;
@@ -715,13 +739,16 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err
715739 let impl_span = tcx. def_span ( checker. impl_def_id ) ;
716740 let self_ty = tcx. impl_trait_ref ( checker. impl_def_id ) . unwrap ( ) . instantiate_identity ( ) . self_ty ( ) ;
717741
718- let is_permitted_primitive = match * self_ty. kind ( ) {
719- ty:: Adt ( def, _) => def. is_box ( ) ,
720- ty:: Uint ( ..) | ty:: Int ( ..) | ty:: RawPtr ( ..) | ty:: Ref ( ..) | ty:: FnPtr ( ..) => true ,
721- _ => false ,
722- } ;
742+ fn is_permitted_primitive ( self_ty : Ty < ' _ > ) -> bool {
743+ match * self_ty. kind ( ) {
744+ ty:: Adt ( def, _) => def. is_box ( ) ,
745+ ty:: Uint ( ..) | ty:: Int ( ..) | ty:: RawPtr ( ..) | ty:: Ref ( ..) | ty:: FnPtr ( ..) => true ,
746+ ty:: Pat ( base, _) => is_permitted_primitive ( base) ,
747+ _ => false ,
748+ }
749+ }
723750
724- if is_permitted_primitive
751+ if is_permitted_primitive ( self_ty )
725752 && let Ok ( layout) = tcx. layout_of ( typing_env. as_query_input ( self_ty) )
726753 && layout. layout . is_pointer_like ( & tcx. data_layout )
727754 {
0 commit comments