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

-2
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

+1-1
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

+50
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

+9
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

+19
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

+6
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; }
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+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![feature(associated_type_defaults)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![feature(const_trait_impl)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(doc_cfg)]
2+
3+
#[cfg(any(windows, doc))]
4+
#[doc(cfg(windows))]
5+
/// The application's icon in the notification area (a.k.a. system tray).
6+
///
7+
/// # Examples
8+
///
9+
/// ```no_run
10+
/// extern crate my_awesome_ui_library;
11+
/// use my_awesome_ui_library::current_app;
12+
/// use my_awesome_ui_library::windows::notification;
13+
///
14+
/// let icon = current_app().get::<notification::Icon>();
15+
/// icon.show();
16+
/// icon.show_message("Hello");
17+
/// ```
18+
pub struct Icon {
19+
// ...
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[cfg(any(windows, doc))]
2+
#[doc(cfg(windows))]
3+
/// The application's icon in the notification area (a.k.a. system tray).
4+
///
5+
/// # Examples
6+
///
7+
/// ```no_run
8+
/// extern crate my_awesome_ui_library;
9+
/// use my_awesome_ui_library::current_app;
10+
/// use my_awesome_ui_library::windows::notification;
11+
///
12+
/// let icon = current_app().get::<notification::Icon>();
13+
/// icon.show();
14+
/// icon.show_message("Hello");
15+
/// ```
16+
pub struct Icon {
17+
// ...
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2021-2024 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with GCC; see the file COPYING3. If not see
15+
# <http://www.gnu.org/licenses/>.
16+
17+
# Compile tests, no torture testing.
18+
#
19+
# These tests raise errors in the front end; torture testing doesn't apply.
20+
21+
# Load support procs.
22+
load_lib rust-dg.exp
23+
24+
# Initialize `dg'.
25+
dg-init
26+
27+
# Main loop.
28+
set saved-dg-do-what-default ${dg-do-what-default}
29+
30+
set dg-do-what-default "compile"
31+
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
32+
set dg-do-what-default ${saved-dg-do-what-default}
33+
34+
# All done.
35+
dg-finish
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// check-pass
2+
// { dg-additional-options "-frust-compile-until=lowering" }
3+
4+
#![feature(impl_trait_in_assoc_type)]
5+
6+
fn main() {}
7+
8+
trait Bar {
9+
type Assoc;
10+
}
11+
12+
trait Thing {
13+
type Out;
14+
fn func() -> Self::Out;
15+
}
16+
17+
struct AssocIsCopy;
18+
impl Bar for AssocIsCopy {
19+
type Assoc = u8;
20+
}
21+
22+
impl Thing for AssocIsCopy {
23+
type Out = impl Bar<Assoc: Copy>;
24+
25+
fn func() -> Self::Out {
26+
AssocIsCopy
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// { dg-additional-options "-frust-compile-until=lowering" }
2+
3+
fn main() {}
4+
5+
trait Bar {
6+
type Assoc;
7+
}
8+
9+
trait Thing {
10+
type Out;
11+
fn func() -> Self::Out;
12+
}
13+
14+
struct AssocIsCopy;
15+
impl Bar for AssocIsCopy {
16+
type Assoc = u8;
17+
}
18+
19+
impl Thing for AssocIsCopy {
20+
type Out = impl Bar<Assoc: Copy>; // { dg-error "impl trait in assoc type is experimental" }
21+
22+
fn func() -> Self::Out {
23+
AssocIsCopy
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(register_tool)]
2+
#![register_tool(my_tool)]
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![register_tool(my_tool)] // { dg-error "register tool is an experimental feature" }
2+
3+
fn main() {}

0 commit comments

Comments
 (0)