aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjjasmine <tanghocle456@gmail.com>2024-05-15 12:44:15 -0700
committerCohenArthur <arthur.cohen@embecosm.com>2024-05-24 09:27:42 +0000
commit84666c6eecc0d32019f03169b2ba242ead1e2d49 (patch)
treeb21343ca6d9492b82a619306eb7b39ba1e37ca2e
parent219cea788152068895ece969d0462c7b6a102a69 (diff)
downloadgcc-84666c6eecc0d32019f03169b2ba242ead1e2d49.zip
gcc-84666c6eecc0d32019f03169b2ba242ead1e2d49.tar.gz
gcc-84666c6eecc0d32019f03169b2ba242ead1e2d49.tar.bz2
Make gccrs recognize negative_impls
gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): make gccrs recognize negative_impls * checks/errors/rust-feature-gate.h: likewise. * checks/errors/rust-feature.cc (Feature::create): likewise. * checks/errors/rust-feature.h: likewise. gcc/testsuite/ChangeLog: * rust/compile/negative_impls.rs: New test. * rust/compile/negative_impls_2.rs: New test.
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.cc9
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.h1
-rw-r--r--gcc/rust/checks/errors/rust-feature.cc4
-rw-r--r--gcc/rust/checks/errors/rust-feature.h1
-rw-r--r--gcc/testsuite/rust/compile/negative_impls.rs8
-rw-r--r--gcc/testsuite/rust/compile/negative_impls_2.rs16
6 files changed, 39 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc
index 33bbfa1..eb23192 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -19,6 +19,7 @@
#include "rust-feature-gate.h"
#include "rust-abi.h"
#include "rust-ast-visitor.h"
+#include "rust-feature.h"
namespace Rust {
@@ -144,4 +145,12 @@ FeatureGate::visit (AST::ExternalTypeItem &item)
"extern types are experimental");
}
+void
+FeatureGate::visit (AST::TraitImpl &impl)
+{
+ if (impl.is_exclam ())
+ gate (Feature::Name::NEGATIVE_IMPLS, impl.get_locus (),
+ "negative_impls are not yet implemented");
+};
+
} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index 481b5a5..d7c84a5 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -127,6 +127,7 @@ public:
void visit (AST::StaticItem &static_item) override {}
void visit (AST::TraitItemConst &item) override {}
void visit (AST::TraitItemType &item) override {}
+ void visit (AST::TraitImpl &impl) override;
void visit (AST::Trait &trait) override {}
void visit (AST::ExternalTypeItem &item) override;
void visit (AST::ExternalStaticItem &item) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc
index c12710a..6249758 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -42,6 +42,9 @@ Feature::create (Feature::Name name)
case Feature::Name::EXTERN_TYPES:
return Feature (Feature::Name::EXTERN_TYPES, Feature::State::ACTIVE,
"extern_types", "1.23.0", 43467, tl::nullopt, "");
+ case Feature::Name::NEGATIVE_IMPLS:
+ return Feature (Feature::Name::NEGATIVE_IMPLS, Feature::State::ACTIVE,
+ "negative_impls", "1.0.0", 68318, tl::nullopt, "");
default:
rust_unreachable ();
}
@@ -52,6 +55,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
{"intrinsics", Feature::Name::INTRINSICS},
{"rustc_attrs", Feature::Name::RUSTC_ATTRS},
{"decl_macro", Feature::Name::DECL_MACRO},
+ {"negative_impls", Feature::Name::NEGATIVE_IMPLS},
// TODO: Rename to "auto_traits" when supporting
// later Rust versions
{"optin_builtin_traits", Feature::Name::AUTO_TRAITS},
diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h
index e6bc236..306baf2 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -39,6 +39,7 @@ public:
{
ASSOCIATED_TYPE_BOUNDS,
INTRINSICS,
+ NEGATIVE_IMPLS,
RUSTC_ATTRS,
DECL_MACRO,
AUTO_TRAITS,
diff --git a/gcc/testsuite/rust/compile/negative_impls.rs b/gcc/testsuite/rust/compile/negative_impls.rs
new file mode 100644
index 0000000..949a390
--- /dev/null
+++ b/gcc/testsuite/rust/compile/negative_impls.rs
@@ -0,0 +1,8 @@
+#![feature(negative_impls)]
+
+trait ExampleTrait {}
+
+impl !ExampleTrait for i32 {}
+
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/negative_impls_2.rs b/gcc/testsuite/rust/compile/negative_impls_2.rs
new file mode 100644
index 0000000..d66fbc9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/negative_impls_2.rs
@@ -0,0 +1,16 @@
+// This test case should error out since we haven't included the negative_impls feature
+// Output from online rust compiler 2021 ver
+// Compiling playground v0.0.1 (/playground)
+// error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
+// --> src/main.rs:8:6
+// |
+// 8 | impl !ExampleTrait for i32 {}//
+// | ^^^^^^^^^^^^^
+// |
+// = note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
+
+// For more information about this error, try `rustc --explain E0658`.
+// error: could not compile `playground` (bin "playground") due to 1 previous error
+trait ExampleTrait {}
+
+impl !ExampleTrait for i32 {} // { dg-error "negative_impls are not yet implemented" } \ No newline at end of file