about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-10-03 13:22:18 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-10-03 13:22:18 -0700
commit02f57f83a9ea5903cb02bdc304800661c8f4296f (patch)
treeb0a392f842107e5b11569fed4e3c09d23577239d /src/libsyntax/parse
parentf1499a864688a484c04c4e53962dc8ec44f79a03 (diff)
downloadrust-02f57f83a9ea5903cb02bdc304800661c8f4296f.tar.gz
rust-02f57f83a9ea5903cb02bdc304800661c8f4296f.zip
review comments
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/diagnostics.rs57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs
index 72206ffb28d..e3abf8ffc6c 100644
--- a/src/libsyntax/parse/diagnostics.rs
+++ b/src/libsyntax/parse/diagnostics.rs
@@ -17,8 +17,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan, SpanSnippetError};
 use log::{debug, trace};
 use std::mem;
 
-const TURBOFISH: &'static str = "use the \"turbofish\" `::<...>` instead of `<...>` to specify \
-                                 type arguments";
+const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify type arguments";
 /// Creates a placeholder argument.
 crate fn dummy_arg(ident: Ident) -> Param {
     let pat = P(Pat {
@@ -585,7 +584,7 @@ impl<'a> Parser<'a> {
                 );
 
                 let suggest = |err: &mut DiagnosticBuilder<'_>| {
-                    err.span_suggestion(
+                    err.span_suggestion_verbose(
                         op_span.shrink_to_lo(),
                         TURBOFISH,
                         "::".to_string(),
@@ -647,29 +646,16 @@ impl<'a> Parser<'a> {
                         // We have high certainty that this was a bad turbofish at this point.
                         // `foo< bar >(`
                         suggest(&mut err);
-
-                        let snapshot = self.clone();
-                        self.bump(); // `(`
-
                         // Consume the fn call arguments.
-                        let modifiers = [
-                            (token::OpenDelim(token::Paren), 1),
-                            (token::CloseDelim(token::Paren), -1),
-                        ];
-                        self.consume_tts(1, &modifiers[..]);
-
-                        if self.token.kind == token::Eof {
-                            // Not entirely sure now, but we bubble the error up with the
-                            // suggestion.
-                            mem::replace(self, snapshot);
-                            Err(err)
-                        } else {
-                            // 99% certain that the suggestion is correct, continue parsing.
-                            err.emit();
-                            // FIXME: actually check that the two expressions in the binop are
-                            // paths and resynthesize new fn call expression instead of using
-                            // `ExprKind::Err` placeholder.
-                            mk_err_expr(self, lhs.span.to(self.prev_span))
+                        match self.consume_fn_args() {
+                            Err(()) => Err(err),
+                            Ok(()) => {
+                                err.emit();
+                                // FIXME: actually check that the two expressions in the binop are
+                                // paths and resynthesize new fn call expression instead of using
+                                // `ExprKind::Err` placeholder.
+                                mk_err_expr(self, lhs.span.to(self.prev_span))
+                            }
                         }
                     } else {
                         // All we know is that this is `foo < bar >` and *nothing* else. Try to
@@ -687,6 +673,27 @@ impl<'a> Parser<'a> {
         Ok(None)
     }
 
+    fn consume_fn_args(&mut self) -> Result<(), ()> {
+        let snapshot = self.clone();
+        self.bump(); // `(`
+
+        // Consume the fn call arguments.
+        let modifiers = [
+            (token::OpenDelim(token::Paren), 1),
+            (token::CloseDelim(token::Paren), -1),
+        ];
+        self.consume_tts(1, &modifiers[..]);
+
+        if self.token.kind == token::Eof {
+            // Not entirely sure that what we consumed were fn arguments, rollback.
+            mem::replace(self, snapshot);
+            Err(())
+        } else {
+            // 99% certain that the suggestion is correct, continue parsing.
+            Ok(())
+        }
+    }
+
     crate fn maybe_report_ambiguous_plus(
         &mut self,
         allow_plus: bool,