44use std:: ops:: ControlFlow ;
55
66use rustc_hir:: { def:: DefKind , def_id:: LocalDefId } ;
7- use rustc_middle:: ty:: { self , TyCtxt } ;
7+ use rustc_middle:: ty:: TyCtxt ;
88use rustc_span:: Span ;
99use rustc_type_ir:: visit:: TypeVisitable ;
1010
@@ -25,24 +25,9 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
2525 let kind = tcx. def_kind ( item) ;
2626 trace ! ( ?kind) ;
2727 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 ( ) ;
4631 let hir_sig = tcx. hir ( ) . get_by_def_id ( item) . fn_decl ( ) . unwrap ( ) ;
4732 // Walk over the inputs and outputs manually in order to get good spans for them.
4833 visitor. visit ( hir_sig. output . span ( ) , ty_sig. output ( ) ) ;
@@ -61,7 +46,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
6146 Some ( ty) => ty. span ,
6247 _ => tcx. def_span ( item) ,
6348 } ;
64- visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
49+ visitor. visit ( span, tcx. type_of ( item) . instantiate_identity ( ) ) ;
6550 for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
6651 visitor. visit ( span, pred) ?;
6752 }
@@ -74,13 +59,15 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
7459 // Look at field types
7560 DefKind :: Struct | DefKind :: Union | DefKind :: Enum => {
7661 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 ( ) ) ;
7863 for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
7964 visitor. visit ( span, pred) ?;
8065 }
8166 }
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 => { }
8471 DefKind :: Impl { of_trait } => {
8572 if of_trait {
8673 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>>(
9279 _ => tcx. def_span ( item) ,
9380 } ;
9481 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 => {
9982 for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
10083 visitor. visit ( span, pred) ?;
10184 }
10285 }
103- DefKind :: TraitAlias => {
86+ DefKind :: TraitAlias | DefKind :: Trait => {
10487 for ( pred, span) in tcx. predicates_of ( item) . instantiate_identity ( tcx) {
10588 visitor. visit ( span, pred) ?;
10689 }
0 commit comments