aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-19 02:44:42 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-06-11 11:19:26 +0000
commitca178958c4bb599da331f62cc5cc8a480ea5371e (patch)
treec7673eea2ba04c27791e83215090baecd1bbcfe4
parent32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3 (diff)
downloadgcc-ca178958c4bb599da331f62cc5cc8a480ea5371e.zip
gcc-ca178958c4bb599da331f62cc5cc8a480ea5371e.tar.gz
gcc-ca178958c4bb599da331f62cc5cc8a480ea5371e.tar.bz2
Add feature gate for box syntax
The box syntax is experimental even though it is used in the standard library. It should be feature gated to prevent anyone from using it in stable rust. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Allow visitor recursion in functions. Also add the gate for the box syntax. * checks/errors/rust-feature-gate.h: Remove several recursion fences in the feature gate visitor. * checks/errors/rust-feature.cc (Feature::create): Add a new feature. (Feature::as_name): Likewise. * checks/errors/rust-feature.h: Add box_syntax gate. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.cc11
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.h3
-rw-r--r--gcc/rust/checks/errors/rust-feature.cc6
-rw-r--r--gcc/rust/checks/errors/rust-feature.h3
4 files changed, 19 insertions, 4 deletions
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc
index eb23192..33b0387 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -134,6 +134,8 @@ FeatureGate::visit (AST::Function &function)
{
if (!function.is_external ())
check_rustc_attri (function.get_outer_attrs ());
+
+ AST::DefaultASTVisitor::visit (function);
}
void
@@ -153,4 +155,13 @@ FeatureGate::visit (AST::TraitImpl &impl)
"negative_impls are not yet implemented");
};
+void
+FeatureGate::visit (AST::BoxExpr &expr)
+{
+ gate (
+ Feature::Name::BOX_SYNTAX, expr.get_locus (),
+ "box expression syntax is experimental; you can call `Box::new` instead");
+ AST::DefaultASTVisitor::visit (expr);
+}
+
} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index d7c84a5..aa90ae2 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -81,7 +81,6 @@ public:
void visit (AST::MethodCallExpr &expr) override {}
void visit (AST::FieldAccessExpr &expr) override {}
void visit (AST::ClosureExprInner &expr) override {}
- void visit (AST::BlockExpr &expr) override {}
void visit (AST::ClosureExprInnerTyped &expr) override {}
void visit (AST::ContinueExpr &expr) override {}
void visit (AST::BreakExpr &expr) override {}
@@ -92,6 +91,7 @@ public:
void visit (AST::RangeFromToInclExpr &expr) override {}
void visit (AST::RangeToInclExpr &expr) override {}
void visit (AST::ReturnExpr &expr) override {}
+ void visit (AST::BoxExpr &expr) override;
void visit (AST::UnsafeBlockExpr &expr) override {}
void visit (AST::LoopExpr &expr) override {}
void visit (AST::WhileLoopExpr &expr) override {}
@@ -166,7 +166,6 @@ public:
void visit (AST::SlicePattern &pattern) override {}
void visit (AST::AltPattern &pattern) override {}
void visit (AST::EmptyStmt &stmt) override {}
- void visit (AST::LetStmt &stmt) override {}
void visit (AST::ExprStmt &stmt) override {}
void visit (AST::TraitBound &bound) override {}
void visit (AST::ImplTraitType &type) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc
index 6249758..18cfa33 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -45,6 +45,9 @@ Feature::create (Feature::Name name)
case Feature::Name::NEGATIVE_IMPLS:
return Feature (Feature::Name::NEGATIVE_IMPLS, Feature::State::ACTIVE,
"negative_impls", "1.0.0", 68318, tl::nullopt, "");
+ case Feature::Name::BOX_SYNTAX:
+ return Feature (Feature::Name::BOX_SYNTAX, Feature::State::ACTIVE,
+ "box_syntax", "1.0.0", 49733, tl::nullopt, "");
default:
rust_unreachable ();
}
@@ -62,6 +65,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
{"extern_types", Feature::Name::EXTERN_TYPES},
{"lang_items", Feature::Name::LANG_ITEMS},
{"no_core", Feature::Name::NO_CORE},
+ {"box_syntax", Feature::Name::BOX_SYNTAX},
}; // namespace Rust
tl::optional<Feature::Name>
@@ -73,4 +77,4 @@ Feature::as_name (const std::string &name)
return tl::nullopt;
}
-} // namespace Rust \ No newline at end of file
+} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h
index 306baf2..238bf07 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -46,6 +46,7 @@ public:
EXTERN_TYPES,
LANG_ITEMS,
NO_CORE,
+ BOX_SYNTAX,
};
const std::string &as_string () { return m_name_str; }
@@ -79,4 +80,4 @@ private:
};
} // namespace Rust
-#endif \ No newline at end of file
+#endif