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

Make gccrs recognize negative_impls #3002

Merged
merged 1 commit into from
May 24, 2024
Merged
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
9 changes: 9 additions & 0 deletions gcc/rust/checks/errors/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "rust-feature-gate.h"
#include "rust-abi.h"
#include "rust-ast-visitor.h"
#include "rust-feature.h"

namespace Rust {

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class FeatureGate : public AST::DefaultASTVisitor
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 {}
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/checks/errors/rust-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand All @@ -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},
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/rust-feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Feature
{
ASSOCIATED_TYPE_BOUNDS,
INTRINSICS,
NEGATIVE_IMPLS,
RUSTC_ATTRS,
DECL_MACRO,
AUTO_TRAITS,
Expand Down
8 changes: 8 additions & 0 deletions gcc/testsuite/rust/compile/negative_impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(negative_impls)]

trait ExampleTrait {}

impl !ExampleTrait for i32 {}


fn main() {}
16 changes: 16 additions & 0 deletions gcc/testsuite/rust/compile/negative_impls_2.rs
Original file line number Diff line number Diff line change
@@ -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" }
Loading