https://gcc.gnu.org/g:6e5e0c1fd943d77aac9f21fc343e1f5b732eca1c

commit r16-2894-g6e5e0c1fd943d77aac9f21fc343e1f5b732eca1c
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Mon Jun 23 12:59:33 2025 +0100

    gccrs: Fix bug with non compiled const decl
    
    There was a sily bug where if you reorder this test case to declare A 
before B
    this test would work but its meant to work in any order. So this fixes the 
bug
    during code gen to fall back to our query compile system if this is needed.
    
    Fixes Rust-GCC#3525
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-resolve-path.cc: if this fails fall back to 
query compile
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-3525.rs: New test.
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/backend/rust-compile-resolve-path.cc | 13 +++++++++----
 gcc/testsuite/rust/compile/issue-3525.rs      |  6 ++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index 81d2dbb033f1..1ce9676913d3 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -187,13 +187,18 @@ ResolvePathRef::resolve_with_node_id (
     }
 
   // Handle unit struct
+  tree resolved_item = error_mark_node;
   if (lookup->get_kind () == TyTy::TypeKind::ADT)
-    return attempt_constructor_expression_lookup (lookup, ctx, mappings,
-                                                 expr_locus);
+    resolved_item
+      = attempt_constructor_expression_lookup (lookup, ctx, mappings,
+                                              expr_locus);
+
+  if (!error_operand_p (resolved_item))
+    return resolved_item;
 
   // let the query system figure it out
-  tree resolved_item = query_compile (ref, lookup, final_segment, mappings,
-                                     expr_locus, is_qualified_path);
+  resolved_item = query_compile (ref, lookup, final_segment, mappings,
+                                expr_locus, is_qualified_path);
   if (resolved_item != error_mark_node)
     {
       TREE_USED (resolved_item) = 1;
diff --git a/gcc/testsuite/rust/compile/issue-3525.rs 
b/gcc/testsuite/rust/compile/issue-3525.rs
new file mode 100644
index 000000000000..84a7ebeee116
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3525.rs
@@ -0,0 +1,6 @@
+// { dg-options "-w" }
+
+struct Foo(usize);
+
+const B: usize = A.0;
+const A: Foo = Foo(123);

Reply via email to