1
1
use rustc_errors:: ErrorGuaranteed ;
2
+ use rustc_hir:: def:: DefKind ;
2
3
use rustc_hir:: def_id:: DefId ;
3
4
use rustc_infer:: infer:: TyCtxtInferExt ;
4
5
use rustc_middle:: query:: Providers ;
@@ -15,54 +16,48 @@ fn resolve_instance<'tcx>(
15
16
tcx : TyCtxt < ' tcx > ,
16
17
key : ty:: ParamEnvAnd < ' tcx , ( DefId , GenericArgsRef < ' tcx > ) > ,
17
18
) -> Result < Option < Instance < ' tcx > > , ErrorGuaranteed > {
18
- let ( param_env, ( def , args) ) = key. into_parts ( ) ;
19
+ let ( param_env, ( def_id , args) ) = key. into_parts ( ) ;
19
20
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 ) {
21
22
debug ! ( " => associated item, attempting to find impl in param_env {:#?}" , param_env) ;
22
23
resolve_associated_item (
23
24
tcx,
24
- def ,
25
+ def_id ,
25
26
param_env,
26
27
trait_def_id,
27
28
tcx. normalize_erasing_regions ( param_env, args) ,
28
29
)
29
30
} 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 ) ;
32
36
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 ) ,
59
49
}
50
+
51
+ ty:: InstanceDef :: DropGlue ( def_id, Some ( ty) )
52
+ } else {
53
+ debug ! ( " => trivial drop glue" ) ;
54
+ ty:: InstanceDef :: DropGlue ( def_id, None )
60
55
}
61
- _ => {
62
- debug ! ( " => free item" ) ;
63
- ty:: InstanceDef :: Item ( def)
64
- }
56
+ } else {
57
+ debug ! ( " => free item" ) ;
58
+ ty:: InstanceDef :: Item ( def_id)
65
59
} ;
60
+
66
61
Ok ( Some ( Instance { def, args } ) )
67
62
} ;
68
63
debug ! ( "inner_resolve_instance: result={:?}" , result) ;
0 commit comments