Skip to content

Commit

Permalink
gcc/rust/ChangeLog:
Browse files Browse the repository at this point in the history
	* 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.
  • Loading branch information
MajoraSans committed Dec 18, 2024
1 parent daa2977 commit 8a82b04
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 3 deletions.
2 changes: 0 additions & 2 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,6 @@ DefaultASTVisitor::visit (AST::Function &function)
visit (function.get_qualifiers ());
for (auto &generic : function.get_generic_params ())
visit (generic);
if (function.has_self_param ())
visit (function.get_self_param ());
for (auto &param : function.get_function_params ())
visit (param);
if (function.has_return_type ())
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::StructPatternElements &spe);
virtual void visit (AST::MaybeNamedParam &param);

void visit (AST::Attribute &attribute) {}
virtual void visit (AST::Attribute &attribute) {}

template <typename T> void visit_outer_attrs (T &node)
{
Expand Down
50 changes: 50 additions & 0 deletions gcc/rust/checks/errors/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@
// <http://www.gnu.org/licenses/>.

#include "rust-feature-gate.h"
#include "config.h"
#include "is-a.h"
#include "rust-abi.h"
#include "rust-ast.h"
#include "rust-attribute-values.h"
#include "rust-ast-visitor.h"
#include "rust-feature.h"
#include "rust-ast-full.h"
#include "rust-item.h"
#include "rust-path.h"
#include "rust-type.h"
#include "rust-tyty.h"
#include <iostream>

namespace Rust {

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

void
FeatureGate::visit (AST::RawPointerType &type)
{
auto &t = static_cast<AST::TypePath &> (type.get_type_pointed_to ());
if (t.get_num_segments () == 1)
{
auto seg
= static_cast<AST::TypePathSegment> (*t.get_segments ().at (0).get ());
if (seg.is_big_self_seg ())
gate (Feature::Name::ARBITRARY_SELF_TYPES, type.get_locus (),
"arbitrary self types are experimental");
}
}

void
FeatureGate::visit (AST::ImplTraitType &type)
{
gate (Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE, type.get_locus (),
"impl trait in assoc type is experimental");
}

void
FeatureGate::visit (AST::ImplTraitTypeOneBound &type)
{
gate (Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE, type.get_locus (),
"impl trait in assoc type is experimental");
}

void
FeatureGate::visit (AST::Attribute &attr)
{
if (attr.get_path().as_string() == "register_tool")
gate (Feature::Name::REGISTER_TOOL, attr.get_locus (),
"register tool is an experimental feature");
}

void
FeatureGate::visit (AST::TypeAlias &type)
{

}

} // namespace Rust
9 changes: 9 additions & 0 deletions gcc/rust/checks/errors/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#define RUST_FEATURE_GATE_H

#include "rust-ast-visitor.h"
#include "rust-ast.h"
#include "rust-feature.h"
#include "rust-item.h"
#include "rust-path.h"
#include "rust-type.h"

namespace Rust {

Expand All @@ -47,6 +51,11 @@ class FeatureGate : public AST::DefaultASTVisitor
void visit (AST::ExternBlock &block) override;
void visit (AST::MacroRulesDefinition &rules_def) override;
void visit (AST::RangePattern &pattern) override;
void visit (AST::RawPointerType &type) override;
void visit (AST::ImplTraitType &type) override;
void visit (AST::ImplTraitTypeOneBound &type) override;
void visit (AST::Attribute &attr) override;
void visit (AST::TypeAlias &attr) override;

private:
void gate (Feature::Name name, location_t loc, const std::string &error_msg);
Expand Down
19 changes: 19 additions & 0 deletions gcc/rust/checks/errors/rust-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ Feature::create (Feature::Name f)
case Feature::Name::AUTO_TRAITS:
return Feature (f, Feature::State::ACTIVE, "optin_builtin_traits",
"1.0.0", 13231);
case Feature::Name::ARBITRARY_SELF_TYPES:
return Feature (f, Feature::State::ACCEPTED, "arbitrary_self_types", "1.49.0", 44874);
case Feature::Name::DOC_CFG:
return Feature (f, Feature::State::ACCEPTED, "doc_cfg", "1.49.0", 43781);
case Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE:
return Feature (f, Feature::State::ACCEPTED, "impl_trait_in_assoc_type", "1.49.0", 63063);
case Feature::Name::REGISTER_TOOL:
return Feature (f, Feature::State::ACCEPTED, "register_tool", "1.49.0", 66079);
case Feature::Name::ASSOCIATED_TYPE_DEFAULTS:
return Feature (f, Feature::State::ACCEPTED, "associated_type_defaults", "1.49.0", 29661);
case Feature::Name::CONST_TRAIT_IMPL:
return Feature (f, Feature::State::ACCEPTED, "const_trait_impl", "1.49.0", 67792);
default:
rust_unreachable ();
}
Expand All @@ -80,6 +92,13 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
{"raw_ref_op", Feature::Name::RAW_REF_OP},
{"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
{"prelude_import", Feature::Name::PRELUDE_IMPORT},
// Required features for Rust for Linux
{"arbitrary_self_types", Feature::Name::ARBITRARY_SELF_TYPES},
{"doc_cfg", Feature::Name::DOC_CFG},
{"impl_trait_in_assoc_type", Feature::Name::IMPL_TRAIT_IN_ASSOC_TYPE},
{"register_tool", Feature::Name::REGISTER_TOOL},
{"associated_type_defaults", Feature::Name::ASSOCIATED_TYPE_DEFAULTS},
{"const_trait_impl", Feature::Name::CONST_TRAIT_IMPL},
}; // namespace Rust

tl::optional<Feature::Name>
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/checks/errors/rust-feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Feature
RAW_REF_OP,
EXCLUSIVE_RANGE_PATTERN,
PRELUDE_IMPORT,
ARBITRARY_SELF_TYPES,
DOC_CFG,
IMPL_TRAIT_IN_ASSOC_TYPE,
REGISTER_TOOL,
ASSOCIATED_TYPE_DEFAULTS,
CONST_TRAIT_IMPL,
};

const std::string &as_string () { return m_name_str; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![feature(arbitrary_self_types)]

trait Foo {
fn bar(self: *const Self);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait Foo {
fn bar(self: *const Self); // { dg-error "arbitrary self types are experimental." }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![feature(associated_type_defaults)]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#![feature(const_trait_impl)]
20 changes: 20 additions & 0 deletions gcc/testsuite/rust/compile/features/doc_cfg_activated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(doc_cfg)]

#[cfg(any(windows, doc))]
#[doc(cfg(windows))]
/// The application's icon in the notification area (a.k.a. system tray).
///
/// # Examples
///
/// ```no_run
/// extern crate my_awesome_ui_library;
/// use my_awesome_ui_library::current_app;
/// use my_awesome_ui_library::windows::notification;
///
/// let icon = current_app().get::<notification::Icon>();
/// icon.show();
/// icon.show_message("Hello");
/// ```
pub struct Icon {
// ...
}
18 changes: 18 additions & 0 deletions gcc/testsuite/rust/compile/features/doc_cfg_not_activated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[cfg(any(windows, doc))]
#[doc(cfg(windows))]
/// The application's icon in the notification area (a.k.a. system tray).
///
/// # Examples
///
/// ```no_run
/// extern crate my_awesome_ui_library;
/// use my_awesome_ui_library::current_app;
/// use my_awesome_ui_library::windows::notification;
///
/// let icon = current_app().get::<notification::Icon>();
/// icon.show();
/// icon.show_message("Hello");
/// ```
pub struct Icon {
// ...
}
35 changes: 35 additions & 0 deletions gcc/testsuite/rust/compile/features/feature.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2021-2024 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.

# Compile tests, no torture testing.
#
# These tests raise errors in the front end; torture testing doesn't apply.

# Load support procs.
load_lib rust-dg.exp

# Initialize `dg'.
dg-init

# Main loop.
set saved-dg-do-what-default ${dg-do-what-default}

set dg-do-what-default "compile"
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
set dg-do-what-default ${saved-dg-do-what-default}

# All done.
dg-finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// check-pass
// { dg-additional-options "-frust-compile-until=lowering" }

#![feature(impl_trait_in_assoc_type)]

fn main() {}

trait Bar {
type Assoc;
}

trait Thing {
type Out;
fn func() -> Self::Out;
}

struct AssocIsCopy;
impl Bar for AssocIsCopy {
type Assoc = u8;
}

impl Thing for AssocIsCopy {
type Out = impl Bar<Assoc: Copy>;

fn func() -> Self::Out {
AssocIsCopy
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// { dg-additional-options "-frust-compile-until=lowering" }

fn main() {}

trait Bar {
type Assoc;
}

trait Thing {
type Out;
fn func() -> Self::Out;
}

struct AssocIsCopy;
impl Bar for AssocIsCopy {
type Assoc = u8;
}

impl Thing for AssocIsCopy {
type Out = impl Bar<Assoc: Copy>; // { dg-error "impl trait in assoc type is experimental" }

fn func() -> Self::Out {
AssocIsCopy
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![feature(register_tool)]
#![register_tool(my_tool)]

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![register_tool(my_tool)] // { dg-error "register tool is an experimental feature" }

fn main() {}

0 comments on commit 8a82b04

Please sign in to comment.