aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-item.h
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-05-07 16:07:43 +0100
committerPhilip Herron <philip.herron@embecosm.com>2025-05-08 09:01:20 +0000
commitfc6b54365731c2ebfa1974058c48772e03203fdd (patch)
treeef6a38b428a94f3695943799bbaa839d915a6e41 /gcc/rust/ast/rust-item.h
parent11d46d45c3b61169b4466d7bcf2cabb7e79dbb07 (diff)
downloadgcc-fc6b54365731c2ebfa1974058c48772e03203fdd.zip
gcc-fc6b54365731c2ebfa1974058c48772e03203fdd.tar.gz
gcc-fc6b54365731c2ebfa1974058c48772e03203fdd.tar.bz2
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>
Diffstat (limited to 'gcc/rust/ast/rust-item.h')
-rw-r--r--gcc/rust/ast/rust-item.h25
1 files changed, 10 insertions, 15 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index f507c90..2f53f8d 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -51,21 +51,12 @@ class TypePath;
// A type generic parameter (as opposed to a lifetime generic parameter)
class TypeParam : public GenericParam
{
- // bool has_outer_attribute;
- // std::unique_ptr<Attribute> outer_attr;
AST::AttrVec outer_attrs;
-
Identifier type_representation;
-
- // bool has_type_param_bounds;
- // TypeParamBounds type_param_bounds;
- std::vector<std::unique_ptr<TypeParamBound>>
- type_param_bounds; // inlined form
-
- // bool has_type;
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
std::unique_ptr<Type> type;
-
location_t locus;
+ bool was_impl_trait;
public:
Identifier get_type_representation () const { return type_representation; }
@@ -85,18 +76,19 @@ public:
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
= std::vector<std::unique_ptr<TypeParamBound>> (),
std::unique_ptr<Type> type = nullptr,
- AST::AttrVec outer_attrs = {})
+ AST::AttrVec outer_attrs = {}, bool was_impl_trait = false)
: GenericParam (Analysis::Mappings::get ().get_next_node_id ()),
outer_attrs (std::move (outer_attrs)),
type_representation (std::move (type_representation)),
type_param_bounds (std::move (type_param_bounds)),
- type (std::move (type)), locus (locus)
+ type (std::move (type)), locus (locus), was_impl_trait (was_impl_trait)
{}
// Copy constructor uses clone
TypeParam (TypeParam const &other)
: GenericParam (other.node_id), outer_attrs (other.outer_attrs),
- type_representation (other.type_representation), locus (other.locus)
+ type_representation (other.type_representation), locus (other.locus),
+ was_impl_trait (other.was_impl_trait)
{
// guard to prevent null pointer dereference
if (other.type != nullptr)
@@ -114,6 +106,7 @@ public:
outer_attrs = other.outer_attrs;
locus = other.locus;
node_id = other.node_id;
+ was_impl_trait = other.was_impl_trait;
// guard to prevent null pointer dereference
if (other.type != nullptr)
@@ -153,17 +146,19 @@ public:
return type;
}
- // TODO: mutable getter seems kinda dodgy
std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
{
return type_param_bounds;
}
+
const std::vector<std::unique_ptr<TypeParamBound>> &
get_type_param_bounds () const
{
return type_param_bounds;
}
+ bool from_impl_trait () const { return was_impl_trait; }
+
protected:
// Clone function implementation as virtual method
TypeParam *clone_generic_param_impl () const override