Skip to content

Commit 208cd08

Browse files
committed
gccrs: Fix silly ordering bug in trait reference resolution
Ensure proper ordering when resolving trait references to prevent incorrect type resolution in certain contexts. gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.cc: Fix ordering bug. * typecheck/rust-hir-type-check-type.cc: Update call site. * testsuite/rust/compile/silly-order-bug.rs: New test.
1 parent cf4b34a commit 208cd08

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

gcc/rust/typecheck/rust-hir-trait-reference.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,15 @@ TraitReference::on_resolved ()
342342
{
343343
for (auto &item : item_refs)
344344
{
345-
item.on_resolved ();
345+
if (item.get_trait_item_type ()
346+
== TraitItemReference::TraitItemType::TYPE)
347+
item.on_resolved ();
348+
}
349+
for (auto &item : item_refs)
350+
{
351+
if (item.get_trait_item_type ()
352+
!= TraitItemReference::TraitItemType::TYPE)
353+
item.on_resolved ();
346354
}
347355
}
348356

gcc/rust/typecheck/rust-hir-type-check-type.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,7 @@ TypeCheckType::resolve_segments (
549549
bool selfResolveOk = false;
550550

551551
if (first_segment && tySegIsBigSelf
552-
&& context->block_context ().is_in_context ()
553-
&& context->block_context ().peek ().is_impl_block ())
552+
&& context->block_context ().is_in_context ())
554553
{
555554
TypeCheckBlockContextItem ctx = context->block_context ().peek ();
556555
TyTy::BaseType *lookup = nullptr;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[lang = "sized"]
2+
trait Sized {}
3+
4+
#[lang = "fn_once"]
5+
pub trait FnOnce<Args> {
6+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
7+
type Output;
8+
}

0 commit comments

Comments
 (0)