4
4
use std:: ops:: ControlFlow ;
5
5
6
6
use rustc_hir:: { def:: DefKind , def_id:: LocalDefId } ;
7
- use rustc_middle:: ty:: { self , TyCtxt } ;
7
+ use rustc_middle:: ty:: TyCtxt ;
8
8
use rustc_span:: Span ;
9
9
use rustc_type_ir:: visit:: TypeVisitable ;
10
10
@@ -25,24 +25,9 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
25
25
let kind = tcx. def_kind ( item) ;
26
26
trace ! ( ?kind) ;
27
27
match kind {
28
- DefKind :: Coroutine => {
29
- match tcx. type_of ( item) . instantiate_identity ( ) . kind ( ) {
30
- ty:: Coroutine ( _, args, _) => visitor. visit ( tcx. def_span ( item) , args. as_coroutine ( ) . sig ( ) ) ?,
31
- _ => bug ! ( ) ,
32
- }
33
- for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
34
- visitor. visit ( span, pred) ?;
35
- }
36
- }
37
- // Walk over the signature of the function-like
38
- DefKind :: Closure | DefKind :: AssocFn | DefKind :: Fn => {
39
- let ty_sig = match kind {
40
- DefKind :: Closure => match tcx. type_of ( item) . instantiate_identity ( ) . kind ( ) {
41
- ty:: Closure ( _, args) => args. as_closure ( ) . sig ( ) ,
42
- _ => bug ! ( ) ,
43
- } ,
44
- _ => tcx. fn_sig ( item) . instantiate_identity ( ) ,
45
- } ;
28
+ // Walk over the signature of the function
29
+ DefKind :: AssocFn | DefKind :: Fn => {
30
+ let ty_sig = tcx. fn_sig ( item) . instantiate_identity ( ) ;
46
31
let hir_sig = tcx. hir ( ) . get_by_def_id ( item) . fn_decl ( ) . unwrap ( ) ;
47
32
// Walk over the inputs and outputs manually in order to get good spans for them.
48
33
visitor. visit ( hir_sig. output . span ( ) , ty_sig. output ( ) ) ;
@@ -61,7 +46,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
61
46
Some ( ty) => ty. span ,
62
47
_ => tcx. def_span ( item) ,
63
48
} ;
64
- visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
49
+ visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
65
50
for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
66
51
visitor. visit ( span, pred) ?;
67
52
}
@@ -74,13 +59,15 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
74
59
// Look at field types
75
60
DefKind :: Struct | DefKind :: Union | DefKind :: Enum => {
76
61
let span = tcx. def_ident_span ( item) . unwrap ( ) ;
77
- visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
62
+ visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
78
63
for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
79
64
visitor. visit ( span, pred) ?;
80
65
}
81
66
}
82
- // Does not have a syntactical signature
83
- DefKind :: InlineConst => { }
67
+ // These are not part of a public API, they can only appear as hidden types, and there
68
+ // the interesting parts are solely in the signature of the containing item's opaque type
69
+ // or dyn type.
70
+ DefKind :: InlineConst | DefKind :: Closure | DefKind :: Coroutine => { }
84
71
DefKind :: Impl { of_trait } => {
85
72
if of_trait {
86
73
let span = tcx. hir ( ) . get_by_def_id ( item) . expect_item ( ) . expect_impl ( ) . of_trait . unwrap ( ) . path . span ;
@@ -92,15 +79,11 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
92
79
_ => tcx. def_span ( item) ,
93
80
} ;
94
81
visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
95
- for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
96
- visitor. visit ( span, pred) ?;
97
- } }
98
- DefKind :: Trait => {
99
82
for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
100
83
visitor. visit ( span, pred) ?;
101
84
}
102
85
}
103
- DefKind :: TraitAlias => {
86
+ DefKind :: TraitAlias | DefKind :: Trait => {
104
87
for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
105
88
visitor. visit ( span, pred) ?;
106
89
}
0 commit comments