@@ -47,7 +47,6 @@ pub(super) fn check_trait<'tcx>(
4747 checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ?;
4848 checker
4949 . check ( lang_items. dispatch_from_dyn_trait ( ) , visit_implementation_of_dispatch_from_dyn) ?;
50- checker. check ( lang_items. pointer_like ( ) , visit_implementation_of_pointer_like) ?;
5150 checker. check (
5251 lang_items. coerce_pointee_validated_trait ( ) ,
5352 visit_implementation_of_coerce_pointee_validity,
@@ -707,104 +706,6 @@ fn infringing_fields_error<'tcx>(
707706 err. emit ( )
708707}
709708
710- fn visit_implementation_of_pointer_like ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
711- let tcx = checker. tcx ;
712- let typing_env = ty:: TypingEnv :: non_body_analysis ( tcx, checker. impl_def_id ) ;
713- let impl_span = tcx. def_span ( checker. impl_def_id ) ;
714- let self_ty = tcx. impl_trait_ref ( checker. impl_def_id ) . unwrap ( ) . instantiate_identity ( ) . self_ty ( ) ;
715-
716- let is_permitted_primitive = match * self_ty. kind ( ) {
717- ty:: Adt ( def, _) => def. is_box ( ) ,
718- ty:: Uint ( ..) | ty:: Int ( ..) | ty:: RawPtr ( ..) | ty:: Ref ( ..) | ty:: FnPtr ( ..) => true ,
719- _ => false ,
720- } ;
721-
722- if is_permitted_primitive
723- && let Ok ( layout) = tcx. layout_of ( typing_env. as_query_input ( self_ty) )
724- && layout. layout . is_pointer_like ( & tcx. data_layout )
725- {
726- return Ok ( ( ) ) ;
727- }
728-
729- let why_disqualified = match * self_ty. kind ( ) {
730- // If an ADT is repr(transparent)
731- ty:: Adt ( self_ty_def, args) => {
732- if self_ty_def. repr ( ) . transparent ( ) {
733- // FIXME(compiler-errors): This should and could be deduplicated into a query.
734- // Find the nontrivial field.
735- let adt_typing_env = ty:: TypingEnv :: non_body_analysis ( tcx, self_ty_def. did ( ) ) ;
736- let nontrivial_field = self_ty_def. all_fields ( ) . find ( |field_def| {
737- let field_ty = tcx. type_of ( field_def. did ) . instantiate_identity ( ) ;
738- !tcx. layout_of ( adt_typing_env. as_query_input ( field_ty) )
739- . is_ok_and ( |layout| layout. layout . is_1zst ( ) )
740- } ) ;
741-
742- if let Some ( nontrivial_field) = nontrivial_field {
743- // Check that the nontrivial field implements `PointerLike`.
744- let nontrivial_field_ty = nontrivial_field. ty ( tcx, args) ;
745- let ( infcx, param_env) = tcx. infer_ctxt ( ) . build_with_typing_env ( typing_env) ;
746- let ocx = ObligationCtxt :: new ( & infcx) ;
747- ocx. register_bound (
748- ObligationCause :: misc ( impl_span, checker. impl_def_id ) ,
749- param_env,
750- nontrivial_field_ty,
751- tcx. require_lang_item ( LangItem :: PointerLike , impl_span) ,
752- ) ;
753- // FIXME(dyn-star): We should regionck this implementation.
754- if ocx. select_all_or_error ( ) . is_empty ( ) {
755- return Ok ( ( ) ) ;
756- } else {
757- format ! (
758- "the field `{field_name}` of {descr} `{self_ty}` \
759- does not implement `PointerLike`",
760- field_name = nontrivial_field. name,
761- descr = self_ty_def. descr( )
762- )
763- }
764- } else {
765- format ! (
766- "the {descr} `{self_ty}` is `repr(transparent)`, \
767- but does not have a non-trivial field (it is zero-sized)",
768- descr = self_ty_def. descr( )
769- )
770- }
771- } else if self_ty_def. is_box ( ) {
772- // If we got here, then the `layout.is_pointer_like()` check failed
773- // and this box is not a thin pointer.
774-
775- String :: from ( "boxes of dynamically-sized types are too large to be `PointerLike`" )
776- } else {
777- format ! (
778- "the {descr} `{self_ty}` is not `repr(transparent)`" ,
779- descr = self_ty_def. descr( )
780- )
781- }
782- }
783- ty:: Ref ( ..) => {
784- // If we got here, then the `layout.is_pointer_like()` check failed
785- // and this reference is not a thin pointer.
786- String :: from ( "references to dynamically-sized types are too large to be `PointerLike`" )
787- }
788- ty:: Dynamic ( ..) | ty:: Foreign ( ..) => {
789- String :: from ( "types of dynamic or unknown size may not implement `PointerLike`" )
790- }
791- _ => {
792- // This is a white lie; it is true everywhere outside the standard library.
793- format ! ( "only user-defined sized types are eligible for `impl PointerLike`" )
794- }
795- } ;
796-
797- Err ( tcx
798- . dcx ( )
799- . struct_span_err (
800- impl_span,
801- "implementation must be applied to type that has the same ABI as a pointer, \
802- or is `repr(transparent)` and whose field is `PointerLike`",
803- )
804- . with_note ( why_disqualified)
805- . emit ( ) )
806- }
807-
808709fn visit_implementation_of_coerce_pointee_validity (
809710 checker : & Checker < ' _ > ,
810711) -> Result < ( ) , ErrorGuaranteed > {
0 commit comments