@@ -230,8 +230,8 @@ impl<'a> SpanUtils<'a> {
230230 // Reparse span and return an owned vector of sub spans of the first limit
231231 // identifier tokens in the given nesting level.
232232 // example with Foo<Bar<T,V>, Bar<T,V>>
233- // Nesting = 0: all idents outside of brackets: Vec< Foo>
234- // Nesting = 1: idents within one level of brackets: Vec< Bar, Bar>
233+ // Nesting = 0: all idents outside of brackets: [ Foo]
234+ // Nesting = 1: idents within one level of brackets: [ Bar, Bar]
235235 pub fn spans_with_brackets ( & self , span : Span , nesting : isize , limit : isize ) -> Vec < Span > {
236236 let mut result: Vec < Span > = vec ! ( ) ;
237237
@@ -260,10 +260,20 @@ impl<'a> SpanUtils<'a> {
260260 token:: BinOp ( token:: Shr ) => -2 ,
261261 _ => 0
262262 } ;
263+
263264 // Ignore the `>::` in `<Type as Trait>::AssocTy`.
265+
266+ // The root cause of this hack is that the AST representation of
267+ // qpaths is horrible. It treats <A as B>::C as a path with two
268+ // segments, B and C and notes that there is also a self type A at
269+ // position 0. Because we don't have spans for individual idents,
270+ // only the whole path, we have to iterate over the tokens in the
271+ // path, trying to pull out the non-nested idents (e.g., avoiding 'a
272+ // in `<A as B<'a>>::C`). So we end up with a span for `B>::C` from
273+ // the start of the first ident to the end of the path.
264274 if !found_ufcs_sep && bracket_count == -1 {
265275 found_ufcs_sep = true ;
266- bracket_count += 1
276+ bracket_count += 1 ;
267277 }
268278 if ts. tok . is_ident ( ) && bracket_count == nesting {
269279 result. push ( self . make_sub_span ( span, Some ( ts. sp ) ) . unwrap ( ) ) ;
@@ -332,7 +342,7 @@ impl<'a> SpanUtils<'a> {
332342 }
333343
334344
335- // Returns a list of the spans of idents in a patch .
345+ // Returns a list of the spans of idents in a path .
336346 // E.g., For foo::bar<x,t>::baz, we return [foo, bar, baz] (well, their spans)
337347 pub fn spans_for_path_segments ( & self , path : & ast:: Path ) -> Vec < Span > {
338348 if generated_code ( path. span ) {
0 commit comments