Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required features for Rust For Linux #3309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need virtual i dont see where your overriding it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait scratch that i see now sorry


template <typename T> void visit_outer_attrs (T &node)
{
Expand Down
44 changes: 44 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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use rust-system.h i dont see why you need iostream and rust-tyty.h for the type abstractions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not need them actually, my lsp just went overboard with the includes ^^'


namespace Rust {

Expand Down Expand Up @@ -236,4 +244,40 @@ 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");
}

} // namespace Rust
8 changes: 8 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,10 @@ 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;

private:
void gate (Feature::Name name, location_t loc, const std::string &error_msg);
Expand Down
24 changes: 24 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,23 @@ 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 +97,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,15 @@
// check-pass

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_activated.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for excess errors)

// This is another instance of the "normalizations don't work" issue with
// defaulted associated types.

#![feature(associated_type_defaults)]

pub trait Emitter<'a> {
type Ctxt: 'a;
type CtxtBrw: 'a = &'a Self::Ctxt;

fn get_cx(&'a self) -> Self::CtxtBrw;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// check-pass

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_not_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_not_activated.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_not_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_not_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/features/associated_type_defaults_not_activated.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for excess errors)

// This is another instance of the "normalizations don't work" issue with
// defaulted associated types.

// #![feature(associated_type_defaults)]

pub trait Emitter<'a> {
type Ctxt: 'a;
type CtxtBrw: 'a = &'a Self::Ctxt;

fn get_cx(&'a self) -> Self::CtxtBrw;
}

fn main() {}
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() {}
Loading