@@ -50,8 +50,8 @@ pub(super) fn check_trait<'tcx>(
50
50
. check ( lang_items. dispatch_from_dyn_trait ( ) , visit_implementation_of_dispatch_from_dyn) ?;
51
51
checker. check ( lang_items. pointer_like ( ) , visit_implementation_of_pointer_like) ?;
52
52
checker. check (
53
- lang_items. coerce_pointee_wellformed_trait ( ) ,
54
- visit_implementation_of_coerce_pointee_wellformed ,
53
+ lang_items. coerce_pointee_validated_trait ( ) ,
54
+ visit_implementation_of_coerce_pointee_validity ,
55
55
) ?;
56
56
Ok ( ( ) )
57
57
}
@@ -795,19 +795,21 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err
795
795
. emit ( ) )
796
796
}
797
797
798
- fn visit_implementation_of_coerce_pointee_wellformed (
798
+ fn visit_implementation_of_coerce_pointee_validity (
799
799
checker : & Checker < ' _ > ,
800
800
) -> Result < ( ) , ErrorGuaranteed > {
801
801
let tcx = checker. tcx ;
802
802
let self_ty = tcx. impl_trait_ref ( checker. impl_def_id ) . unwrap ( ) . instantiate_identity ( ) . self_ty ( ) ;
803
+ let span = tcx. def_span ( checker. impl_def_id ) ;
804
+ if !tcx. is_builtin_derived ( checker. impl_def_id . into ( ) ) {
805
+ return Err ( tcx. dcx ( ) . emit_err ( errors:: CoercePointeeNoUserValidityAssertion { span } ) ) ;
806
+ }
803
807
let ty:: Adt ( def, _args) = self_ty. kind ( ) else {
804
- return Err ( tcx. dcx ( ) . emit_err ( errors:: CoercePointeeNotConcreteType {
805
- span : tcx. def_span ( checker. impl_def_id ) ,
806
- } ) ) ;
808
+ return Err ( tcx. dcx ( ) . emit_err ( errors:: CoercePointeeNotConcreteType { span } ) ) ;
807
809
} ;
808
810
let did = def. did ( ) ;
809
- let span =
810
- if let Some ( local ) = did . as_local ( ) { tcx. source_span ( local ) } else { tcx . def_span ( did) } ;
811
+ // Now get a more precise span of the `struct`.
812
+ let span = tcx. def_span ( did) ;
811
813
if !def. is_struct ( ) {
812
814
return Err ( tcx
813
815
. dcx ( )
0 commit comments