@@ -17,14 +17,15 @@
// <http://www.gnu.org/licenses/>.
#include "rust-feature-gate.h"
-#include "rust-feature.h"
+#include "rust-abi.h"
namespace Rust {
void
FeatureGate::check (AST::Crate &crate)
{
- std::vector<Feature> valid_features;
+ valid_features.clear ();
+
for (const auto &attr : crate.inner_attrs)
{
if (attr.get_path ().as_string () == "feature")
@@ -39,20 +40,22 @@ FeatureGate::check (AST::Crate &crate)
option.parse_to_meta_item ());
for (const auto &item : meta_item->get_items ())
{
- const auto &name = item->as_string ();
- auto tname = Feature::as_name (name);
+ const auto &name_str = item->as_string ();
+ auto tname = Feature::as_name (name_str);
if (!tname.is_none ())
- valid_features.push_back (Feature::create (tname.get ()));
+ {
+ auto name = tname.get ();
+ valid_features.insert (name);
+ }
+
else
rust_error_at (item->get_locus (), "unknown feature '%s'",
- name.c_str ());
+ name_str.c_str ());
}
}
}
}
- valid_features.shrink_to_fit ();
- // TODO (mxlol233): add the real feature gate stuff.
auto &items = crate.items;
for (auto it = items.begin (); it != items.end (); it++)
{
@@ -60,4 +63,46 @@ FeatureGate::check (AST::Crate &crate)
item->accept_vis (*this);
}
}
+
+void
+FeatureGate::gate (Feature::Name name, Location loc,
+ const std::string &error_msg)
+{
+ if (!valid_features.count (name))
+ {
+ auto feature = Feature::create (name);
+ auto issue = feature.issue ();
+ if (issue > 0)
+ {
+ const char *fmt_str
+ = "%s. see issue %ld "
+ "<https://github.com/rust-lang/rust/issues/%ld> for more "
+ "information. add `#![feature(%s)]` to the crate attributes to "
+ "enable.";
+ rust_error_at (loc, fmt_str, error_msg.c_str (), issue, issue,
+ feature.as_string ().c_str ());
+ }
+ else
+ {
+ const char *fmt_str
+ = "%s. add `#![feature(%s)]` to the crate attributes to enable.";
+ rust_error_at (loc, fmt_str, error_msg.c_str (),
+ feature.as_string ().c_str ());
+ }
+ }
+}
+
+void
+FeatureGate::visit (AST::ExternBlock &block)
+{
+ if (block.has_abi ())
+ {
+ const auto abi = block.get_abi ();
+
+ if (get_abi_from_string (abi) == ABI::INTRINSIC)
+ gate (Feature::Name::INTRINSICS, block.get_locus (),
+ "intrinsics are subject to change");
+ }
+}
+
} // namespace Rust
\ No newline at end of file
@@ -21,6 +21,7 @@
#include "rust-ast-visitor.h"
#include "rust-ast-full.h"
+#include "rust-feature.h"
namespace Rust {
@@ -136,7 +137,7 @@ public:
void visit (AST::TraitImpl &impl) override {}
void visit (AST::ExternalStaticItem &item) override {}
void visit (AST::ExternalFunctionItem &item) override {}
- void visit (AST::ExternBlock &block) override {}
+ void visit (AST::ExternBlock &block) override;
void visit (AST::MacroMatchFragment &match) override {}
void visit (AST::MacroMatchRepetition &match) override {}
void visit (AST::MacroMatcher &matcher) override {}
@@ -186,6 +187,10 @@ public:
void visit (AST::SliceType &type) override {}
void visit (AST::InferredType &type) override {}
void visit (AST::BareFunctionType &type) override {}
+
+private:
+ void gate (Feature::Name name, Location loc, const std::string &error_msg);
+ std::set<Feature::Name> valid_features;
};
} // namespace Rust
#endif
\ No newline at end of file
@@ -47,6 +47,7 @@ public:
Name name () { return m_name; }
const std::string &description () { return m_description; }
State state () { return m_state; }
+ uint64_t issue () { return m_issue; }
static Optional<Name> as_name (const std::string &name);
static Feature create (Name name);
@@ -57,7 +58,7 @@ private:
const Optional<CompileOptions::Edition> &edition,
const char *description)
: m_state (state), m_name (name), m_name_str (name_str),
- m_rustc_since (rustc_since), issue (issue_number), edition (edition),
+ m_rustc_since (rustc_since), m_issue (issue_number), edition (edition),
m_description (description)
{}
@@ -65,7 +66,7 @@ private:
Name m_name;
std::string m_name_str;
std::string m_rustc_since;
- uint64_t issue;
+ uint64_t m_issue;
Optional<CompileOptions::Edition> edition;
std::string m_description;
@@ -1,4 +1,5 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
mod intrinsics {
extern "rust-intrinsic" {
new file mode 100644
@@ -0,0 +1,7 @@
+
+extern "rust-intrinsic" { //{ dg-error "intrinsics are subject to change." "" { target *-*-* } }
+ pub fn sqrtf32(x: f32) -> f32;
+}
+
+fn main() {
+}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
mod mem {
extern "rust-intrinsic" {
fn size_of<T>() -> usize;
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
fn size_of<T>() -> usize;
fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
mod intrinsics {
extern "rust-intrinsic" {
pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "C" {
fn printf(s: *const i8, ...);
}
@@ -1,4 +1,6 @@
// { dg-excess-errors "accessing value of" }
+#![feature(intrinsics)]
+
mod mem {
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
fn not_an_intrinsic();
}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
#[lang = "sized"]
pub trait Sized {}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
#[lang = "sized"]
pub trait Sized {}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn unchecked_add<T>(x: T, y: T) -> T;
pub fn unchecked_sub<T>(x: T, y: T) -> T;
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn unchecked_add<T>(x: T, y: T) -> T;
// { dg-error "unchecked operation intrinsics can only be used with basic integer types .got .NotAdd.." "" { target *-*-* } .-1 }
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn size_of<T>() -> usize;
}
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,5 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
mod intrinsics {
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn rotate_left<T>(l: T, r: T) -> T;
}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
#[lang = "sized"]
pub trait Sized {}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
#[lang = "sized"]
pub trait Sized {}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,5 +1,7 @@
// { dg-additional-options "-w" }
// { dg-output "slice_access=3\r*\n" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,4 +1,6 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
@@ -1,5 +1,7 @@
// { dg-additional-options "-w" }
// { dg-output "t1sz=5 t2sz=10\r*" }
+#![feature(intrinsics)]
+
mod mem {
extern "rust-intrinsic" {
#[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
@@ -1,4 +1,5 @@
// { dg-additional-options "-w" }
+#![feature(intrinsics)]
extern "rust-intrinsic" {
fn transmute<T, U>(value: T) -> U;
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn wrapping_add<T>(l: T, r: T) -> T;
}
@@ -1,3 +1,5 @@
+#![feature(intrinsics)]
+
extern "rust-intrinsic" {
pub fn wrapping_add<T>(l: T, r: T) -> T;
pub fn wrapping_sub<T>(l: T, r: T) -> T;