@@ -70,23 +70,21 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
7070 let self_type = tcx. type_of ( impl_did) ;
7171 debug ! ( "visit_implementation_of_copy: self_type={:?} (bound)" , self_type) ;
7272
73- let span = tcx. hir ( ) . span ( impl_hir_id) ;
7473 let param_env = tcx. param_env ( impl_did) ;
7574 assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
7675
7776 debug ! ( "visit_implementation_of_copy: self_type={:?} (free)" , self_type) ;
7877
78+ let span = match tcx. hir ( ) . expect_item ( impl_did) . kind {
79+ ItemKind :: Impl ( hir:: Impl { polarity : hir:: ImplPolarity :: Negative ( _) , .. } ) => return ,
80+ ItemKind :: Impl ( impl_) => impl_. self_ty . span ,
81+ _ => bug ! ( "expected Copy impl item" ) ,
82+ } ;
83+
7984 let cause = traits:: ObligationCause :: misc ( span, impl_hir_id) ;
8085 match can_type_implement_copy ( tcx, param_env, self_type, cause) {
8186 Ok ( ( ) ) => { }
8287 Err ( CopyImplementationError :: InfrigingFields ( fields) ) => {
83- let item = tcx. hir ( ) . expect_item ( impl_did) ;
84- let span = if let ItemKind :: Impl ( hir:: Impl { of_trait : Some ( ref tr) , .. } ) = item. kind {
85- tr. path . span
86- } else {
87- span
88- } ;
89-
9088 let mut err = struct_span_err ! (
9189 tcx. sess,
9290 span,
@@ -166,10 +164,6 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
166164 err. emit ( ) ;
167165 }
168166 Err ( CopyImplementationError :: NotAnAdt ) => {
169- let item = tcx. hir ( ) . expect_item ( impl_did) ;
170- let span =
171- if let ItemKind :: Impl ( ref impl_) = item. kind { impl_. self_ty . span } else { span } ;
172-
173167 tcx. sess . emit_err ( CopyImplOnNonAdt { span } ) ;
174168 }
175169 Err ( CopyImplementationError :: HasDestructor ) => {
0 commit comments