@@ -1755,7 +1755,7 @@ impl<'a> Parser<'a> {
1755
1755
self . expect ( & token:: ModSep ) ?;
1756
1756
1757
1757
let qself = QSelf { ty, position : path. segments . len ( ) } ;
1758
- self . parse_path_segments ( & mut path. segments , style) ?;
1758
+ self . parse_path_segments ( & mut path. segments , style, true ) ?;
1759
1759
1760
1760
Ok ( ( qself, ast:: Path { segments : path. segments , span : lo. to ( self . prev_span ) } ) )
1761
1761
}
@@ -1770,16 +1770,20 @@ impl<'a> Parser<'a> {
1770
1770
/// `a::b::C::<D>` (with disambiguator)
1771
1771
/// `Fn(Args)` (without disambiguator)
1772
1772
/// `Fn::(Args)` (with disambiguator)
1773
- pub fn parse_path ( & mut self , style : PathStyle ) -> PResult < ' a , ast:: Path >
1774
- {
1773
+ pub fn parse_path ( & mut self , style : PathStyle ) -> PResult < ' a , ast:: Path > {
1774
+ self . parse_path_common ( style, true )
1775
+ }
1776
+
1777
+ pub fn parse_path_common ( & mut self , style : PathStyle , enable_warning : bool )
1778
+ -> PResult < ' a , ast:: Path > {
1775
1779
maybe_whole ! ( self , NtPath , |x| x) ;
1776
1780
1777
1781
let lo = self . meta_var_span . unwrap_or ( self . span ) ;
1778
1782
let mut segments = Vec :: new ( ) ;
1779
1783
if self . eat ( & token:: ModSep ) {
1780
1784
segments. push ( PathSegment :: crate_root ( lo) ) ;
1781
1785
}
1782
- self . parse_path_segments ( & mut segments, style) ?;
1786
+ self . parse_path_segments ( & mut segments, style, enable_warning ) ?;
1783
1787
1784
1788
Ok ( ast:: Path { segments, span : lo. to ( self . prev_span ) } )
1785
1789
}
@@ -1804,18 +1808,19 @@ impl<'a> Parser<'a> {
1804
1808
self . parse_path ( style)
1805
1809
}
1806
1810
1807
- fn parse_path_segments ( & mut self , segments : & mut Vec < PathSegment > , style : PathStyle )
1808
- -> PResult < ' a , ( ) > {
1811
+ fn parse_path_segments ( & mut self , segments : & mut Vec < PathSegment > , style : PathStyle ,
1812
+ enable_warning : bool ) -> PResult < ' a , ( ) > {
1809
1813
loop {
1810
- segments. push ( self . parse_path_segment ( style) ?) ;
1814
+ segments. push ( self . parse_path_segment ( style, enable_warning ) ?) ;
1811
1815
1812
1816
if self . is_import_coupler ( ) || !self . eat ( & token:: ModSep ) {
1813
1817
return Ok ( ( ) ) ;
1814
1818
}
1815
1819
}
1816
1820
}
1817
1821
1818
- fn parse_path_segment ( & mut self , style : PathStyle ) -> PResult < ' a , PathSegment > {
1822
+ fn parse_path_segment ( & mut self , style : PathStyle , enable_warning : bool )
1823
+ -> PResult < ' a , PathSegment > {
1819
1824
let ident_span = self . span ;
1820
1825
let ident = self . parse_path_segment_ident ( ) ?;
1821
1826
@@ -1835,7 +1840,10 @@ impl<'a> Parser<'a> {
1835
1840
&& self . look_ahead ( 1 , |t| is_args_start ( t) ) {
1836
1841
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
1837
1842
let lo = self . span ;
1838
- self . eat ( & token:: ModSep ) ;
1843
+ if self . eat ( & token:: ModSep ) && style == PathStyle :: Type && enable_warning {
1844
+ self . diagnostic ( ) . struct_span_warn ( self . prev_span , "unnecessary path disambiguator" )
1845
+ . span_label ( self . prev_span , "try removing `::`" ) . emit ( ) ;
1846
+ }
1839
1847
1840
1848
let parameters = if self . eat_lt ( ) {
1841
1849
// `<'a, T, A = U>`
@@ -2371,7 +2379,7 @@ impl<'a> Parser<'a> {
2371
2379
2372
2380
// Assuming we have just parsed `.`, continue parsing into an expression.
2373
2381
fn parse_dot_suffix ( & mut self , self_arg : P < Expr > , lo : Span ) -> PResult < ' a , P < Expr > > {
2374
- let segment = self . parse_path_segment ( PathStyle :: Expr ) ?;
2382
+ let segment = self . parse_path_segment ( PathStyle :: Expr , true ) ?;
2375
2383
Ok ( match self . token {
2376
2384
token:: OpenDelim ( token:: Paren ) => {
2377
2385
// Method call `expr.f()`
0 commit comments