@@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
55use rustc_hir:: def:: { DefKind , Res } ;
66use rustc_hir:: def_id:: DefId ;
77use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
8- use rustc_hir:: { /* ExprKind, */ GenericParam , GenericParamKind , HirId } ;
8+ use rustc_hir:: { ExprKind , GenericParam , GenericParamKind , HirId } ;
99use rustc_middle:: ty:: TyCtxt ;
1010use rustc_span:: Span ;
1111
@@ -20,14 +20,14 @@ crate fn collect_spans_and_sources(
2020 krate : clean:: Crate ,
2121 src_root : & std:: path:: Path ,
2222 include_sources : bool ,
23- generate_link_to_definition : bool ,
23+ _generate_link_to_definition : bool ,
2424) -> ( clean:: Crate , FxHashMap < std:: path:: PathBuf , String > , FxHashMap < ( u32 , u32 ) , LinkFromSrc > ) {
2525 let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
2626
2727 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+ // }
3131 let ( krate, sources) = sources:: collect_local_sources ( tcx, src_root, krate) ;
3232 ( krate, sources, visitor. matches )
3333 } else {
@@ -94,17 +94,37 @@ impl Visitor<'tcx> for SpanMapVisitor<'tcx> {
9494 intravisit:: walk_path ( self , path) ;
9595 }
9696
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+ }
108128
109129 fn visit_use ( & mut self , path : & ' tcx rustc_hir:: Path < ' tcx > , id : HirId ) {
110130 self . handle_path ( path, None ) ;
0 commit comments