@@ -17,8 +17,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan, SpanSnippetError};
1717use log:: { debug, trace} ;
1818use std:: mem;
1919
20- const TURBOFISH : & ' static str = "use the \" turbofish\" `::<...>` instead of `<...>` to specify \
21- type arguments";
20+ const TURBOFISH : & ' static str = "use `::<...>` instead of `<...>` to specify type arguments" ;
2221/// Creates a placeholder argument.
2322crate fn dummy_arg ( ident : Ident ) -> Param {
2423 let pat = P ( Pat {
@@ -585,7 +584,7 @@ impl<'a> Parser<'a> {
585584 ) ;
586585
587586 let suggest = |err : & mut DiagnosticBuilder < ' _ > | {
588- err. span_suggestion (
587+ err. span_suggestion_verbose (
589588 op_span. shrink_to_lo ( ) ,
590589 TURBOFISH ,
591590 "::" . to_string ( ) ,
@@ -647,29 +646,16 @@ impl<'a> Parser<'a> {
647646 // We have high certainty that this was a bad turbofish at this point.
648647 // `foo< bar >(`
649648 suggest ( & mut err) ;
650-
651- let snapshot = self . clone ( ) ;
652- self . bump ( ) ; // `(`
653-
654649 // Consume the fn call arguments.
655- let modifiers = [
656- ( token:: OpenDelim ( token:: Paren ) , 1 ) ,
657- ( token:: CloseDelim ( token:: Paren ) , -1 ) ,
658- ] ;
659- self . consume_tts ( 1 , & modifiers[ ..] ) ;
660-
661- if self . token . kind == token:: Eof {
662- // Not entirely sure now, but we bubble the error up with the
663- // suggestion.
664- mem:: replace ( self , snapshot) ;
665- Err ( err)
666- } else {
667- // 99% certain that the suggestion is correct, continue parsing.
668- err. emit ( ) ;
669- // FIXME: actually check that the two expressions in the binop are
670- // paths and resynthesize new fn call expression instead of using
671- // `ExprKind::Err` placeholder.
672- mk_err_expr ( self , lhs. span . to ( self . prev_span ) )
650+ match self . consume_fn_args ( ) {
651+ Err ( ( ) ) => Err ( err) ,
652+ Ok ( ( ) ) => {
653+ err. emit ( ) ;
654+ // FIXME: actually check that the two expressions in the binop are
655+ // paths and resynthesize new fn call expression instead of using
656+ // `ExprKind::Err` placeholder.
657+ mk_err_expr ( self , lhs. span . to ( self . prev_span ) )
658+ }
673659 }
674660 } else {
675661 // All we know is that this is `foo < bar >` and *nothing* else. Try to
@@ -687,6 +673,27 @@ impl<'a> Parser<'a> {
687673 Ok ( None )
688674 }
689675
676+ fn consume_fn_args ( & mut self ) -> Result < ( ) , ( ) > {
677+ let snapshot = self . clone ( ) ;
678+ self . bump ( ) ; // `(`
679+
680+ // Consume the fn call arguments.
681+ let modifiers = [
682+ ( token:: OpenDelim ( token:: Paren ) , 1 ) ,
683+ ( token:: CloseDelim ( token:: Paren ) , -1 ) ,
684+ ] ;
685+ self . consume_tts ( 1 , & modifiers[ ..] ) ;
686+
687+ if self . token . kind == token:: Eof {
688+ // Not entirely sure that what we consumed were fn arguments, rollback.
689+ mem:: replace ( self , snapshot) ;
690+ Err ( ( ) )
691+ } else {
692+ // 99% certain that the suggestion is correct, continue parsing.
693+ Ok ( ( ) )
694+ }
695+ }
696+
690697 crate fn maybe_report_ambiguous_plus (
691698 & mut self ,
692699 allow_plus : bool ,
0 commit comments