@@ -230,8 +230,8 @@ impl<'a> SpanUtils<'a> {
230
230
// Reparse span and return an owned vector of sub spans of the first limit
231
231
// identifier tokens in the given nesting level.
232
232
// 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]
235
235
pub fn spans_with_brackets ( & self , span : Span , nesting : isize , limit : isize ) -> Vec < Span > {
236
236
let mut result: Vec < Span > = vec ! ( ) ;
237
237
@@ -260,10 +260,20 @@ impl<'a> SpanUtils<'a> {
260
260
token:: BinOp ( token:: Shr ) => -2 ,
261
261
_ => 0
262
262
} ;
263
+
263
264
// 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.
264
274
if !found_ufcs_sep && bracket_count == -1 {
265
275
found_ufcs_sep = true ;
266
- bracket_count += 1
276
+ bracket_count += 1 ;
267
277
}
268
278
if ts. tok . is_ident ( ) && bracket_count == nesting {
269
279
result. push ( self . make_sub_span ( span, Some ( ts. sp ) ) . unwrap ( ) ) ;
@@ -332,7 +342,7 @@ impl<'a> SpanUtils<'a> {
332
342
}
333
343
334
344
335
- // Returns a list of the spans of idents in a patch .
345
+ // Returns a list of the spans of idents in a path .
336
346
// E.g., For foo::bar<x,t>::baz, we return [foo, bar, baz] (well, their spans)
337
347
pub fn spans_for_path_segments ( & self , path : & ast:: Path ) -> Vec < Span > {
338
348
if generated_code ( path. span ) {
0 commit comments