@@ -1715,8 +1715,11 @@ impl<'a> Parser<'a> {
17151715 self . parse_path_segments ( & mut segments, T :: PATH_STYLE , true ) ?;
17161716
17171717 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+ ) ;
17201723
17211724 self . diagnostic ( )
17221725 . struct_span_err ( span, "missing angle brackets in associated item path" )
@@ -1905,21 +1908,32 @@ impl<'a> Parser<'a> {
19051908 /// `qualified_path = <type [as trait_ref]>::path`
19061909 ///
19071910 /// # Examples
1911+ /// `<T>::default`
19081912 /// `<T as U>::a`
19091913 /// `<T as U>::F::a<S>` (without disambiguator)
19101914 /// `<T as U>::F::a::<S>` (with disambiguator)
19111915 fn parse_qpath ( & mut self , style : PathStyle ) -> PResult < ' a , ( QSelf , ast:: Path ) > {
19121916 let lo = self . prev_span ;
19131917 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 ) ;
19161928 } 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+
19191933 self . expect ( & token:: Gt ) ?;
19201934 self . expect ( & token:: ModSep ) ?;
19211935
1922- let qself = QSelf { ty, position : path. segments . len ( ) } ;
1936+ let qself = QSelf { ty, path_span , position : path. segments . len ( ) } ;
19231937 self . parse_path_segments ( & mut path. segments , style, true ) ?;
19241938
19251939 Ok ( ( qself, ast:: Path { segments : path. segments , span : lo. to ( self . prev_span ) } ) )
0 commit comments