]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Prevent passing generic arguments to impl traits in argument position
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 7 May 2025 15:07:43 +0000 (16:07 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:41 +0000 (16:36 +0200)
commit9819ac46419165dc59f9c5773f2d8bb878129bf6
treebb2adb3a69d4e78f8037bed318a43425ad562e31
parent17a863d7ace5bd994ef7eacf977348a7a493b816
gccrs: Prevent passing generic arguments to impl traits in argument position

When using impl traits in argument position (APIT), they are desugared into generics,
and supplying explicit generic arguments is not allowed. This commit adds the error
diagnostic E0632 for attempting to pass generic arguments to impl traits, completing
the implementation of the APIT feature.

gcc/rust/ChangeLog:

* ast/rust-desugar-apit.cc: track if this is a impl-trait generic
* ast/rust-item.h (class TypeParam): add field to track if from impl trait
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): likewise
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): upate hir as well
(TypeParam::operator=): likewise
* hir/tree/rust-hir-item.h (class TypeParam): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): add error
* typecheck/rust-tyty-subst.h: add const getter for the associated TypeParm

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/impl_trait_generic_arg.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ast/rust-desugar-apit.cc
gcc/rust/ast/rust-item.h
gcc/rust/hir/rust-ast-lower-type.cc
gcc/rust/hir/tree/rust-hir-item.cc
gcc/rust/hir/tree/rust-hir-item.h
gcc/rust/typecheck/rust-tyty-subst.cc
gcc/rust/typecheck/rust-tyty-subst.h
gcc/testsuite/rust/compile/impl_trait_generic_arg.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude