]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix silly ordering bug in trait reference resolution
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 20 Jun 2025 17:21:30 +0000 (18:21 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:50 +0000 (16:36 +0200)
Ensure proper ordering when resolving trait references to prevent
incorrect type resolution in certain contexts.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (TraitReference::on_resolved): ensure associated
types are done first
* typecheck/rust-hir-type-check-type.cc: Update call site.

gcc/testsuite/ChangeLog:

* rust/compile/silly-order-bug.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-trait-reference.cc
gcc/rust/typecheck/rust-hir-type-check-type.cc
gcc/testsuite/rust/compile/silly-order-bug.rs [new file with mode: 0644]

index 83985f009893bb47ce44a58cfea5e843f0b8a355..88e270d510d2f7013377435693a959aef8306c83 100644 (file)
@@ -342,7 +342,15 @@ TraitReference::on_resolved ()
 {
   for (auto &item : item_refs)
     {
-      item.on_resolved ();
+      if (item.get_trait_item_type ()
+         == TraitItemReference::TraitItemType::TYPE)
+       item.on_resolved ();
+    }
+  for (auto &item : item_refs)
+    {
+      if (item.get_trait_item_type ()
+         != TraitItemReference::TraitItemType::TYPE)
+       item.on_resolved ();
     }
 }
 
index 18e04581ab838e98bcb6fe6c83db388e45415ffa..f23352baacdad4506a702956bb945af04bafa483 100644 (file)
@@ -549,8 +549,7 @@ TypeCheckType::resolve_segments (
       bool selfResolveOk = false;
 
       if (first_segment && tySegIsBigSelf
-         && context->block_context ().is_in_context ()
-         && context->block_context ().peek ().is_impl_block ())
+         && context->block_context ().is_in_context ())
        {
          TypeCheckBlockContextItem ctx = context->block_context ().peek ();
          TyTy::BaseType *lookup = nullptr;
diff --git a/gcc/testsuite/rust/compile/silly-order-bug.rs b/gcc/testsuite/rust/compile/silly-order-bug.rs
new file mode 100644 (file)
index 0000000..0d9cf1d
--- /dev/null
@@ -0,0 +1,8 @@
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+    type Output;
+}