Skip to content

Commit 65574f0

Browse files
committed
gccrs: fix unconstrained infer vars on generic associated type
The trick here is that when Bar::test is resolved it resolves to the trait method: fn <Bar<i32>, T> (placeholder) -> placeholder Which is fine so we need to setup the associated types for Bar<i32> which means looking up the associated impl block then setting up the projection of A = T so it becomes: fn <Bar<i32>, T> (placeholder: projection<T>:T) -> placeholder: projection<T>:T But previously it was auto injecting inference variables so it became: fn <Bar<i32>, T> (placeholder: projection<T>:?T) -> placeholder: projection<T>:?T The issue is that the binding of the generics was still T so this caused inference variables to be injected again but unlinked. A possible tweak would be that we are substituting again with new infer vars to actually just unify them enplace so they are all part of the chain. This still might be needed but lets hold off for now. So basically when we are Path probing we dont allow GAT's to generate new inference vars because they wont be bound to this current segment which just causes confusion. Fixes #3242 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: add default infer arg * typecheck/rust-hir-trait-resolve.cc: dont add new infer vars * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont infer gcc/testsuite/ChangeLog: * rust/compile/issue-3242.rs: no longer skip the test Signed-off-by: Philip Herron <[email protected]>
1 parent 46ed038 commit 65574f0

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,9 @@ class AssociatedImplTrait
254254

255255
void setup_raw_associated_types ();
256256

257-
TyTy::BaseType *
258-
setup_associated_types (const TyTy::BaseType *self,
259-
const TyTy::TypeBoundPredicate &bound,
260-
TyTy::SubstitutionArgumentMappings *args = nullptr);
257+
TyTy::BaseType *setup_associated_types (
258+
const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
259+
TyTy::SubstitutionArgumentMappings *args = nullptr, bool infer = true);
261260

262261
void reset_associated_types ();
263262

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ AssociatedImplTrait::setup_raw_associated_types ()
485485
TyTy::BaseType *
486486
AssociatedImplTrait::setup_associated_types (
487487
const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
488-
TyTy::SubstitutionArgumentMappings *args)
488+
TyTy::SubstitutionArgumentMappings *args, bool infer)
489489
{
490490
// compute the constrained impl block generic arguments based on self and the
491491
// higher ranked trait bound
@@ -545,7 +545,7 @@ AssociatedImplTrait::setup_associated_types (
545545
std::vector<TyTy::SubstitutionArg> subst_args;
546546
for (auto &p : substitutions)
547547
{
548-
if (p.needs_substitution ())
548+
if (p.needs_substitution () && infer)
549549
{
550550
TyTy::TyVar infer_var = TyTy::TyVar::get_implicit_infer_var (locus);
551551
subst_args.push_back (
@@ -619,7 +619,7 @@ AssociatedImplTrait::setup_associated_types (
619619
= unify_site_and (a->get_ref (), TyTy::TyWithLocation (a),
620620
TyTy::TyWithLocation (b), impl_predicate.get_locus (),
621621
true /*emit-errors*/, true /*commit-if-ok*/,
622-
false /*infer*/, true /*cleanup-on-fail*/);
622+
true /*infer*/, true /*cleanup-on-fail*/);
623623
rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
624624
}
625625

@@ -632,7 +632,7 @@ AssociatedImplTrait::setup_associated_types (
632632
TyTy::TyWithLocation (impl_self_infer),
633633
impl_predicate.get_locus (),
634634
true /*emit-errors*/, true /*commit-if-ok*/,
635-
false /*infer*/, true /*cleanup-on-fail*/);
635+
true /*infer*/, true /*cleanup-on-fail*/);
636636
rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
637637
TyTy::BaseType *self_result = result;
638638

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
535535
= impl_block_ty->lookup_predicate (trait_ref.get_defid ());
536536
if (!predicate.is_error ())
537537
impl_block_ty
538-
= associated->setup_associated_types (prev_segment,
539-
predicate);
538+
= associated->setup_associated_types (prev_segment, predicate,
539+
nullptr, false);
540540
}
541541
}
542542

gcc/testsuite/rust/compile/issue-3242.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#[lang = "sized"]
2-
// { dg-skip-if "" { *-*-* } }
32
pub trait Sized {}
43

54
trait Foo<T> {

0 commit comments

Comments
 (0)