File tree 1 file changed +18
-3
lines changed
src/librustdoc/html/render
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -45,9 +45,9 @@ pub(crate) fn collect_spans_and_sources(
45
45
include_sources : bool ,
46
46
generate_link_to_definition : bool ,
47
47
) -> ( FxIndexMap < PathBuf , String > , FxHashMap < Span , LinkFromSrc > ) {
48
- let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
49
-
50
48
if include_sources {
49
+ let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
50
+
51
51
if generate_link_to_definition {
52
52
tcx. hir ( ) . walk_toplevel_module ( & mut visitor) ;
53
53
}
@@ -76,7 +76,22 @@ impl<'tcx> SpanMapVisitor<'tcx> {
76
76
} else {
77
77
LinkFromSrc :: External ( def_id)
78
78
} ;
79
- self . matches . insert ( path. span , link) ;
79
+ // In case the path ends with generics, we remove them from the span.
80
+ let span = path
81
+ . segments
82
+ . last ( )
83
+ . map ( |last| {
84
+ // In `use` statements, the included item is not in the path segments.
85
+ // However, it doesn't matter because you can't have generics on `use`
86
+ // statements.
87
+ if path. span . contains ( last. ident . span ) {
88
+ path. span . with_hi ( last. ident . span . hi ( ) )
89
+ } else {
90
+ path. span
91
+ }
92
+ } )
93
+ . unwrap_or ( path. span ) ;
94
+ self . matches . insert ( span, link) ;
80
95
}
81
96
Res :: Local ( _) => {
82
97
if let Some ( span) = self . tcx . hir ( ) . res_span ( path. res ) {
You can’t perform that action at this time.
0 commit comments