Skip to content

Commit a9db302

Browse files
committed
Remove non leaf errors
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Return a nullptr on error instead of a valid function. (Parser::parse_let_stmt): Remove non leaf error. (Parser::parse_if_expr): Likewise. (Parser::parse_loop_expr): Likewise. (Parser::parse_expr): Return error on null denotation error. gcc/testsuite/ChangeLog: * rust/compile/braced_macro_arm.rs: Remove parent errors. * rust/compile/issue-407-2.rs: Likewise. * rust/compile/issue-407.rs: Likewise. * rust/compile/issue-4162.rs: Likewise. * rust/compile/issue-867.rs: Likewise. * rust/compile/raw_ref_op_invalid.rs: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
1 parent 8f265dd commit a9db302

File tree

7 files changed

+9
-52
lines changed

7 files changed

+9
-52
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,15 +1855,7 @@ Parser<ManagedTokenSource>::parse_macro_invocation_semi (
18551855
std::unique_ptr<AST::TokenTree> tree = parse_token_tree ();
18561856

18571857
if (tree == nullptr)
1858-
{
1859-
Error error (t->get_locus (),
1860-
"failed to parse token tree for macro invocation semi "
1861-
"- found %qs",
1862-
t->get_token_description ());
1863-
add_error (std::move (error));
1864-
1865-
return nullptr;
1866-
}
1858+
return nullptr;
18671859

18681860
token_trees.push_back (std::move (tree));
18691861

@@ -2999,8 +2991,9 @@ Parser<ManagedTokenSource>::parse_function (AST::Visibility vis,
29992991
else
30002992
{
30012993
std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr ();
3002-
if (block_expr != nullptr)
3003-
body = std::move (block_expr);
2994+
if (block_expr == nullptr)
2995+
return nullptr;
2996+
body = std::move (block_expr);
30042997
}
30052998

30062999
return std::unique_ptr<AST::Function> (
@@ -6226,10 +6219,6 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
62266219
expr = parse_expr ();
62276220
if (expr == nullptr)
62286221
{
6229-
Error error (lexer.peek_token ()->get_locus (),
6230-
"failed to parse expression in let statement");
6231-
add_error (std::move (error));
6232-
62336222
skip_after_semicolon ();
62346223
return nullptr;
62356224
}
@@ -7256,11 +7245,7 @@ Parser<ManagedTokenSource>::parse_block_expr (
72567245
ExprOrStmt expr_or_stmt = parse_stmt_or_expr ();
72577246
if (expr_or_stmt.is_error ())
72587247
{
7259-
Error error (
7260-
t->get_locus (),
7261-
"failed to parse statement or expression in block expression");
7262-
add_error (std::move (error));
7263-
7248+
skip_after_end_block ();
72647249
return nullptr;
72657250
}
72667251

@@ -7783,14 +7768,7 @@ Parser<ManagedTokenSource>::parse_if_expr (AST::AttrVec outer_attrs,
77837768
// parse required block expr
77847769
std::unique_ptr<AST::BlockExpr> if_body = parse_block_expr ();
77857770
if (if_body == nullptr)
7786-
{
7787-
Error error (lexer.peek_token ()->get_locus (),
7788-
"failed to parse if body block expression in if expression");
7789-
add_error (std::move (error));
7790-
7791-
// skip somewhere?
7792-
return nullptr;
7793-
}
7771+
return nullptr;
77947772

77957773
// branch to parse end or else (and then else, else if, or else if let)
77967774
if (lexer.peek_token ()->get_id () != ELSE)
@@ -8113,13 +8091,7 @@ Parser<ManagedTokenSource>::parse_loop_expr (AST::AttrVec outer_attrs,
81138091
// parse loop body, which is required
81148092
std::unique_ptr<AST::BlockExpr> loop_body = parse_block_expr ();
81158093
if (loop_body == nullptr)
8116-
{
8117-
Error error (lexer.peek_token ()->get_locus (),
8118-
"could not parse loop body in (infinite) loop expression");
8119-
add_error (std::move (error));
8120-
8121-
return nullptr;
8122-
}
8094+
return nullptr;
81238095

81248096
return std::unique_ptr<AST::LoopExpr> (
81258097
new AST::LoopExpr (std::move (loop_body), locus, std::move (label),
@@ -12198,6 +12170,8 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
1219812170
// parse null denotation (unary part of expression)
1219912171
std::unique_ptr<AST::Expr> expr
1220012172
= null_denotation ({}, null_denotation_restrictions);
12173+
if (expr == nullptr)
12174+
return nullptr;
1220112175

1220212176
return left_denotations (std::move (expr), right_binding_power,
1220312177
std::move (outer_attrs), restrictions);

gcc/testsuite/rust/compile/braced_macro_arm.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ macro_rules! m {
77

88
fn h(c: bool) {
99
match c {
10-
// { dg-error "failed to parse statement or expression in block expression" "" { target *-*-* } .-1 }
1110
true => m! {}
1211
false => ()
1312
// { dg-error "exprwithoutblock requires comma after match case expression in match arm \\(if not final case\\)" "" { target *-*-* } .-1 }
14-
// { dg-error "unrecognised token .false. for start of item" "" { target *-*-* } .-2 }
1513
};
1614
}
1715

gcc/testsuite/rust/compile/issue-407-2.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
pub fn loopy() {
33
let mut a = 1;
44
loop {
5-
// { dg-error {failed to parse statement or expression in block expression} "" { target *-*-* } .-1 }
65
if a < 40 {
7-
// { dg-error {failed to parse statement or expression in block expression} "" { target *-*-* } .-1 }
86
a + = 1; // { dg-error "found unexpected token '=' in null denotation" }
9-
// { dg-error {failed to parse statement or expression in block expression} "" { target *-*-* } .-1 }
10-
// { dg-error {failed to parse if body block expression in if expression} "" { target *-*-* } .-2 }
11-
// { dg-error {could not parse loop body in \(infinite\) loop expression} "" { target *-*-* } .-3 }
12-
// { dg-error {unrecognised token 'integer literal' for start of item} "" { target *-*-* } .-4 }
137
} else {
148
break;
159
}

gcc/testsuite/rust/compile/issue-407.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
fn test() {
33
let mut a = 1;
44
a + = 1; // { dg-error "found unexpected token '=' in null denotation" }
5-
// { dg-error {failed to parse statement or expression in block expression} "" { target *-*-* } .-1 }
6-
// { dg-error {unrecognised token 'integer literal' for start of item} "" { target *-*-* } .-2 }
75
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
pub fn main() {
22
while let = 5
33
// { dg-error "should be at least 1 pattern" "" { target *-*-* } .-1 }
4-
// { dg-error "failed to parse statement or expression in block expression" "" { target *-*-* } .-2 }
5-
// { dg-error "unrecognised token .=. for start of item" "" { target *-*-* } .-3 }
64
{}
75
}
86

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
fn main() {
22
let _ = 42;
33
let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" }
4-
// { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1 }
5-
// { dg-error {failed to parse statement or expression in block expression} "" { target *-*-* } .-2 }
6-
// { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+1 }
74
}

gcc/testsuite/rust/compile/raw_ref_op_invalid.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ pub struct Toto {
77

88
pub fn test(mut toto: Toto) {
99
let _c = &raw toto.u; //{ dg-error "expecting .;. but .identifier. found" "" { target *-*-* } }
10-
//{ dg-excess-errors "Additional errors for parent items" { target *-*-* } }
11-
1210
}

0 commit comments

Comments
 (0)