@@ -70,23 +70,21 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
70
70
let self_type = tcx. type_of ( impl_did) ;
71
71
debug ! ( "visit_implementation_of_copy: self_type={:?} (bound)" , self_type) ;
72
72
73
- let span = tcx. hir ( ) . span ( impl_hir_id) ;
74
73
let param_env = tcx. param_env ( impl_did) ;
75
74
assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
76
75
77
76
debug ! ( "visit_implementation_of_copy: self_type={:?} (free)" , self_type) ;
78
77
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
+
79
84
let cause = traits:: ObligationCause :: misc ( span, impl_hir_id) ;
80
85
match can_type_implement_copy ( tcx, param_env, self_type, cause) {
81
86
Ok ( ( ) ) => { }
82
87
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
-
90
88
let mut err = struct_span_err ! (
91
89
tcx. sess,
92
90
span,
@@ -166,10 +164,6 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
166
164
err. emit ( ) ;
167
165
}
168
166
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
-
173
167
tcx. sess . emit_err ( CopyImplOnNonAdt { span } ) ;
174
168
}
175
169
Err ( CopyImplementationError :: HasDestructor ) => {
0 commit comments