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

If a self segment is malformed we do not want to continue as the node id
retrieved during import finalization may crash the compiler.

Fixes Rust-GCC/gccrs#4735

gcc/rust/ChangeLog:

        * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Return on
        error.

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/4cc06a6e9ddd02b79f87b3daeec1f0bdc0ece765

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#4735: https://github.com/Rust-GCC/gccrs/issues/4735

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

 gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index cb67af3e9..aae601e92 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -594,8 +594,12 @@ Early::visit (AST::UseDeclaration &decl)
       if (rebind.get_path ().get_final_segment ().is_lower_self_seg ())
        {
          collect_error (
-           Error (decl.get_locus (), ErrorCode::E0429,
+           Error (rebind.get_path ().get_final_segment ().get_locus (),
+                  ErrorCode::E0429,
                   "%<self%> imports are only allowed within a { } list"));
+         // We must not continue, malformed use declaration must not be
+         // finalized.
+         return;
        }
     }
 
-- 
2.55.0

Reply via email to