]> 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)
committerPhilip Herron <philip.herron@embecosm.com>
Thu, 8 May 2025 09:01:20 +0000 (09:01 +0000)
commitfc6b54365731c2ebfa1974058c48772e03203fdd
treeef6a38b428a94f3695943799bbaa839d915a6e41
parent11d46d45c3b61169b4466d7bcf2cabb7e79dbb07
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