Rollup merge of #103444 - chenyukang:yukang/fix-103425-extra-diag, r=davidtwco
Remove extra type error after missing semicolon error Fixes #103425
This commit is contained in:
commit
742741f9c1
3 changed files with 79 additions and 28 deletions
|
@ -553,39 +553,46 @@ impl<'a> Parser<'a> {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
// Expression without semicolon.
|
// Expression without semicolon.
|
||||||
StmtKind::Expr(ref mut expr)
|
StmtKind::Expr(ref mut expr)
|
||||||
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) =>
|
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => {
|
||||||
{
|
|
||||||
// Just check for errors and recover; do not eat semicolon yet.
|
// Just check for errors and recover; do not eat semicolon yet.
|
||||||
if let Err(mut e) =
|
// `expect_one_of` returns PResult<'a, bool /* recovered */>
|
||||||
self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)])
|
let replace_with_err =
|
||||||
{
|
match self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)]) {
|
||||||
if let TokenKind::DocComment(..) = self.token.kind {
|
// Recover from parser, skip type error to avoid extra errors.
|
||||||
if let Ok(snippet) = self.span_to_snippet(self.token.span) {
|
Ok(true) => true,
|
||||||
let sp = self.token.span;
|
Err(mut e) => {
|
||||||
let marker = &snippet[..3];
|
if let TokenKind::DocComment(..) = self.token.kind &&
|
||||||
let (comment_marker, doc_comment_marker) = marker.split_at(2);
|
let Ok(snippet) = self.span_to_snippet(self.token.span) {
|
||||||
|
let sp = self.token.span;
|
||||||
|
let marker = &snippet[..3];
|
||||||
|
let (comment_marker, doc_comment_marker) = marker.split_at(2);
|
||||||
|
|
||||||
e.span_suggestion(
|
e.span_suggestion(
|
||||||
sp.with_hi(sp.lo() + BytePos(marker.len() as u32)),
|
sp.with_hi(sp.lo() + BytePos(marker.len() as u32)),
|
||||||
&format!(
|
&format!(
|
||||||
"add a space before `{}` to use a regular comment",
|
"add a space before `{}` to use a regular comment",
|
||||||
doc_comment_marker,
|
doc_comment_marker,
|
||||||
),
|
),
|
||||||
format!("{} {}", comment_marker, doc_comment_marker),
|
format!("{} {}", comment_marker, doc_comment_marker),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Err(mut e) =
|
if let Err(mut e) =
|
||||||
self.check_mistyped_turbofish_with_multiple_type_params(e, expr)
|
self.check_mistyped_turbofish_with_multiple_type_params(e, expr)
|
||||||
{
|
{
|
||||||
if recover.no() {
|
if recover.no() {
|
||||||
return Err(e);
|
return Err(e);
|
||||||
|
}
|
||||||
|
e.emit();
|
||||||
|
self.recover_stmt();
|
||||||
}
|
}
|
||||||
e.emit();
|
true
|
||||||
self.recover_stmt();
|
|
||||||
}
|
}
|
||||||
// Don't complain about type errors in body tail after parse error (#57383).
|
_ => false
|
||||||
|
};
|
||||||
|
if replace_with_err {
|
||||||
|
// We already emitted an error, so don't emit another type error
|
||||||
let sp = expr.span.to(self.prev_token.span);
|
let sp = expr.span.to(self.prev_token.span);
|
||||||
*expr = self.mk_expr_err(sp);
|
*expr = self.mk_expr_err(sp);
|
||||||
}
|
}
|
||||||
|
|
15
src/test/ui/parser/issue-103425.rs
Normal file
15
src/test/ui/parser/issue-103425.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
fn f() -> f32 {
|
||||||
|
3
|
||||||
|
//~^ ERROR expected `;`
|
||||||
|
5.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn k() -> f32 {
|
||||||
|
2_u32
|
||||||
|
//~^ ERROR expected `;`
|
||||||
|
3_i8
|
||||||
|
//~^ ERROR expected `;`
|
||||||
|
5.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
29
src/test/ui/parser/issue-103425.stderr
Normal file
29
src/test/ui/parser/issue-103425.stderr
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
error: expected `;`, found `5.0`
|
||||||
|
--> $DIR/issue-103425.rs:2:6
|
||||||
|
|
|
||||||
|
LL | 3
|
||||||
|
| ^ help: add `;` here
|
||||||
|
LL |
|
||||||
|
LL | 5.0
|
||||||
|
| --- unexpected token
|
||||||
|
|
||||||
|
error: expected `;`, found `3_i8`
|
||||||
|
--> $DIR/issue-103425.rs:8:10
|
||||||
|
|
|
||||||
|
LL | 2_u32
|
||||||
|
| ^ help: add `;` here
|
||||||
|
LL |
|
||||||
|
LL | 3_i8
|
||||||
|
| ---- unexpected token
|
||||||
|
|
||||||
|
error: expected `;`, found `5.0`
|
||||||
|
--> $DIR/issue-103425.rs:10:9
|
||||||
|
|
|
||||||
|
LL | 3_i8
|
||||||
|
| ^ help: add `;` here
|
||||||
|
LL |
|
||||||
|
LL | 5.0
|
||||||
|
| --- unexpected token
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue