Skip to content

Commit 8a82b04

Browse files
committed
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): enabled a default visitor to be overrided * ast/rust-ast-visitor.h: passes a method virtual * checks/errors/rust-feature-gate.cc (FeatureGate::visit): implements all checks for the new features * checks/errors/rust-feature-gate.h: the prototypes of the new checkers * checks/errors/rust-feature.cc (Feature::create): implements the recognition and creation of some new features * checks/errors/rust-feature.h: creation of the features name in the enum gcc/testsuite/ChangeLog: * rust/compile/feature_extern_types.rs: Move to... * rust/compile/features/extern_types.rs: ...here. * rust/compile/feature_intrinsics.rs: Move to... * rust/compile/features/intrinsics.rs: ...here. * rust/compile/features/arbitrary_self_types_activated.rs: New test. * rust/compile/features/arbitrary_self_types_not_activated.rs: New test. * rust/compile/features/associated_type_defaults_activated.rs: New test. * rust/compile/features/const_trait_impl_activated.rs: New test. * rust/compile/features/doc_cfg_activated.rs: New test. * rust/compile/features/doc_cfg_not_activated.rs: New test. * rust/compile/features/feature.exp: New test. * rust/compile/features/impl_trait_in_assoc_type_activated.rs: New test. * rust/compile/features/impl_trait_in_assoc_type_not_activated.rs: New test. * rust/compile/features/register_tool_activated.rs: New test. * rust/compile/features/register_tool_not_activated.rs: New test.
1 parent daa2977 commit 8a82b04

19 files changed

+228
-3
lines changed

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,6 @@ DefaultASTVisitor::visit (AST::Function &function)
831831
visit (function.get_qualifiers ());
832832
for (auto &generic : function.get_generic_params ())
833833
visit (generic);
834-
if (function.has_self_param ())
835-
visit (function.get_self_param ());
836834
for (auto &param : function.get_function_params ())
837835
visit (param);
838836
if (function.has_return_type ())

gcc/rust/ast/rust-ast-visitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class DefaultASTVisitor : public ASTVisitor
435435
virtual void visit (AST::StructPatternElements &spe);
436436
virtual void visit (AST::MaybeNamedParam &param);
437437

438-
void visit (AST::Attribute &attribute) {}
438+
virtual void visit (AST::Attribute &attribute) {}
439439

440440
template <typename T> void visit_outer_attrs (T &node)
441441
{

gcc/rust/checks/errors/rust-feature-gate.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
// <http://www.gnu.org/licenses/>.
1818

1919
#include "rust-feature-gate.h"
20+
#include "config.h"
21+
#include "is-a.h"
2022
#include "rust-abi.h"
23+
#include "rust-ast.h"
2124
#include "rust-attribute-values.h"
2225
#include "rust-ast-visitor.h"
2326
#include "rust-feature.h"
2427
#include "rust-ast-full.h"
28+
#include "rust-item.h"
29+
#include "rust-path.h"
30+
#include "rust-type.h"
31+
#include "rust-tyty.h"
32+
#include <iostream>
2533

2634
namespace Rust {
2735

@@ -236,4 +244,46 @@ FeatureGate::visit (AST::UseTreeGlob &use)
236244
// #[feature(prelude_import)]
237245
}
238246

247+
void
248+
FeatureGate::visit (AST::RawPointerType &type)
249+
{
250+
auto &t = static_cast<AST::TypePath &> (type.get_type_pointed_to ());
251+
if (t.get_num_segments () == 1)
252+
{
253+
auto seg
254+
= static_cast<AST::TypePathSegment> (*t.get_segments ().at (0).get ());
255+
if (seg.is_big_self_seg ())
256+
gate (Feature::Name::ARBITRARY_SELF_TYPES, type.get_locus (),
257+
"arbitrary self types are experimental");
258+
}
259+
}
260+
261+
void
262+
FeatureGate::visit (AST::ImplTraitType &type)
263+
{
264+
gate (Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE, type.get_locus (),
265+
"impl trait in assoc type is experimental");
266+
}
267+
268+
void
269+
FeatureGate::visit (AST::ImplTraitTypeOneBound &type)
270+
{
271+
gate (Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE, type.get_locus (),
272+
"impl trait in assoc type is experimental");
273+
}
274+
275+
void
276+
FeatureGate::visit (AST::Attribute &attr)
277+
{
278+
if (attr.get_path().as_string() == "register_tool")
279+
gate (Feature::Name::REGISTER_TOOL, attr.get_locus (),
280+
"register tool is an experimental feature");
281+
}
282+
283+
void
284+
FeatureGate::visit (AST::TypeAlias &type)
285+
{
286+
287+
}
288+
239289
} // namespace Rust

gcc/rust/checks/errors/rust-feature-gate.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#define RUST_FEATURE_GATE_H
2121

2222
#include "rust-ast-visitor.h"
23+
#include "rust-ast.h"
2324
#include "rust-feature.h"
25+
#include "rust-item.h"
26+
#include "rust-path.h"
27+
#include "rust-type.h"
2428

2529
namespace Rust {
2630

@@ -47,6 +51,11 @@ class FeatureGate : public AST::DefaultASTVisitor
4751
void visit (AST::ExternBlock &block) override;
4852
void visit (AST::MacroRulesDefinition &rules_def) override;
4953
void visit (AST::RangePattern &pattern) override;
54+
void visit (AST::RawPointerType &type) override;
55+
void visit (AST::ImplTraitType &type) override;
56+
void visit (AST::ImplTraitTypeOneBound &type) override;
57+
void visit (AST::Attribute &attr) override;
58+
void visit (AST::TypeAlias &attr) override;
5059

5160
private:
5261
void gate (Feature::Name name, location_t loc, const std::string &error_msg);

gcc/rust/checks/errors/rust-feature.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ Feature::create (Feature::Name f)
5858
case Feature::Name::AUTO_TRAITS:
5959
return Feature (f, Feature::State::ACTIVE, "optin_builtin_traits",
6060
"1.0.0", 13231);
61+
case Feature::Name::ARBITRARY_SELF_TYPES:
62+
return Feature (f, Feature::State::ACCEPTED, "arbitrary_self_types", "1.49.0", 44874);
63+
case Feature::Name::DOC_CFG:
64+
return Feature (f, Feature::State::ACCEPTED, "doc_cfg", "1.49.0", 43781);
65+
case Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE:
66+
return Feature (f, Feature::State::ACCEPTED, "impl_trait_in_assoc_type", "1.49.0", 63063);
67+
case Feature::Name::REGISTER_TOOL:
68+
return Feature (f, Feature::State::ACCEPTED, "register_tool", "1.49.0", 66079);
69+
case Feature::Name::ASSOCIATED_TYPE_DEFAULTS:
70+
return Feature (f, Feature::State::ACCEPTED, "associated_type_defaults", "1.49.0", 29661);
71+
case Feature::Name::CONST_TRAIT_IMPL:
72+
return Feature (f, Feature::State::ACCEPTED, "const_trait_impl", "1.49.0", 67792);
6173
default:
6274
rust_unreachable ();
6375
}
@@ -80,6 +92,13 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
8092
{"raw_ref_op", Feature::Name::RAW_REF_OP},
8193
{"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
8294
{"prelude_import", Feature::Name::PRELUDE_IMPORT},
95+
// Required features for Rust for Linux
96+
{"arbitrary_self_types", Feature::Name::ARBITRARY_SELF_TYPES},
97+
{"doc_cfg", Feature::Name::DOC_CFG},
98+
{"impl_trait_in_assoc_type", Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE},
99+
{"register_tool", Feature::Name::REGISTER_TOOL},
100+
{"associated_type_defaults", Feature::Name::ASSOCIATED_TYPE_DEFAULTS},
101+
{"const_trait_impl", Feature::Name::CONST_TRAIT_IMPL},
83102
}; // namespace Rust
84103

85104
tl::optional<Feature::Name>

gcc/rust/checks/errors/rust-feature.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class Feature
5151
RAW_REF_OP,
5252
EXCLUSIVE_RANGE_PATTERN,
5353
PRELUDE_IMPORT,
54+
ARBITRARY_SELF_TYPES,
55+
DOC_CFG,
56+
IMPL_TRAIT_IN_ASSOC_TYPE,
57+
REGISTER_TOOL,
58+
ASSOCIATED_TYPE_DEFAULTS,
59+
CONST_TRAIT_IMPL,
5460
};
5561

5662
const std::string &as_string () { return m_name_str; }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(arbitrary_self_types)]
2+
3+
trait Foo {
4+
fn bar(self: *const Self);
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Foo {
2+
fn bar(self: *const Self); // { dg-error "arbitrary self types are experimental." }
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![feature(associated_type_defaults)]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![feature(const_trait_impl)]

0 commit comments

Comments
 (0)