11use rustc_errors:: ErrorGuaranteed ;
2+ use rustc_hir:: def:: DefKind ;
23use rustc_hir:: def_id:: DefId ;
34use rustc_infer:: infer:: TyCtxtInferExt ;
45use rustc_middle:: query:: Providers ;
@@ -15,54 +16,48 @@ fn resolve_instance<'tcx>(
1516 tcx : TyCtxt < ' tcx > ,
1617 key : ty:: ParamEnvAnd < ' tcx , ( DefId , GenericArgsRef < ' tcx > ) > ,
1718) -> Result < Option < Instance < ' tcx > > , ErrorGuaranteed > {
18- let ( param_env, ( def , args) ) = key. into_parts ( ) ;
19+ let ( param_env, ( def_id , args) ) = key. into_parts ( ) ;
1920
20- let result = if let Some ( trait_def_id) = tcx. trait_of_item ( def ) {
21+ let result = if let Some ( trait_def_id) = tcx. trait_of_item ( def_id ) {
2122 debug ! ( " => associated item, attempting to find impl in param_env {:#?}" , param_env) ;
2223 resolve_associated_item (
2324 tcx,
24- def ,
25+ def_id ,
2526 param_env,
2627 trait_def_id,
2728 tcx. normalize_erasing_regions ( param_env, args) ,
2829 )
2930 } else {
30- let ty = tcx. type_of ( def) ;
31- let item_type = tcx. subst_and_normalize_erasing_regions ( args, param_env, ty) ;
31+ let def = if matches ! ( tcx. def_kind( def_id) , DefKind :: Fn ) && tcx. is_intrinsic ( def_id) {
32+ debug ! ( " => intrinsic" ) ;
33+ ty:: InstanceDef :: Intrinsic ( def_id)
34+ } else if Some ( def_id) == tcx. lang_items ( ) . drop_in_place_fn ( ) {
35+ let ty = args. type_at ( 0 ) ;
3236
33- let def = match * item_type. kind ( ) {
34- ty:: FnDef ( def_id, ..) if tcx. is_intrinsic ( def_id) => {
35- debug ! ( " => intrinsic" ) ;
36- ty:: InstanceDef :: Intrinsic ( def)
37- }
38- ty:: FnDef ( def_id, args) if Some ( def_id) == tcx. lang_items ( ) . drop_in_place_fn ( ) => {
39- let ty = args. type_at ( 0 ) ;
40-
41- if ty. needs_drop ( tcx, param_env) {
42- debug ! ( " => nontrivial drop glue" ) ;
43- match * ty. kind ( ) {
44- ty:: Closure ( ..)
45- | ty:: Generator ( ..)
46- | ty:: Tuple ( ..)
47- | ty:: Adt ( ..)
48- | ty:: Dynamic ( ..)
49- | ty:: Array ( ..)
50- | ty:: Slice ( ..) => { }
51- // Drop shims can only be built from ADTs.
52- _ => return Ok ( None ) ,
53- }
54-
55- ty:: InstanceDef :: DropGlue ( def_id, Some ( ty) )
56- } else {
57- debug ! ( " => trivial drop glue" ) ;
58- ty:: InstanceDef :: DropGlue ( def_id, None )
37+ if ty. needs_drop ( tcx, param_env) {
38+ debug ! ( " => nontrivial drop glue" ) ;
39+ match * ty. kind ( ) {
40+ ty:: Closure ( ..)
41+ | ty:: Generator ( ..)
42+ | ty:: Tuple ( ..)
43+ | ty:: Adt ( ..)
44+ | ty:: Dynamic ( ..)
45+ | ty:: Array ( ..)
46+ | ty:: Slice ( ..) => { }
47+ // Drop shims can only be built from ADTs.
48+ _ => return Ok ( None ) ,
5949 }
50+
51+ ty:: InstanceDef :: DropGlue ( def_id, Some ( ty) )
52+ } else {
53+ debug ! ( " => trivial drop glue" ) ;
54+ ty:: InstanceDef :: DropGlue ( def_id, None )
6055 }
61- _ => {
62- debug ! ( " => free item" ) ;
63- ty:: InstanceDef :: Item ( def)
64- }
56+ } else {
57+ debug ! ( " => free item" ) ;
58+ ty:: InstanceDef :: Item ( def_id)
6559 } ;
60+
6661 Ok ( Some ( Instance { def, args } ) )
6762 } ;
6863 debug ! ( "inner_resolve_instance: result={:?}" , result) ;
0 commit comments