aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-20 13:26:43 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:31 +0100
commit8cd5487f4415f1e6e392f24665a8befed6c894ad (patch)
tree88d071bd1c6ebe76c3a0b66e7786942c3f679c94 /gcc
parent6fef5bc497572798b817ad7afdcf5e5fb00c7910 (diff)
downloadgcc-8cd5487f4415f1e6e392f24665a8befed6c894ad.zip
gcc-8cd5487f4415f1e6e392f24665a8befed6c894ad.tar.gz
gcc-8cd5487f4415f1e6e392f24665a8befed6c894ad.tar.bz2
gccrs: Add dropck_eyepatch feature gate for may_dangle
Add a new feature gate for may_dangle generic param outer attributes. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc: Visit and gate may_dangle attributes. * checks/errors/rust-feature-gate.h: Update visit function prototype and add a new member function to check on a set of attributes whether one is may_dangle. * checks/errors/rust-feature.cc (Feature::create): Add new dropck_eyepatch feature. * checks/errors/rust-feature.h: Likewise. * util/rust-attribute-values.h: Add new may_dangle attribute value. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.cc37
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.h8
-rw-r--r--gcc/rust/checks/errors/rust-feature.cc4
-rw-r--r--gcc/rust/checks/errors/rust-feature.h1
-rw-r--r--gcc/rust/util/rust-attribute-values.h1
5 files changed, 48 insertions, 3 deletions
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc
index 69348cb..16c5ece 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -18,6 +18,7 @@
#include "rust-feature-gate.h"
#include "rust-abi.h"
+#include "rust-attribute-values.h"
#include "rust-ast-visitor.h"
#include "rust-feature.h"
@@ -124,6 +125,19 @@ FeatureGate::check_rustc_attri (const std::vector<AST::Attribute> &attributes)
}
void
+FeatureGate::check_may_dangle_attribute (
+ const std::vector<AST::Attribute> &attributes)
+{
+ for (const AST::Attribute &attr : attributes)
+ {
+ if (attr.get_path ().as_string () == Values::Attributes::MAY_DANGLE)
+ gate (Feature::Name::DROPCK_EYEPATCH, attr.get_locus (),
+ "`may_dangle` has unstable semantics and may be removed in the "
+ "future");
+ }
+}
+
+void
FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
{
check_rustc_attri (rules_def.get_outer_attrs ());
@@ -153,6 +167,8 @@ FeatureGate::visit (AST::TraitImpl &impl)
if (impl.is_exclam ())
gate (Feature::Name::NEGATIVE_IMPLS, impl.get_locus (),
"negative_impls are not yet implemented");
+
+ AST::DefaultASTVisitor::visit (impl);
};
void
@@ -164,4 +180,25 @@ FeatureGate::visit (AST::BoxExpr &expr)
AST::DefaultASTVisitor::visit (expr);
}
+void
+FeatureGate::visit (AST::LifetimeParam &lifetime_param)
+{
+ check_may_dangle_attribute (lifetime_param.get_outer_attrs ());
+ AST::DefaultASTVisitor::visit (lifetime_param);
+}
+
+void
+FeatureGate::visit (AST::ConstGenericParam &const_param)
+{
+ check_may_dangle_attribute (const_param.get_outer_attrs ());
+ AST::DefaultASTVisitor::visit (const_param);
+}
+
+void
+FeatureGate::visit (AST::TypeParam &param)
+{
+ check_may_dangle_attribute (param.get_outer_attrs ());
+ AST::DefaultASTVisitor::visit (param);
+}
+
} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index bef7cf1..5ead1103 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -40,8 +40,8 @@ public:
void visit (AST::AttrInputMetaItemContainer &input) override {}
void visit (AST::IdentifierExpr &ident_expr) override {}
void visit (AST::Lifetime &lifetime) override {}
- void visit (AST::LifetimeParam &lifetime_param) override {}
- void visit (AST::ConstGenericParam &const_param) override {}
+ void visit (AST::LifetimeParam &lifetime_param) override;
+ void visit (AST::ConstGenericParam &const_param) override;
void visit (AST::PathInExpression &path) override {}
void visit (AST::TypePathSegment &segment) override {}
void visit (AST::TypePathSegmentGeneric &segment) override {}
@@ -104,7 +104,7 @@ public:
void visit (AST::MatchExpr &expr) override {}
void visit (AST::AwaitExpr &expr) override {}
void visit (AST::AsyncBlockExpr &expr) override {}
- void visit (AST::TypeParam &param) override {}
+ void visit (AST::TypeParam &param) override;
void visit (AST::LifetimeWhereClauseItem &item) override {}
void visit (AST::TypeBoundWhereClauseItem &item) override {}
void visit (AST::Module &module) override {}
@@ -188,6 +188,8 @@ public:
private:
void gate (Feature::Name name, location_t loc, const std::string &error_msg);
void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
+ void
+ check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
std::set<Feature::Name> valid_features;
};
} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc
index f993bbb..b9a648e 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -48,6 +48,9 @@ Feature::create (Feature::Name name)
case Feature::Name::BOX_SYNTAX:
return Feature (Feature::Name::BOX_SYNTAX, Feature::State::ACTIVE,
"box_syntax", "1.0.0", 49733, tl::nullopt, "");
+ case Feature::Name::DROPCK_EYEPATCH:
+ return Feature (Feature::Name::DROPCK_EYEPATCH, Feature::State::ACTIVE,
+ "dropck_eyepatch", "1.10.0", 34761, tl::nullopt, "");
default:
rust_unreachable ();
}
@@ -66,6 +69,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
{"lang_items", Feature::Name::LANG_ITEMS},
{"no_core", Feature::Name::NO_CORE},
{"box_syntax", Feature::Name::BOX_SYNTAX},
+ {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
}; // namespace Rust
tl::optional<Feature::Name>
diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h
index 736d97e..0fb63b5 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -47,6 +47,7 @@ public:
LANG_ITEMS,
NO_CORE,
BOX_SYNTAX,
+ DROPCK_EYEPATCH,
};
const std::string &as_string () { return m_name_str; }
diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h
index fec73b1..9041701 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -55,6 +55,7 @@ public:
static constexpr auto &UNSTABLE = "unstable";
static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
+ static constexpr auto &MAY_DANGLE = "may_dangle";
};
} // namespace Values
} // namespace Rust