@@ -88,6 +88,13 @@ impl<'ctx, 'gen> CannotDeriveCopy<'ctx, 'gen> {
88
88
89
89
ConstrainResult :: Changed
90
90
}
91
+
92
+ /// A type is not `Copy` if we've determined it is not copy, or if it is
93
+ /// blacklisted.
94
+ fn is_not_copy ( & self , id : ItemId ) -> bool {
95
+ self . cannot_derive_copy . contains ( & id) ||
96
+ !self . ctx . whitelisted_items ( ) . contains ( & id)
97
+ }
91
98
}
92
99
93
100
impl < ' ctx , ' gen > MonotoneFramework for CannotDeriveCopy < ' ctx , ' gen > {
@@ -118,6 +125,15 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
118
125
return ConstrainResult :: Same ;
119
126
}
120
127
128
+ // If an item is reachable from the whitelisted items set, but isn't
129
+ // itself whitelisted, then it must be blacklisted. We assume that
130
+ // blacklisted items are not `Copy`, since they are presumably
131
+ // blacklisted because they are too complicated for us to understand.
132
+ if !self . ctx . whitelisted_items ( ) . contains ( & id) {
133
+ trace ! ( " blacklisted items are assumed not to be Copy" ) ;
134
+ return ConstrainResult :: Same ;
135
+ }
136
+
121
137
let item = self . ctx . resolve_item ( id) ;
122
138
let ty = match item. as_type ( ) {
123
139
Some ( ty) => ty,
@@ -163,7 +179,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
163
179
}
164
180
165
181
TypeKind :: Array ( t, len) => {
166
- let cant_derive_copy = self . cannot_derive_copy . contains ( & t) ;
182
+ let cant_derive_copy = self . is_not_copy ( t) ;
167
183
if cant_derive_copy {
168
184
trace ! (
169
185
" arrays of T for which we cannot derive Copy \
@@ -184,7 +200,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
184
200
TypeKind :: ResolvedTypeRef ( t) |
185
201
TypeKind :: TemplateAlias ( t, _) |
186
202
TypeKind :: Alias ( t) => {
187
- let cant_derive_copy = self . cannot_derive_copy . contains ( & t) ;
203
+ let cant_derive_copy = self . is_not_copy ( t) ;
188
204
if cant_derive_copy {
189
205
trace ! (
190
206
" arrays of T for which we cannot derive Copy \
@@ -237,7 +253,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
237
253
238
254
let bases_cannot_derive =
239
255
info. base_members ( ) . iter ( ) . any ( |base| {
240
- self . cannot_derive_copy . contains ( & base. ty )
256
+ self . is_not_copy ( base. ty )
241
257
} ) ;
242
258
if bases_cannot_derive {
243
259
trace ! (
@@ -250,11 +266,11 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
250
266
let fields_cannot_derive =
251
267
info. fields ( ) . iter ( ) . any ( |f| match * f {
252
268
Field :: DataMember ( ref data) => {
253
- self . cannot_derive_copy . contains ( & data. ty ( ) )
269
+ self . is_not_copy ( data. ty ( ) )
254
270
}
255
271
Field :: Bitfields ( ref bfu) => {
256
272
bfu. bitfields ( ) . iter ( ) . any ( |b| {
257
- self . cannot_derive_copy . contains ( & b. ty ( ) )
273
+ self . is_not_copy ( b. ty ( ) )
258
274
} )
259
275
}
260
276
} ) ;
@@ -270,7 +286,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
270
286
TypeKind :: TemplateInstantiation ( ref template) => {
271
287
let args_cannot_derive =
272
288
template. template_arguments ( ) . iter ( ) . any ( |arg| {
273
- self . cannot_derive_copy . contains ( & arg)
289
+ self . is_not_copy ( * arg)
274
290
} ) ;
275
291
if args_cannot_derive {
276
292
trace ! (
@@ -284,8 +300,8 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveCopy<'ctx, 'gen> {
284
300
!template. template_definition( ) . is_opaque( self . ctx, & ( ) ) ,
285
301
"The early ty.is_opaque check should have handled this case"
286
302
) ;
287
- let def_cannot_derive = self . cannot_derive_copy . contains (
288
- & template. template_definition ( ) ,
303
+ let def_cannot_derive = self . is_not_copy (
304
+ template. template_definition ( ) ,
289
305
) ;
290
306
if def_cannot_derive {
291
307
trace ! (
0 commit comments