[COMMITTED 50/83] gccrs: Do not continue when self is malformed
arthur.cohen@opensrcsec.com
arthur.cohen@opensrcsec.com
Wed Sep 16 12:30:09 GMT 2026
From: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
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 <pierre.emmanuel.patry@opensrcsec.com>
---
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 cb67af3e9b3..aae601e9246 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.50.1
More information about the Gcc-rust
mailing list