@@ -38,33 +38,7 @@ fn resolve_instance_raw<'tcx>(
3838 } else if tcx. is_lang_item ( def_id, LangItem :: DropInPlace ) {
3939 let ty = args. type_at ( 0 ) ;
4040
41- if ty. needs_drop ( tcx, typing_env) {
42- debug ! ( " => nontrivial drop glue" ) ;
43- match * ty. kind ( ) {
44- ty:: Coroutine ( coroutine_def_id, ..) => {
45- // FIXME: sync drop of coroutine with async drop (generate both versions?)
46- // Currently just ignored
47- if tcx. optimized_mir ( coroutine_def_id) . coroutine_drop_async ( ) . is_some ( ) {
48- ty:: InstanceKind :: DropGlue ( def_id, None )
49- } else {
50- ty:: InstanceKind :: DropGlue ( def_id, Some ( ty) )
51- }
52- }
53- ty:: Closure ( ..)
54- | ty:: CoroutineClosure ( ..)
55- | ty:: Tuple ( ..)
56- | ty:: Adt ( ..)
57- | ty:: Dynamic ( ..)
58- | ty:: Array ( ..)
59- | ty:: Slice ( ..)
60- | ty:: UnsafeBinder ( ..) => ty:: InstanceKind :: DropGlue ( def_id, Some ( ty) ) ,
61- // Drop shims can only be built from ADTs.
62- _ => return Ok ( None ) ,
63- }
64- } else {
65- debug ! ( " => trivial drop glue" ) ;
66- ty:: InstanceKind :: DropGlue ( def_id, None )
67- }
41+ return ty:: Instance :: try_resolve_drop_in_place ( tcx, typing_env, ty) ;
6842 } else if tcx. is_lang_item ( def_id, LangItem :: AsyncDropInPlace ) {
6943 let ty = args. type_at ( 0 ) ;
7044
@@ -166,6 +140,20 @@ fn resolve_associated_item<'tcx>(
166140 if !eligible {
167141 return Ok ( None ) ;
168142 }
143+ if tcx. is_lang_item ( trait_ref. def_id , LangItem :: Destruct ) {
144+ if !tcx. is_lang_item ( trait_item_id, LangItem :: DestructDropInPlace ) {
145+ bug ! (
146+ "unexpected associated item for built-in `{trait_ref}`: {}" ,
147+ tcx. item_name( trait_item_id)
148+ ) ;
149+ }
150+
151+ debug ! ( "Got user Destruct impl" ) ;
152+ return Ok ( Some ( Instance {
153+ def : ty:: InstanceKind :: Item ( leaf_def. item . def_id ) ,
154+ args : rcvr_args,
155+ } ) ) ;
156+ }
169157
170158 let typing_env = typing_env. with_post_analysis_normalized ( tcx) ;
171159 let ( infcx, param_env) = tcx. infer_ctxt ( ) . build_with_typing_env ( typing_env) ;
@@ -403,6 +391,46 @@ fn resolve_associated_item<'tcx>(
403391 } else {
404392 bug ! ( "unexpected associated associated item" )
405393 }
394+ } else if tcx. is_lang_item ( trait_ref. def_id , LangItem :: Destruct ) {
395+ debug ! (
396+ "resolving Destruct for ImplSource::Builtin: {:?}, {:?}, {:?}" ,
397+ typing_env, trait_item_id, rcvr_args
398+ ) ;
399+ if !tcx. is_lang_item ( trait_item_id, LangItem :: DestructDropInPlace ) {
400+ bug ! (
401+ "unexpected associated item for built-in `{trait_ref}`: {}" ,
402+ tcx. item_name( trait_item_id)
403+ ) ;
404+ }
405+
406+ let self_ty = trait_ref. self_ty ( ) ;
407+
408+ let def = if self_ty. needs_drop ( tcx, typing_env) {
409+ match * self_ty. kind ( ) {
410+ ty:: Coroutine ( coroutine_def_id, ..) => {
411+ if tcx. optimized_mir ( coroutine_def_id) . coroutine_drop_async ( ) . is_some ( )
412+ {
413+ ty:: InstanceKind :: DropGlue ( trait_item_id, None )
414+ } else {
415+ ty:: InstanceKind :: DropGlue ( trait_item_id, Some ( self_ty) )
416+ }
417+ }
418+ ty:: Closure ( ..)
419+ | ty:: CoroutineClosure ( ..)
420+ | ty:: Tuple ( ..)
421+ | ty:: Adt ( ..)
422+ | ty:: Dynamic ( ..)
423+ | ty:: Array ( ..)
424+ | ty:: Slice ( ..)
425+ | ty:: UnsafeBinder ( ..) => {
426+ ty:: InstanceKind :: DropGlue ( trait_item_id, Some ( self_ty) )
427+ }
428+ _ => return Ok ( None ) ,
429+ }
430+ } else {
431+ ty:: InstanceKind :: DropGlue ( trait_item_id, None )
432+ } ;
433+ Some ( ty:: Instance { def, args : rcvr_args } )
406434 } else {
407435 Instance :: try_resolve_item_for_coroutine ( tcx, trait_item_id, trait_id, rcvr_args)
408436 }
0 commit comments