From 5961fbb130a24942d122f28e0b0d4d9fd6f3e417 Mon Sep 17 00:00:00 2001 From: 0xllx0 Date: Fri, 3 Oct 2025 03:17:54 +0000 Subject: [PATCH 1/2] fix: add early return for empty module file Converts an assert into an early return during AST parsing. Resolves: #4145 gcc/rust/ChangeLog: * ast/rust-ast.cc (Module::process_file_path): empty module early return Signed-off-by: Elle Rhumsaa --- gcc/rust/ast/rust-ast.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 003a6edbc10..ed4b92e8b95 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -3363,7 +3363,13 @@ void Module::process_file_path () { rust_assert (kind == Module::ModuleKind::UNLOADED); - rust_assert (module_file.empty ()); + + if (!module_file.empty ()) + { + rust_error_at (locus, "error handling module file for %qs", + module_name.as_string ().c_str ()); + return; + } // This corresponds to the path of the file 'including' the module. So the // file that contains the 'mod ;' directive From 535f54ae6965a7f35408c8d5dfb0226df8badf58 Mon Sep 17 00:00:00 2001 From: 0xllx0 Date: Tue, 30 Sep 2025 15:17:24 +0000 Subject: [PATCH 2/2] test: add a regression test for issue #4145 gcc/testsuite/ChangeLog: * rust/compile/issue-4145.rs: New test. Signed-off-by: Elle Rhumsaa --- gcc/testsuite/rust/compile/issue-4145.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-4145.rs diff --git a/gcc/testsuite/rust/compile/issue-4145.rs b/gcc/testsuite/rust/compile/issue-4145.rs new file mode 100644 index 00000000000..98b33cade11 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4145.rs @@ -0,0 +1,13 @@ +// { dg-excess-errors "warnings" } + +struct S { + field: [u8; { + #[path = "outer/inner.rs"] + // { dg-warning "error handling module file for .inner." "#4145" { xfail *-*-* } .+1 } + mod inner; + // OK + 0 + }], +} + +fn main() {}