Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 49 additions & 0 deletions gcc/rust/checks/errors/feature/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ FeatureGate::check_may_dangle_attribute (
}
}

void
FeatureGate::check_lang_item_attribute (
const std::vector<AST::Attribute> &attributes)
{
for (const AST::Attribute &attr : attributes)
{
const auto &str_path = attr.get_path ().as_string ();
bool is_lang_item = str_path == Values::Attributes::LANG
&& attr.has_attr_input ()
&& attr.get_attr_input ().get_attr_input_type ()
== AST::AttrInput::AttrInputType::LITERAL;

if (is_lang_item)
gate (Feature::Name::LANG_ITEMS, attr.get_locus (),
"lang items are subject to change");
}
}

void
FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
{
Expand All @@ -158,6 +176,8 @@ FeatureGate::visit (AST::Function &function)
if (!function.is_external ())
check_rustc_attri (function.get_outer_attrs ());

check_lang_item_attribute (function.get_outer_attrs ());

AST::DefaultASTVisitor::visit (function);
}

Expand Down Expand Up @@ -186,6 +206,7 @@ FeatureGate::visit (AST::Trait &trait)
if (trait.is_auto ())
gate (Feature::Name::OPTIN_BUILTIN_TRAITS, trait.get_locus (),
"auto traits are experimental and possibly buggy");
check_lang_item_attribute (trait.get_outer_attrs ());
AST::DefaultASTVisitor::visit (trait);
}

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

void
FeatureGate::visit (AST::StructStruct &struct_item)
{
check_lang_item_attribute (struct_item.get_outer_attrs ());
AST::DefaultASTVisitor::visit (struct_item);
}

void
FeatureGate::visit (AST::TraitItemType &trait_item_type)
{
check_lang_item_attribute (trait_item_type.get_outer_attrs ());
AST::DefaultASTVisitor::visit (trait_item_type);
}

void
FeatureGate::visit (AST::Enum &enum_item)
{
check_lang_item_attribute (enum_item.get_outer_attrs ());
AST::DefaultASTVisitor::visit (enum_item);
}

void
FeatureGate::visit (AST::EnumItem &enum_variant)
{
check_lang_item_attribute (enum_variant.get_outer_attrs ());
AST::DefaultASTVisitor::visit (enum_variant);
}

} // namespace Rust
6 changes: 6 additions & 0 deletions gcc/rust/checks/errors/feature/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ 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::StructStruct &struct_item) override;
void visit (AST::TraitItemType &trait_item_type) override;
void visit (AST::Enum &enum_item) override;
void visit (AST::EnumItem &enum_variant) override;

private:
void gate (Feature::Name name, location_t loc, const std::string &error_msg);
void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
void
check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
void
check_lang_item_attribute (const std::vector<AST::Attribute> &attributes);
std::set<Feature::Name> valid_features;
};
} // namespace Rust
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/borrowck/reference.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }

#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/borrowck/tmp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
// { dg-enable-nn-line-numbers "" }

#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/additional-trait-bounds1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(optin_builtin_traits)]
#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
#[lang = "sync"]
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/additional-trait-bounds2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(optin_builtin_traits)]
#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
#[lang = "sync"]
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(optin_builtin_traits)]
#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
#[lang = "sync"]
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/auto_traits1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// { dg-additional-options "-frust-compile-until=typecheck" }

#![feature(optin_builtin_traits)]
#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
#[lang = "sync"]
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/auto_traits2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(optin_builtin_traits)]
#![feature(optin_builtin_traits, lang_items)]

pub unsafe auto trait Send {}
#[lang = "sync"]
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/bad-rpit1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/black_box.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-options "-fdump-tree-gimple" }
#![feature(rustc_attrs)]
#![feature(rustc_attrs, lang_items)]

#[lang = "sized"]
pub trait Sized {}
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/bounds1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// { dg-options "-frust-compile-until=lowering" }
#![feature(lang_items)]
#[lang = "owned_box"]
pub struct Box<T>;

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/bug-with-default-generic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/canonical_paths1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// { dg-additional-options "-w -fdump-tree-gimple -frust-crate=example" }
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/cast_generics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/closure_no_type_anno.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/cmp1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// { dg-options "-w" }
// taken from https://github.com/rust-lang/rust/blob/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/cmp.rs#L98

#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const-issue1440.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// { dg-additional-options "-w" }
#![feature(intrinsics)]

#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// There are errors about unused generic parameters, but we can't handle that yet.
// Still, this code is invalid Rust.

#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_10.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/const_generics_11.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-options "-w" }

#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/const_generics_12.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-options "-w" }

#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_13.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_14.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_15.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_16.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_18.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_19.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/const_generics_8.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/const_generics_9.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-options "-w" }

#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/derive-debug1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}

Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/derive-default1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lang_items)]

#[derive(Default)]
struct Foo { _a: i32, _b: i64, _c: u8 }

Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/derive-eq-invalid.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lang_items)]

mod core {
mod cmp {
#[lang = "eq"]
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/derive-hash1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(intrinsics)]
#![feature(intrinsics, lang_items)]

#[lang = "sized"]
trait Sized {}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/derive-partialeq1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(intrinsics)]
#![feature(intrinsics, lang_items)]

#[lang = "sized"]
trait Sized {}
Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/derive_clone_enum1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lang_items)]

#[lang = "clone"]
trait Clone {
pub fn clone(&self) -> Self;
Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/derive_clone_enum2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lang_items)]

#[lang = "clone"]
trait Clone {
pub fn clone(&self) -> Self;
Expand Down
2 changes: 2 additions & 0 deletions gcc/testsuite/rust/compile/derive_clone_enum3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lang_items)]

#[lang = "clone"]
trait Clone {
pub fn clone(&self) -> Self;
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/derive_macro1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/derive_macro3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/derive_macro4.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/derive_macro6.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/derive_partial_ord1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// { dg-additional-options "-w" }

#![feature(intrinsics)]
#![feature(intrinsics, lang_items)]

mod core {
mod option {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// this SEGVs in lowering for now
// { dg-additional-options "-frust-compile-until=nameresolution" }
#![feature(lang_items)]

macro_rules! forward_ref_binop {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/expected_type_args2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/expected_type_args3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lang_items)]
#[lang = "sized"]
pub trait Sized {}

Expand Down
3 changes: 2 additions & 1 deletion gcc/testsuite/rust/compile/extern_generics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[lang="sized"]
#![feature(lang_items)]
#[lang = "sized"]
trait Sized {}


Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/for-loop1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-output "loop\r*\nloop\r*\n" }
#![feature(intrinsics)]
#![feature(intrinsics, lang_items)]

pub use option::Option::{self, None, Some};
pub use result::Result::{self, Err, Ok};
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/for-loop2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// { dg-output "1\r*\n2\r*\n" }
#![feature(intrinsics)]
#![feature(intrinsics, lang_items)]

pub use option::Option::{self, None, Some};
pub use result::Result::{self, Err, Ok};
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/format_args_basic_expansion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(rustc_attrs)]
#![feature(rustc_attrs, lang_items)]

#[rustc_builtin_macro]
macro_rules! format_args {
Expand Down
Loading