File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
src/librustdoc/html/render Expand file tree Collapse file tree 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(
4545 include_sources : bool ,
4646 generate_link_to_definition : bool ,
4747) -> ( FxIndexMap < PathBuf , String > , FxHashMap < Span , LinkFromSrc > ) {
48- let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
49-
5048 if include_sources {
49+ let mut visitor = SpanMapVisitor { tcx, matches : FxHashMap :: default ( ) } ;
50+
5151 if generate_link_to_definition {
5252 tcx. hir ( ) . walk_toplevel_module ( & mut visitor) ;
5353 }
@@ -76,7 +76,22 @@ impl<'tcx> SpanMapVisitor<'tcx> {
7676 } else {
7777 LinkFromSrc :: External ( def_id)
7878 } ;
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) ;
8095 }
8196 Res :: Local ( _) => {
8297 if let Some ( span) = self . tcx . hir ( ) . res_span ( path. res ) {
You can’t perform that action at this time.
0 commit comments