@@ -131,32 +131,23 @@ impl<'tcx> SpanMapVisitor<'tcx> {
131131 Res :: Def ( kind, def_id) if kind != DefKind :: TyParam => {
132132 let last_segment = path. segments . last ( ) . unwrap ( ) ;
133133 // In case the path ends with generics, we remove them from the span.
134- let span = if only_use_last_segment
135- && let Some ( path_span) = path. segments . last ( ) . map ( |segment| segment. ident . span )
136- {
137- path_span
134+ let span = if only_use_last_segment {
135+ last_segment. ident . span
138136 } else {
139- path. segments
140- . last ( )
141- . map ( |last| {
142- // In `use` statements, the included item is not in the path segments.
143- // However, it doesn't matter because you can't have generics on `use`
144- // statements.
145- if path. span . contains ( last. ident . span ) {
146- path. span . with_hi ( last. ident . span . hi ( ) )
147- } else {
148- path. span
149- }
150- } )
151- . unwrap_or ( path. span )
137+ // In `use` statements, the included item is not in the path segments.
138+ // However, it doesn't matter because you can't have generics on `use`
139+ // statements.
140+ if path. span . contains ( last_segment. ident . span ) {
141+ path. span . with_hi ( last_segment. ident . span . hi ( ) )
142+ } else {
143+ path. span
144+ }
152145 } ;
153146 self . matches . insert ( span. into ( ) , self . link_for_def ( def_id) ) ;
154147 }
155148 Res :: Local ( _) if let Some ( span) = self . tcx . hir_res_span ( path. res ) => {
156- let path_span = if only_use_last_segment
157- && let Some ( path_span) = path. segments . last ( ) . map ( |segment| segment. ident . span )
158- {
159- path_span
149+ let path_span = if only_use_last_segment {
150+ path. segments . last ( ) . unwrap ( ) . ident . span
160151 } else {
161152 path. span
162153 } ;
@@ -167,7 +158,6 @@ impl<'tcx> SpanMapVisitor<'tcx> {
167158 self . matches
168159 . insert ( path. span . into ( ) , LinkFromSrc :: Primitive ( PrimitiveType :: from ( p) ) ) ;
169160 }
170- Res :: Err => { }
171161 _ => { }
172162 }
173163 }
@@ -265,8 +255,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
265255 // We change the span to not include parens.
266256 span : segment. ident . span ,
267257 res : typeck_results. qpath_res ( qpath, id) ,
268- // FIXME(fmease): Don't create a path with zero segments!
269- segments : & [ ] ,
258+ segments : std:: slice:: from_ref ( segment) ,
270259 } ;
271260 self . handle_path ( & path, false ) ;
272261 }
0 commit comments