@@ -1715,8 +1715,11 @@ impl<'a> Parser<'a> {
1715
1715
self . parse_path_segments ( & mut segments, T :: PATH_STYLE , true ) ?;
1716
1716
1717
1717
let span = ty. span . to ( self . prev_span ) ;
1718
- let recovered =
1719
- base. to_recovered ( Some ( QSelf { ty, position : 0 } ) , ast:: Path { segments, span } ) ;
1718
+ let path_span = span. to ( span) ; // use an empty path since `position` == 0
1719
+ let recovered = base. to_recovered (
1720
+ Some ( QSelf { ty, path_span, position : 0 } ) ,
1721
+ ast:: Path { segments, span } ,
1722
+ ) ;
1720
1723
1721
1724
self . diagnostic ( )
1722
1725
. struct_span_err ( span, "missing angle brackets in associated item path" )
@@ -1905,21 +1908,32 @@ impl<'a> Parser<'a> {
1905
1908
/// `qualified_path = <type [as trait_ref]>::path`
1906
1909
///
1907
1910
/// # Examples
1911
+ /// `<T>::default`
1908
1912
/// `<T as U>::a`
1909
1913
/// `<T as U>::F::a<S>` (without disambiguator)
1910
1914
/// `<T as U>::F::a::<S>` (with disambiguator)
1911
1915
fn parse_qpath ( & mut self , style : PathStyle ) -> PResult < ' a , ( QSelf , ast:: Path ) > {
1912
1916
let lo = self . prev_span ;
1913
1917
let ty = self . parse_ty ( ) ?;
1914
- let mut path = if self . eat_keyword ( keywords:: As ) {
1915
- self . parse_path ( PathStyle :: Type ) ?
1918
+
1919
+ // `path` will contain the prefix of the path up to the `>`,
1920
+ // if any (e.g., `U` in the `<T as U>::*` examples
1921
+ // above). `path_span` has the span of that path, or an empty
1922
+ // span in the case of something like `<T>::Bar`.
1923
+ let ( mut path, path_span) ;
1924
+ if self . eat_keyword ( keywords:: As ) {
1925
+ let path_lo = self . span ;
1926
+ path = self . parse_path ( PathStyle :: Type ) ?;
1927
+ path_span = path_lo. to ( self . prev_span ) ;
1916
1928
} else {
1917
- ast:: Path { segments : Vec :: new ( ) , span : syntax_pos:: DUMMY_SP }
1918
- } ;
1929
+ path = ast:: Path { segments : Vec :: new ( ) , span : syntax_pos:: DUMMY_SP } ;
1930
+ path_span = self . span . to ( self . span ) ;
1931
+ }
1932
+
1919
1933
self . expect ( & token:: Gt ) ?;
1920
1934
self . expect ( & token:: ModSep ) ?;
1921
1935
1922
- let qself = QSelf { ty, position : path. segments . len ( ) } ;
1936
+ let qself = QSelf { ty, path_span , position : path. segments . len ( ) } ;
1923
1937
self . parse_path_segments ( & mut path. segments , style, true ) ?;
1924
1938
1925
1939
Ok ( ( qself, ast:: Path { segments : path. segments , span : lo. to ( self . prev_span ) } ) )
0 commit comments