@@ -15,7 +15,7 @@ use hir::map::DefPathData;
15
15
use infer:: InferCtxt ;
16
16
use hir:: map as ast_map;
17
17
use traits:: { self , Reveal } ;
18
- use ty:: { self , Ty , AdtKind , TyCtxt , TypeAndMut , TypeFlags , TypeFoldable } ;
18
+ use ty:: { self , Ty , TyCtxt , TypeAndMut , TypeFlags , TypeFoldable } ;
19
19
use ty:: { Disr , ParameterEnvironment } ;
20
20
use ty:: fold:: TypeVisitor ;
21
21
use ty:: layout:: { Layout , LayoutError } ;
@@ -120,9 +120,8 @@ impl IntTypeExt for attr::IntType {
120
120
121
121
122
122
#[ derive( Copy , Clone ) ]
123
- pub enum CopyImplementationError {
124
- InfrigingField ( Name ) ,
125
- InfrigingVariant ( Name ) ,
123
+ pub enum CopyImplementationError < ' tcx > {
124
+ InfrigingField ( & ' tcx ty:: FieldDef ) ,
126
125
NotAnAdt ,
127
126
HasDestructor
128
127
}
@@ -145,7 +144,7 @@ pub enum Representability {
145
144
impl < ' tcx > ParameterEnvironment < ' tcx > {
146
145
pub fn can_type_implement_copy < ' a > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
147
146
self_type : Ty < ' tcx > , span : Span )
148
- -> Result < ( ) , CopyImplementationError > {
147
+ -> Result < ( ) , CopyImplementationError > {
149
148
// FIXME: (@jroesch) float this code up
150
149
tcx. infer_ctxt ( None , Some ( self . clone ( ) ) , Reveal :: NotSpecializable ) . enter ( |infcx| {
151
150
let ( adt, substs) = match self_type. sty {
@@ -161,23 +160,10 @@ impl<'tcx> ParameterEnvironment<'tcx> {
161
160
}
162
161
} ;
163
162
164
- match adt. adt_kind ( ) {
165
- AdtKind :: Struct | AdtKind :: Union => {
166
- for field in adt. all_fields ( ) {
167
- if !field_implements_copy ( field) {
168
- return Err ( CopyImplementationError :: InfrigingField (
169
- field. name ) )
170
- }
171
- }
172
- }
173
- AdtKind :: Enum => {
174
- for variant in & adt. variants {
175
- for field in & variant. fields {
176
- if !field_implements_copy ( field) {
177
- return Err ( CopyImplementationError :: InfrigingVariant (
178
- variant. name ) )
179
- }
180
- }
163
+ for variant in & adt. variants {
164
+ for field in & variant. fields {
165
+ if !field_implements_copy ( field) {
166
+ return Err ( CopyImplementationError :: InfrigingField ( field) ) ;
181
167
}
182
168
}
183
169
}
0 commit comments