about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-05-06 16:00:21 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-05-06 16:00:21 -0700
commit54430ad53ab00bf86090a8d11844db1c40b2ca24 (patch)
treeb47e2216f7d0b19222d5d91af00d7240f7430074 /src/libsyntax
parentf6a4b5270a0007e950546828a7f6fc7c54354b96 (diff)
downloadrust-54430ad53ab00bf86090a8d11844db1c40b2ca24.tar.gz
rust-54430ad53ab00bf86090a8d11844db1c40b2ca24.zip
review comments: fix typo and add comments
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/lexer/mod.rs2
-rw-r--r--src/libsyntax/parse/mod.rs4
-rw-r--r--src/libsyntax/parse/parser.rs11
-rw-r--r--src/libsyntax/util/parser.rs5
4 files changed, 14 insertions, 8 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index e7d79a647d3..4e5a51bdd9a 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -1918,7 +1918,7 @@ mod tests {
             raw_identifier_spans: Lock::new(Vec::new()),
             registered_diagnostics: Lock::new(ErrorMap::new()),
             buffered_lints: Lock::new(vec![]),
-            abiguous_block_expr_parse: Lock::new(FxHashMap::default()),
+            ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
         }
     }
 
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 0d41a1ff849..0ad60369422 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -50,7 +50,7 @@ pub struct ParseSess {
     /// Contains the spans of block expressions that could have been incomplete based on the
     /// operation token that followed it, but that the parser cannot identify without further
     /// analysis.
-    pub abiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
+    pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
 }
 
 impl ParseSess {
@@ -74,7 +74,7 @@ impl ParseSess {
             included_mod_stack: Lock::new(vec![]),
             source_map,
             buffered_lints: Lock::new(vec![]),
-            abiguous_block_expr_parse: Lock::new(FxHashMap::default()),
+            ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
         }
     }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 66d45f799d9..460d829fc06 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2928,7 +2928,7 @@ impl<'a> Parser<'a> {
                                               self.this_token_descr());
                             let mut err = self.fatal(&msg);
                             let sp = self.sess.source_map().start_point(self.span);
-                            if let Some(sp) = self.sess.abiguous_block_expr_parse.borrow()
+                            if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow()
                                 .get(&sp)
                             {
                                 self.sess.expr_parentheses_needed(&mut err, *sp, None);
@@ -3630,12 +3630,15 @@ impl<'a> Parser<'a> {
                 return Ok(lhs);
             }
             (false, _) => {} // continue parsing the expression
-            (true, Some(AssocOp::Multiply)) | // `{ 42 } *foo = bar;`
+            // An exhaustive check is done in the following block, but these are checked first
+            // because they *are* ambiguous but also reasonable looking incorrect syntax, so we
+            // want to keep their span info to improve diagnostics in these cases in a later stage.
+            (true, Some(AssocOp::Multiply)) | // `{ 42 } *foo = bar;` or `{ 42 } * 3`
             (true, Some(AssocOp::Subtract)) | // `{ 42 } -5`
             (true, Some(AssocOp::Add)) => { // `{ 42 } + 42
                 // These cases are ambiguous and can't be identified in the parser alone
                 let sp = self.sess.source_map().start_point(self.span);
-                self.sess.abiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
+                self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
                 return Ok(lhs);
             }
             (true, Some(ref op)) if !op.can_continue_expr_unambiguously() => {
@@ -4968,7 +4971,7 @@ impl<'a> Parser<'a> {
                         let mut err = self.fatal(&msg);
                         err.span_label(self.span, format!("expected {}", expected));
                         let sp = self.sess.source_map().start_point(self.span);
-                        if let Some(sp) = self.sess.abiguous_block_expr_parse.borrow().get(&sp) {
+                        if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
                             self.sess.expr_parentheses_needed(&mut err, *sp, None);
                         }
                         return Err(err);
diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs
index d76dede8155..828fbaef985 100644
--- a/src/libsyntax/util/parser.rs
+++ b/src/libsyntax/util/parser.rs
@@ -208,6 +208,10 @@ impl AssocOp {
         }
     }
 
+    /// This operator could be used to follow a block unambiguously.
+    ///
+    /// This is used for error recovery at the moment, providing a suggestion to wrap blocks with
+    /// parentheses while having a high degree of confidence on the correctness of the suggestion.
     pub fn can_continue_expr_unambiguously(&self) -> bool {
         use AssocOp::*;
         match self {
@@ -227,7 +231,6 @@ impl AssocOp {
             Colon => true, // `{ 42 }: usize`
             _ => false,
         }
-
     }
 }