]> git.lizzy.rs Git - rust.git/commitdiff
review comments: fix typo and add comments
authorEsteban Küber <esteban@kuber.com.ar>
Mon, 6 May 2019 23:00:21 +0000 (16:00 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 6 May 2019 23:00:21 +0000 (16:00 -0700)
src/librustc_typeck/check/mod.rs
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/mod.rs
src/libsyntax/parse/parser.rs
src/libsyntax/util/parser.rs

index 763d6b898a4849c6e09ed085d27829d58e9d8c09..cc73e1753d4708ae9269bbd9247166c197819535 100644 (file)
@@ -4174,7 +4174,7 @@ fn check_expr_kind(
                                     oprnd_t,
                                 );
                                 let sp = tcx.sess.source_map().start_point(expr.span);
-                                if let Some(sp) = tcx.sess.parse_sess.abiguous_block_expr_parse
+                                if let Some(sp) = tcx.sess.parse_sess.ambiguous_block_expr_parse
                                     .borrow().get(&sp)
                                 {
                                     tcx.sess.parse_sess.expr_parentheses_needed(
index e7d79a647d360034e1ecc7bd2103d35b056ffcc9..4e5a51bdd9afaf2d18b74824f7d8328621b1b4a7 100644 (file)
@@ -1918,7 +1918,7 @@ fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
             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()),
         }
     }
 
index 0d41a1ff84904be31a1c53c71ad242da4f110e24..0ad6036942280e11cebf35522ef3827fa227dfe8 100644 (file)
@@ -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 @@ pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> ParseS
             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()),
         }
     }
 
index 66d45f799d97d50f83c17995d08445f56bb84b7d..460d829fc0676539d98796541b12dfc0634a20ce 100644 (file)
@@ -2928,7 +2928,7 @@ fn parse_bottom_expr(&mut self) -> PResult<'a, P<Expr>> {
                                               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 @@ fn parse_assoc_expr_with(&mut self,
                 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 @@ fn parse_pat_with_range_pat(
                         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);
index d76dede8155a0ddbe23b2eeb922bb3e58f0ccee4..828fbaef98540ed0fcebfd26e00651b56f81e150 100644 (file)
@@ -208,6 +208,10 @@ pub fn to_ast_binop(&self) -> Option<BinOpKind> {
         }
     }
 
+    /// 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 @@ pub fn can_continue_expr_unambiguously(&self) -> bool {
             Colon => true, // `{ 42 }: usize`
             _ => false,
         }
-
     }
 }