Skip to content

Commit 54430ad

Browse files
committed
review comments: fix typo and add comments
1 parent f6a4b52 commit 54430ad

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4174,7 +4174,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41744174
oprnd_t,
41754175
);
41764176
let sp = tcx.sess.source_map().start_point(expr.span);
4177-
if let Some(sp) = tcx.sess.parse_sess.abiguous_block_expr_parse
4177+
if let Some(sp) = tcx.sess.parse_sess.ambiguous_block_expr_parse
41784178
.borrow().get(&sp)
41794179
{
41804180
tcx.sess.parse_sess.expr_parentheses_needed(

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ mod tests {
19181918
raw_identifier_spans: Lock::new(Vec::new()),
19191919
registered_diagnostics: Lock::new(ErrorMap::new()),
19201920
buffered_lints: Lock::new(vec![]),
1921-
abiguous_block_expr_parse: Lock::new(FxHashMap::default()),
1921+
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
19221922
}
19231923
}
19241924

src/libsyntax/parse/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct ParseSess {
5050
/// Contains the spans of block expressions that could have been incomplete based on the
5151
/// operation token that followed it, but that the parser cannot identify without further
5252
/// analysis.
53-
pub abiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
53+
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
5454
}
5555

5656
impl ParseSess {
@@ -74,7 +74,7 @@ impl ParseSess {
7474
included_mod_stack: Lock::new(vec![]),
7575
source_map,
7676
buffered_lints: Lock::new(vec![]),
77-
abiguous_block_expr_parse: Lock::new(FxHashMap::default()),
77+
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
7878
}
7979
}
8080

src/libsyntax/parse/parser.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,7 @@ impl<'a> Parser<'a> {
29282928
self.this_token_descr());
29292929
let mut err = self.fatal(&msg);
29302930
let sp = self.sess.source_map().start_point(self.span);
2931-
if let Some(sp) = self.sess.abiguous_block_expr_parse.borrow()
2931+
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow()
29322932
.get(&sp)
29332933
{
29342934
self.sess.expr_parentheses_needed(&mut err, *sp, None);
@@ -3630,12 +3630,15 @@ impl<'a> Parser<'a> {
36303630
return Ok(lhs);
36313631
}
36323632
(false, _) => {} // continue parsing the expression
3633-
(true, Some(AssocOp::Multiply)) | // `{ 42 } *foo = bar;`
3633+
// An exhaustive check is done in the following block, but these are checked first
3634+
// because they *are* ambiguous but also reasonable looking incorrect syntax, so we
3635+
// want to keep their span info to improve diagnostics in these cases in a later stage.
3636+
(true, Some(AssocOp::Multiply)) | // `{ 42 } *foo = bar;` or `{ 42 } * 3`
36343637
(true, Some(AssocOp::Subtract)) | // `{ 42 } -5`
36353638
(true, Some(AssocOp::Add)) => { // `{ 42 } + 42
36363639
// These cases are ambiguous and can't be identified in the parser alone
36373640
let sp = self.sess.source_map().start_point(self.span);
3638-
self.sess.abiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
3641+
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
36393642
return Ok(lhs);
36403643
}
36413644
(true, Some(ref op)) if !op.can_continue_expr_unambiguously() => {
@@ -4968,7 +4971,7 @@ impl<'a> Parser<'a> {
49684971
let mut err = self.fatal(&msg);
49694972
err.span_label(self.span, format!("expected {}", expected));
49704973
let sp = self.sess.source_map().start_point(self.span);
4971-
if let Some(sp) = self.sess.abiguous_block_expr_parse.borrow().get(&sp) {
4974+
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
49724975
self.sess.expr_parentheses_needed(&mut err, *sp, None);
49734976
}
49744977
return Err(err);

src/libsyntax/util/parser.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ impl AssocOp {
208208
}
209209
}
210210

211+
/// This operator could be used to follow a block unambiguously.
212+
///
213+
/// This is used for error recovery at the moment, providing a suggestion to wrap blocks with
214+
/// parentheses while having a high degree of confidence on the correctness of the suggestion.
211215
pub fn can_continue_expr_unambiguously(&self) -> bool {
212216
use AssocOp::*;
213217
match self {
@@ -227,7 +231,6 @@ impl AssocOp {
227231
Colon => true, // `{ 42 }: usize`
228232
_ => false,
229233
}
230-
231234
}
232235
}
233236

0 commit comments

Comments
 (0)