@@ -284,32 +284,32 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
284
284
// structs and enums.
285
285
self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
286
286
287
- // For other types, we'll use the builtin rules.
288
- let copy_conditions = self . copy_clone_conditions ( obligation) ;
289
- self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ;
290
- } else if lang_items. discriminant_kind_trait ( ) == Some ( def_id) {
291
- // `DiscriminantKind` is automatically implemented for every type.
292
- candidates. vec . push ( DiscriminantKindCandidate ) ;
293
- } else if lang_items. pointee_trait ( ) == Some ( def_id) {
294
- // `Pointee` is automatically implemented for every type.
295
- candidates. vec . push ( PointeeCandidate ) ;
296
- } else if lang_items. sized_trait ( ) == Some ( def_id) {
297
- // Sized is never implementable by end-users, it is
298
- // always automatically computed.
299
- let sized_conditions = self . sized_conditions ( obligation) ;
300
- self . assemble_builtin_bound_candidates ( sized_conditions, & mut candidates) ;
301
- } else if lang_items. unsize_trait ( ) == Some ( def_id) {
302
- self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
303
- } else if lang_items. drop_trait ( ) == Some ( def_id)
304
- && obligation. predicate . skip_binder ( ) . constness == ty:: BoundConstness :: ConstIfConst
305
- {
306
- if self . is_in_const_context {
307
- self . assemble_const_drop_candidates ( obligation, & mut candidates) ?;
308
- } else {
309
- debug ! ( "passing ~const Drop bound; in non-const context" ) ;
310
- // `~const Drop` when we are not in a const context has no effect.
311
- candidates. vec . push ( ConstDropCandidate )
312
- }
287
+ // For other types, we'll use the builtin rules.
288
+ let copy_conditions = self . copy_clone_conditions ( obligation) ;
289
+ self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ;
290
+ } else if lang_items. discriminant_kind_trait ( ) == Some ( def_id) {
291
+ // `DiscriminantKind` is automatically implemented for every type.
292
+ candidates. vec . push ( DiscriminantKindCandidate ) ;
293
+ } else if lang_items. pointee_trait ( ) == Some ( def_id) {
294
+ // `Pointee` is automatically implemented for every type.
295
+ candidates. vec . push ( PointeeCandidate ) ;
296
+ } else if lang_items. sized_trait ( ) == Some ( def_id) {
297
+ // Sized is never implementable by end-users, it is
298
+ // always automatically computed.
299
+ let sized_conditions = self . sized_conditions ( obligation) ;
300
+ self . assemble_builtin_bound_candidates ( sized_conditions, & mut candidates) ;
301
+ } else if lang_items. unsize_trait ( ) == Some ( def_id) {
302
+ self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
303
+ } else if lang_items. drop_trait ( ) == Some ( def_id)
304
+ && obligation. predicate . skip_binder ( ) . constness == ty:: BoundConstness :: ConstIfConst
305
+ {
306
+ if self . is_in_const_context {
307
+ self . assemble_const_drop_candidates ( obligation, stack , & mut candidates) ?;
308
+ } else {
309
+ debug ! ( "passing ~const Drop bound; in non-const context" ) ;
310
+ // `~const Drop` when we are not in a const context has no effect.
311
+ candidates. vec . push ( ConstDropCandidate )
312
+ }
313
313
} else {
314
314
if lang_items. clone_trait ( ) == Some ( def_id) {
315
315
// Same builtin conditions as `Copy`, i.e., every type which has builtin support
@@ -911,9 +911,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
911
911
}
912
912
}
913
913
914
- fn assemble_const_drop_candidates (
914
+ fn assemble_const_drop_candidates < ' a > (
915
915
& mut self ,
916
916
obligation : & TraitObligation < ' tcx > ,
917
+ obligation_stack : & TraitObligationStack < ' a , ' tcx > ,
917
918
candidates : & mut SelectionCandidateSet < ' tcx > ,
918
919
) -> Result < ( ) , SelectionError < ' tcx > > {
919
920
let mut stack: Vec < ( Ty < ' tcx > , usize ) > = vec ! [ ( obligation. self_ty( ) . skip_binder( ) , 0 ) ] ;
@@ -922,7 +923,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
922
923
let mut noreturn = false ;
923
924
924
925
self . check_recursion_depth ( depth, obligation) ?;
925
- let mut copy_candidates = SelectionCandidateSet { vec : Vec :: new ( ) , ambiguous : false } ;
926
+ let mut new_candidates = SelectionCandidateSet { vec : Vec :: new ( ) , ambiguous : false } ;
926
927
let mut copy_obligation =
927
928
obligation. with ( obligation. predicate . rebind ( ty:: TraitPredicate {
928
929
trait_ref : ty:: TraitRef {
@@ -933,13 +934,28 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
933
934
polarity : ty:: ImplPolarity :: Positive ,
934
935
} ) ) ;
935
936
copy_obligation. recursion_depth = depth + 1 ;
936
- self . assemble_candidates_from_impls ( & copy_obligation, & mut copy_candidates ) ;
937
+ self . assemble_candidates_from_impls ( & copy_obligation, & mut new_candidates ) ;
937
938
let copy_conditions = self . copy_clone_conditions ( & copy_obligation) ;
938
- self . assemble_builtin_bound_candidates ( copy_conditions, & mut copy_candidates) ;
939
- if !copy_candidates. vec . is_empty ( ) {
939
+ self . assemble_builtin_bound_candidates ( copy_conditions, & mut new_candidates) ;
940
+ let copy_stack = self . push_stack ( obligation_stack. list ( ) , & copy_obligation) ;
941
+ self . assemble_candidates_from_caller_bounds ( & copy_stack, & mut new_candidates) ?;
942
+
943
+ let const_drop_obligation =
944
+ obligation. with ( obligation. predicate . rebind ( ty:: TraitPredicate {
945
+ trait_ref : ty:: TraitRef {
946
+ def_id : self . tcx ( ) . require_lang_item ( hir:: LangItem :: Drop , None ) ,
947
+ substs : self . tcx ( ) . mk_substs_trait ( ty, & [ ] ) ,
948
+ } ,
949
+ constness : ty:: BoundConstness :: ConstIfConst ,
950
+ } ) ) ;
951
+
952
+ let const_drop_stack = self . push_stack ( obligation_stack. list ( ) , & const_drop_obligation) ;
953
+ self . assemble_candidates_from_caller_bounds ( & const_drop_stack, & mut new_candidates) ?;
954
+
955
+ if !new_candidates. vec . is_empty ( ) {
940
956
noreturn = true ;
941
957
}
942
- debug ! ( ?copy_candidates . vec, "assemble_const_drop_candidates - copy " ) ;
958
+ debug ! ( ?new_candidates . vec, "assemble_const_drop_candidates" ) ;
943
959
944
960
match ty. kind ( ) {
945
961
ty:: Int ( _)
0 commit comments