@@ -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 , Mod , Node } ;
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,6 +94,25 @@ impl Visitor<'tcx> for SpanMapVisitor<'tcx> {
94
94
intravisit:: walk_path ( self , path) ;
95
95
}
96
96
97
+ fn visit_mod ( & mut self , m : & ' tcx Mod < ' tcx > , span : Span , id : HirId ) {
98
+ // To make the difference between "mod foo {}" and "mod foo;". In case we "import" another
99
+ // file, we want to link to it. Otherwise no need to create a link.
100
+ if !span. overlaps ( m. inner ) {
101
+ // Now that we confirmed it's a file import, we want to get the span for the module
102
+ // name only and not all the "mod foo;".
103
+ if let Some ( node) = self . tcx . hir ( ) . find ( id) {
104
+ match node {
105
+ Node :: Item ( item) => {
106
+ self . matches
107
+ . insert ( span_to_tuple ( item. ident . span ) , LinkFromSrc :: Local ( m. inner ) ) ;
108
+ }
109
+ _ => { }
110
+ }
111
+ }
112
+ }
113
+ intravisit:: walk_mod ( self , m, id) ;
114
+ }
115
+
97
116
fn visit_expr ( & mut self , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
98
117
match expr. kind {
99
118
ExprKind :: MethodCall ( segment, method_span, _, _) => {
0 commit comments