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