@@ -87,6 +87,11 @@ impl<'ctx, 'gen> CannotDeriveDefault<'ctx, 'gen> {
87
87
88
88
ConstrainResult :: Changed
89
89
}
90
+
91
+ fn is_not_default ( & self , id : ItemId ) -> bool {
92
+ self . cannot_derive_default . contains ( & id) ||
93
+ !self . ctx . whitelisted_items ( ) . contains ( & id)
94
+ }
90
95
}
91
96
92
97
impl < ' ctx , ' gen > MonotoneFramework for CannotDeriveDefault < ' ctx , ' gen > {
@@ -153,6 +158,11 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
153
158
return ConstrainResult :: Same ;
154
159
}
155
160
161
+ if !self . ctx . whitelisted_items ( ) . contains ( & id) {
162
+ trace ! ( " blacklisted items pessimistically cannot derive Default" ) ;
163
+ return ConstrainResult :: Same ;
164
+ }
165
+
156
166
let item = self . ctx . resolve_item ( id) ;
157
167
let ty = match item. as_type ( ) {
158
168
Some ( ty) => ty,
@@ -213,7 +223,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
213
223
}
214
224
215
225
TypeKind :: Array ( t, len) => {
216
- if self . cannot_derive_default . contains ( & t) {
226
+ if self . is_not_default ( t) {
217
227
trace ! (
218
228
" arrays of T for which we cannot derive Default \
219
229
also cannot derive Default"
@@ -233,7 +243,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
233
243
TypeKind :: ResolvedTypeRef ( t) |
234
244
TypeKind :: TemplateAlias ( t, _) |
235
245
TypeKind :: Alias ( t) => {
236
- if self . cannot_derive_default . contains ( & t) {
246
+ if self . is_not_default ( t) {
237
247
trace ! (
238
248
" aliases and type refs to T which cannot derive \
239
249
Default also cannot derive Default"
@@ -280,7 +290,7 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
280
290
let bases_cannot_derive =
281
291
info. base_members ( ) . iter ( ) . any ( |base| {
282
292
!self . ctx . whitelisted_items ( ) . contains ( & base. ty ) ||
283
- self . cannot_derive_default . contains ( & base. ty )
293
+ self . is_not_default ( base. ty )
284
294
} ) ;
285
295
if bases_cannot_derive {
286
296
trace ! (
@@ -296,14 +306,14 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
296
306
!self . ctx . whitelisted_items ( ) . contains (
297
307
& data. ty ( ) ,
298
308
) ||
299
- self . cannot_derive_default . contains ( & data. ty ( ) )
309
+ self . is_not_default ( data. ty ( ) )
300
310
}
301
311
Field :: Bitfields ( ref bfu) => {
302
312
bfu. bitfields ( ) . iter ( ) . any ( |b| {
303
313
!self . ctx . whitelisted_items ( ) . contains (
304
314
& b. ty ( ) ,
305
315
) ||
306
- self . cannot_derive_default . contains ( & b. ty ( ) )
316
+ self . is_not_default ( b. ty ( ) )
307
317
} )
308
318
}
309
319
} ) ;
@@ -319,45 +329,34 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDefault<'ctx, 'gen> {
319
329
}
320
330
321
331
TypeKind :: TemplateInstantiation ( ref template) => {
322
- if self . ctx . whitelisted_items ( ) . contains (
323
- & template. template_definition ( ) ,
324
- )
325
- {
326
- let args_cannot_derive =
327
- template. template_arguments ( ) . iter ( ) . any ( |arg| {
328
- self . cannot_derive_default . contains ( & arg)
329
- } ) ;
330
- if args_cannot_derive {
331
- trace ! (
332
- " template args cannot derive Default, so \
333
- insantiation can't either"
334
- ) ;
335
- return self . insert ( id) ;
336
- }
337
-
338
- assert ! (
339
- !template. template_definition( ) . is_opaque( self . ctx, & ( ) ) ,
340
- "The early ty.is_opaque check should have handled this case"
332
+ let args_cannot_derive =
333
+ template. template_arguments ( ) . iter ( ) . any ( |arg| {
334
+ self . is_not_default ( * arg)
335
+ } ) ;
336
+ if args_cannot_derive {
337
+ trace ! (
338
+ " template args cannot derive Default, so \
339
+ insantiation can't either"
341
340
) ;
342
- let def_cannot_derive =
343
- self . cannot_derive_default . contains ( & template
344
- . template_definition ( ) ) ;
345
- if def_cannot_derive {
346
- trace ! (
347
- " template definition cannot derive Default, so \
348
- insantiation can't either"
349
- ) ;
350
- return self . insert ( id) ;
351
- }
341
+ return self . insert ( id) ;
342
+ }
352
343
353
- trace ! ( " template instantiation can derive Default" ) ;
354
- ConstrainResult :: Same
355
- } else {
344
+ assert ! (
345
+ !template. template_definition( ) . is_opaque( self . ctx, & ( ) ) ,
346
+ "The early ty.is_opaque check should have handled this case"
347
+ ) ;
348
+ let def_cannot_derive =
349
+ self . is_not_default ( template. template_definition ( ) ) ;
350
+ if def_cannot_derive {
356
351
trace ! (
357
- " blacklisted template instantiation cannot derive default"
352
+ " template definition cannot derive Default, so \
353
+ insantiation can't either"
358
354
) ;
359
355
return self . insert ( id) ;
360
356
}
357
+
358
+ trace ! ( " template instantiation can derive Default" ) ;
359
+ ConstrainResult :: Same
361
360
}
362
361
363
362
TypeKind :: Opaque => {
0 commit comments