]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/rust/typecheck/rust-tyty-bounds.cc
gccrs: Support associated type bound arguments
authorPhilip Herron <herron.philip@googlemail.com>
Sat, 7 Jan 2023 14:41:12 +0000 (14:41 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:17 +0000 (10:47 +0200)
commit7eab9d18d97d0ea938c5c7194a7a82109d3a5ea6
tree23873ba7605959b748390a45220747787b78c346
parent3f1dbb2cf8fd7d05550ccde3273a618c76cfaf5c
gccrs: Support associated type bound arguments

This patch adds support for the GenercArgsBinding type, where you can
specify the associated types of a trait bound using `<Foo=i32>` style
syntax. Note that the type-resolution relys on the i32 impl for Add
as type resolution will resolve the `a+a` to the core::ops::Add method
so code generation will require this to exist.

I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly
creating an HIR::GenericArgs with a trait-object type and causing issues.
the parsing is still correct but we dont have the mechanism to represent
this in AST and HIR properly. I think we will need a new HIR::GenericArgs
AssociatedTypeBindingBound or something similar. We are still lacking
bounds checking during are type coercions and unifications so running this
example using an f32 will wrongly pass type checking, this will need
addressed next.

Fixes #1720

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Add const get_identifier and get_type method.
* typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound):
Do not assert failure on size mismatch anymore.
(TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor.
(TypeBoundPredicate::operator=): Likewise.
(TypeBoundPredicate::apply_generic_arguments): Likewise.
(TypeBoundPredicateItem::get_tyty_for_receiver): Likewise.
(TypeBoundPredicate::get_num_associated_bindings): Likewise.
(TypeBoundPredicate::lookup_associated_type): Fix implementation for new system.
(TypeBoundPredicate::get_associated_type_items): Likewise.
* typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new
behavior.
(SubstitutionRef::infer_substitions): Use new constructor and add comment.
(SubstitutionRef::solve_missing_mappings_from_this): Use new constructor.
* typecheck/rust-tyty.h: Define new constructors.

gcc/testsuite/ChangeLog:

* rust/compile/bounds.rs: change to use -fsyntax-only
* rust/execute/torture/issue-1720.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/hir/tree/rust-hir-path.h
gcc/rust/typecheck/rust-hir-path-probe.h
gcc/rust/typecheck/rust-hir-trait-resolve.cc
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h
gcc/testsuite/rust/compile/bounds.rs
gcc/testsuite/rust/execute/torture/issue-1720.rs [new file with mode: 0644]