@@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
5
5
use rustc_hir:: def:: { DefKind , Res } ;
6
6
use rustc_hir:: def_id:: DefId ;
7
7
use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
8
- use rustc_hir:: { /* ExprKind, */ GenericParam , GenericParamKind , HirId } ;
8
+ use rustc_hir:: { ExprKind , GenericParam , GenericParamKind , HirId } ;
9
9
use rustc_middle:: ty:: TyCtxt ;
10
10
use rustc_span:: Span ;
11
11
@@ -20,14 +20,14 @@ crate fn collect_spans_and_sources(
20
20
krate : clean:: Crate ,
21
21
src_root : & std:: path:: Path ,
22
22
include_sources : bool ,
23
- generate_link_to_definition : bool ,
23
+ _generate_link_to_definition : bool ,
24
24
) -> ( clean:: Crate , FxHashMap < std:: path:: PathBuf , String > , FxHashMap < ( u32 , u32 ) , LinkFromSrc > ) {
25
25
let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
26
26
27
27
if include_sources {
28
- if generate_link_to_definition {
29
- intravisit:: walk_crate ( & mut visitor, tcx. hir ( ) . krate ( ) ) ;
30
- }
28
+ // if generate_link_to_definition {
29
+ intravisit:: walk_crate ( & mut visitor, tcx. hir ( ) . krate ( ) ) ;
30
+ // }
31
31
let ( krate, sources) = sources:: collect_local_sources ( tcx, src_root, krate) ;
32
32
( krate, sources, visitor. matches )
33
33
} else {
@@ -94,17 +94,37 @@ impl Visitor<'tcx> for SpanMapVisitor<'tcx> {
94
94
intravisit:: walk_path ( self , path) ;
95
95
}
96
96
97
- // fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
98
- // match expr.kind {
99
- // ExprKind::MethodCall(segment, method_span, _, _) => {
100
- // if let Some(hir_id) = segment.hir_id {
101
- // // call https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.type_dependent_def_id
102
- // }
103
- // }
104
- // _ => {}
105
- // }
106
- // intravisit::walk_expr(self, expr);
107
- // }
97
+ fn visit_expr ( & mut self , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
98
+ match expr. kind {
99
+ ExprKind :: MethodCall ( segment, method_span, _, _) => {
100
+ if let Some ( hir_id) = segment. hir_id {
101
+ let hir = self . tcx . hir ( ) ;
102
+ let body_id = hir. enclosing_body_owner ( hir_id) ;
103
+ // FIXME: this is showing error messages for parts of the code that are not
104
+ // compiled (because of cfg)!
105
+ let typeck_results = self . tcx . typeck_body (
106
+ hir. maybe_body_owned_by ( body_id) . expect ( "a body which isn't a body" ) ,
107
+ ) ;
108
+ if let Some ( def_id) = typeck_results. type_dependent_def_id ( expr. hir_id ) {
109
+ match hir. span_if_local ( def_id) {
110
+ Some ( span) => {
111
+ self . matches
112
+ . insert ( span_to_tuple ( method_span) , LinkFromSrc :: Local ( span) ) ;
113
+ }
114
+ None => {
115
+ self . matches . insert (
116
+ span_to_tuple ( method_span) ,
117
+ LinkFromSrc :: External ( def_id) ,
118
+ ) ;
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ _ => { }
125
+ }
126
+ intravisit:: walk_expr ( self , expr) ;
127
+ }
108
128
109
129
fn visit_use ( & mut self , path : & ' tcx rustc_hir:: Path < ' tcx > , id : HirId ) {
110
130
self . handle_path ( path, None ) ;
0 commit comments