review comments
This commit is contained in:
parent
f5b285906e
commit
9dbe2e77b3
2 changed files with 10 additions and 16 deletions
|
@ -327,8 +327,8 @@ impl<'a> Parser<'a> {
|
||||||
self.token.is_keyword(kw::Return) ||
|
self.token.is_keyword(kw::Return) ||
|
||||||
self.token.is_keyword(kw::While)
|
self.token.is_keyword(kw::While)
|
||||||
);
|
);
|
||||||
let cm = self.sess.source_map();
|
let sm = self.sess.source_map();
|
||||||
match (cm.lookup_line(self.token.span.lo()), cm.lookup_line(sp.lo())) {
|
match (sm.lookup_line(self.token.span.lo()), sm.lookup_line(sp.lo())) {
|
||||||
(Ok(ref a), Ok(ref b)) if a.line != b.line && is_semi_suggestable => {
|
(Ok(ref a), Ok(ref b)) if a.line != b.line && is_semi_suggestable => {
|
||||||
// The spans are in different lines, expected `;` and found `let` or `return`.
|
// The spans are in different lines, expected `;` and found `let` or `return`.
|
||||||
// High likelihood that it is only a missing `;`.
|
// High likelihood that it is only a missing `;`.
|
||||||
|
@ -376,9 +376,9 @@ impl<'a> Parser<'a> {
|
||||||
maybe_expected_semicolon: bool,
|
maybe_expected_semicolon: bool,
|
||||||
) {
|
) {
|
||||||
if let Some((sp, likely_path)) = self.last_type_ascription {
|
if let Some((sp, likely_path)) = self.last_type_ascription {
|
||||||
let cm = self.sess.source_map();
|
let sm = self.sess.source_map();
|
||||||
let next_pos = cm.lookup_char_pos(self.token.span.lo());
|
let next_pos = sm.lookup_char_pos(self.token.span.lo());
|
||||||
let op_pos = cm.lookup_char_pos(sp.hi());
|
let op_pos = sm.lookup_char_pos(sp.hi());
|
||||||
|
|
||||||
if likely_path {
|
if likely_path {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
|
@ -814,8 +814,8 @@ impl<'a> Parser<'a> {
|
||||||
return Ok(recovered);
|
return Ok(recovered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let cm = self.sess.source_map();
|
let sm = self.sess.source_map();
|
||||||
match (cm.lookup_line(prev_sp.lo()), cm.lookup_line(sp.lo())) {
|
match (sm.lookup_line(prev_sp.lo()), sm.lookup_line(sp.lo())) {
|
||||||
(Ok(ref a), Ok(ref b)) if a.line == b.line => {
|
(Ok(ref a), Ok(ref b)) if a.line == b.line => {
|
||||||
// When the spans are in the same line, it means that the only content
|
// When the spans are in the same line, it means that the only content
|
||||||
// between them is whitespace, point only at the found token.
|
// between them is whitespace, point only at the found token.
|
||||||
|
|
|
@ -2850,9 +2850,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
match (self.expr_is_complete(&lhs), AssocOp::from_token(&self.token)) {
|
match (self.expr_is_complete(&lhs), AssocOp::from_token(&self.token)) {
|
||||||
(true, None) => {
|
(true, None) => {
|
||||||
if last_type_ascription_set {
|
self.last_type_ascription = None;
|
||||||
self.last_type_ascription = None;
|
|
||||||
}
|
|
||||||
// Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071
|
// Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071
|
||||||
return Ok(lhs);
|
return Ok(lhs);
|
||||||
}
|
}
|
||||||
|
@ -2867,18 +2865,14 @@ impl<'a> Parser<'a> {
|
||||||
// If the next token is a keyword, then the tokens above *are* unambiguously incorrect:
|
// If the next token is a keyword, then the tokens above *are* unambiguously incorrect:
|
||||||
// `if x { a } else { b } && if y { c } else { d }`
|
// `if x { a } else { b } && if y { c } else { d }`
|
||||||
if !self.look_ahead(1, |t| t.is_reserved_ident()) => {
|
if !self.look_ahead(1, |t| t.is_reserved_ident()) => {
|
||||||
if last_type_ascription_set {
|
self.last_type_ascription = None;
|
||||||
self.last_type_ascription = None;
|
|
||||||
}
|
|
||||||
// These cases are ambiguous and can't be identified in the parser alone
|
// These cases are ambiguous and can't be identified in the parser alone
|
||||||
let sp = self.sess.source_map().start_point(self.token.span);
|
let sp = self.sess.source_map().start_point(self.token.span);
|
||||||
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
||||||
return Ok(lhs);
|
return Ok(lhs);
|
||||||
}
|
}
|
||||||
(true, Some(ref op)) if !op.can_continue_expr_unambiguously() => {
|
(true, Some(ref op)) if !op.can_continue_expr_unambiguously() => {
|
||||||
if last_type_ascription_set {
|
self.last_type_ascription = None;
|
||||||
self.last_type_ascription = None;
|
|
||||||
}
|
|
||||||
return Ok(lhs);
|
return Ok(lhs);
|
||||||
}
|
}
|
||||||
(true, Some(_)) => {
|
(true, Some(_)) => {
|
||||||
|
|
Loading…
Reference in a new issue