From: Pierre-Emmanuel Patry <[email protected]>

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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/a9db302cbf593da5168d980da882a01843f01729

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4317

 gcc/rust/parse/rust-parse-impl.h              | 44 ++++---------------
 .../rust/compile/braced_macro_arm.rs          |  2 -
 gcc/testsuite/rust/compile/issue-407-2.rs     |  6 ---
 gcc/testsuite/rust/compile/issue-407.rs       |  2 -
 gcc/testsuite/rust/compile/issue-4162.rs      |  2 -
 gcc/testsuite/rust/compile/issue-867.rs       |  3 --
 .../rust/compile/raw_ref_op_invalid.rs        |  2 -
 7 files changed, 9 insertions(+), 52 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 42e004428..6cb8f0e65 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1855,15 +1855,7 @@ Parser<ManagedTokenSource>::parse_macro_invocation_semi (
       std::unique_ptr<AST::TokenTree> tree = parse_token_tree ();
 
       if (tree == nullptr)
-       {
-         Error error (t->get_locus (),
-                      "failed to parse token tree for macro invocation semi "
-                      "- found %qs",
-                      t->get_token_description ());
-         add_error (std::move (error));
-
-         return nullptr;
-       }
+       return nullptr;
 
       token_trees.push_back (std::move (tree));
 
@@ -2999,8 +2991,9 @@ Parser<ManagedTokenSource>::parse_function 
(AST::Visibility vis,
   else
     {
       std::unique_ptr<AST::BlockExpr> block_expr = parse_block_expr ();
-      if (block_expr != nullptr)
-       body = std::move (block_expr);
+      if (block_expr == nullptr)
+       return nullptr;
+      body = std::move (block_expr);
     }
 
   return std::unique_ptr<AST::Function> (
@@ -6226,10 +6219,6 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec 
outer_attrs,
       expr = parse_expr ();
       if (expr == nullptr)
        {
-         Error error (lexer.peek_token ()->get_locus (),
-                      "failed to parse expression in let statement");
-         add_error (std::move (error));
-
          skip_after_semicolon ();
          return nullptr;
        }
@@ -7256,11 +7245,7 @@ Parser<ManagedTokenSource>::parse_block_expr (
       ExprOrStmt expr_or_stmt = parse_stmt_or_expr ();
       if (expr_or_stmt.is_error ())
        {
-         Error error (
-           t->get_locus (),
-           "failed to parse statement or expression in block expression");
-         add_error (std::move (error));
-
+         skip_after_end_block ();
          return nullptr;
        }
 
@@ -7783,14 +7768,7 @@ Parser<ManagedTokenSource>::parse_if_expr (AST::AttrVec 
outer_attrs,
   // parse required block expr
   std::unique_ptr<AST::BlockExpr> if_body = parse_block_expr ();
   if (if_body == nullptr)
-    {
-      Error error (lexer.peek_token ()->get_locus (),
-                  "failed to parse if body block expression in if expression");
-      add_error (std::move (error));
-
-      // skip somewhere?
-      return nullptr;
-    }
+    return nullptr;
 
   // branch to parse end or else (and then else, else if, or else if let)
   if (lexer.peek_token ()->get_id () != ELSE)
@@ -8113,13 +8091,7 @@ Parser<ManagedTokenSource>::parse_loop_expr 
(AST::AttrVec outer_attrs,
   // parse loop body, which is required
   std::unique_ptr<AST::BlockExpr> loop_body = parse_block_expr ();
   if (loop_body == nullptr)
-    {
-      Error error (lexer.peek_token ()->get_locus (),
-                  "could not parse loop body in (infinite) loop expression");
-      add_error (std::move (error));
-
-      return nullptr;
-    }
+    return nullptr;
 
   return std::unique_ptr<AST::LoopExpr> (
     new AST::LoopExpr (std::move (loop_body), locus, std::move (label),
@@ -12198,6 +12170,8 @@ Parser<ManagedTokenSource>::parse_expr (int 
right_binding_power,
   // parse null denotation (unary part of expression)
   std::unique_ptr<AST::Expr> expr
     = null_denotation ({}, null_denotation_restrictions);
+  if (expr == nullptr)
+    return nullptr;
 
   return left_denotations (std::move (expr), right_binding_power,
                           std::move (outer_attrs), restrictions);
diff --git a/gcc/testsuite/rust/compile/braced_macro_arm.rs 
b/gcc/testsuite/rust/compile/braced_macro_arm.rs
index 9bcd1a69c..8782cf9f9 100644
--- a/gcc/testsuite/rust/compile/braced_macro_arm.rs
+++ b/gcc/testsuite/rust/compile/braced_macro_arm.rs
@@ -7,11 +7,9 @@ macro_rules! m {
 
 fn h(c: bool) {
     match c {
-        // { dg-error "failed to parse statement or expression in block 
expression" "" { target *-*-* } .-1 }
         true => m! {}
         false => ()
         // { dg-error "exprwithoutblock requires comma after match case 
expression in match arm \\(if not final case\\)" "" { target *-*-* } .-1 }
-        // { dg-error "unrecognised token .false. for start of item" "" { 
target *-*-* } .-2 }
     };
 }
 
diff --git a/gcc/testsuite/rust/compile/issue-407-2.rs 
b/gcc/testsuite/rust/compile/issue-407-2.rs
index 002d998a9..6dad8612f 100644
--- a/gcc/testsuite/rust/compile/issue-407-2.rs
+++ b/gcc/testsuite/rust/compile/issue-407-2.rs
@@ -2,14 +2,8 @@
 pub fn loopy()  {
     let mut a = 1;
     loop {
-        // { dg-error {failed to parse statement or expression in block 
expression} "" { target *-*-* } .-1 }
         if a < 40 {
-            // { dg-error {failed to parse statement or expression in block 
expression} "" { target *-*-* } .-1 }
             a + = 1; // { dg-error "found unexpected token '=' in null 
denotation" }
-            // { dg-error {failed to parse statement or expression in block 
expression} "" { target *-*-* } .-1 }
-            // { dg-error {failed to parse if body block expression in if 
expression} "" { target *-*-* } .-2 }
-            // { dg-error {could not parse loop body in \(infinite\) loop 
expression} "" { target *-*-* } .-3 }
-            // { dg-error {unrecognised token 'integer literal' for start of 
item} "" { target *-*-* } .-4 }
         } else {
             break;
         }
diff --git a/gcc/testsuite/rust/compile/issue-407.rs 
b/gcc/testsuite/rust/compile/issue-407.rs
index 9188c2c6b..3a9dbeba9 100644
--- a/gcc/testsuite/rust/compile/issue-407.rs
+++ b/gcc/testsuite/rust/compile/issue-407.rs
@@ -2,6 +2,4 @@
 fn test()  {
     let mut a = 1;
     a + = 1; // { dg-error "found unexpected token '=' in null denotation" }
-    // { dg-error {failed to parse statement or expression in block 
expression} "" { target *-*-* } .-1 }
-    // { dg-error {unrecognised token 'integer literal' for start of item} "" 
{ target *-*-* } .-2 }
 }
diff --git a/gcc/testsuite/rust/compile/issue-4162.rs 
b/gcc/testsuite/rust/compile/issue-4162.rs
index 7caf8870c..ffaa92d97 100644
--- a/gcc/testsuite/rust/compile/issue-4162.rs
+++ b/gcc/testsuite/rust/compile/issue-4162.rs
@@ -1,8 +1,6 @@
 pub fn main() {
     while let  = 5
     // { dg-error "should be at least 1 pattern" "" { target *-*-* } .-1 }
-    // { dg-error "failed to parse statement or expression in block 
expression" "" { target *-*-* } .-2 }
-    // { dg-error "unrecognised token .=. for start of item" "" { target *-*-* 
} .-3 }
     {}
 }
 
diff --git a/gcc/testsuite/rust/compile/issue-867.rs 
b/gcc/testsuite/rust/compile/issue-867.rs
index c61de09d8..1aa29b3ed 100644
--- a/gcc/testsuite/rust/compile/issue-867.rs
+++ b/gcc/testsuite/rust/compile/issue-867.rs
@@ -1,7 +1,4 @@
 fn main() {
     let _ = 42;
     let a = _ + 123; // { dg-error "use of '_' is not allowed on the 
right-side of an assignment" }
-                     // { dg-error {failed to parse expression in let 
statement} "" { target *-*-* } .-1  }
-                     // { dg-error {failed to parse statement or expression in 
block expression} "" { target *-*-* } .-2 }
-                     // { dg-error {unrecognised token '\}' for start of item} 
"" { target *-*-* } .+1 }
 }
diff --git a/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs 
b/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs
index 90e169f30..42ec63d73 100644
--- a/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs
+++ b/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs
@@ -7,6 +7,4 @@ pub struct Toto {
 
 pub fn test(mut toto: Toto) {
     let _c = &raw toto.u; //{ dg-error "expecting .;. but .identifier. found" 
"" { target *-*-* }  }
-    //{ dg-excess-errors "Additional errors for parent items" { target *-*-* } 
}
-
 }

base-commit: 8f265ddce78410a52b93689998b2a267d7ceb8e8
-- 
2.51.2

Reply via email to