mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Emit pre-expansion feature gate warning for negative impls
This commit is contained in:
@@ -218,8 +218,8 @@ fn visit_item(&mut self, i: &'a ast::Item) {
|
||||
self,
|
||||
negative_impls,
|
||||
span.to(of_trait.trait_ref.path.span),
|
||||
"negative trait bounds are not fully implemented; \
|
||||
use marker types for now"
|
||||
"negative impls are experimental",
|
||||
"use marker types for now"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -614,6 +614,7 @@ macro_rules! soft_gate_all_legacy_dont_use {
|
||||
soft_gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
|
||||
soft_gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
|
||||
soft_gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
|
||||
soft_gate_all_legacy_dont_use!(negative_impls, "negative impls are experimental");
|
||||
soft_gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
|
||||
soft_gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
|
||||
// tidy-alphabetical-end
|
||||
|
||||
@@ -603,6 +603,7 @@ fn is_async_fn(&self) -> bool {
|
||||
fn parse_polarity(&mut self) -> ast::ImplPolarity {
|
||||
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
|
||||
if self.check(exp!(Bang)) && self.look_ahead(1, |t| t.can_begin_type()) {
|
||||
self.psess.gated_spans.gate(sym::negative_impls, self.token.span);
|
||||
self.bump(); // `!`
|
||||
ast::ImplPolarity::Negative(self.prev_token.span)
|
||||
} else {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
auto trait MyTrait {}
|
||||
//~^ ERROR auto traits are experimental and possibly buggy
|
||||
|
||||
impl<T> !MyTrait for *mut T {}
|
||||
//~^ ERROR negative trait bounds are not fully implemented
|
||||
|
||||
fn main() {}
|
||||
@@ -1,23 +0,0 @@
|
||||
error[E0658]: auto traits are experimental and possibly buggy
|
||||
--> $DIR/ungated-impl.rs:1:1
|
||||
|
|
||||
LL | auto trait MyTrait {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
|
||||
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: negative trait bounds are not fully implemented; use marker types for now
|
||||
--> $DIR/ungated-impl.rs:4:9
|
||||
|
|
||||
LL | impl<T> !MyTrait for *mut T {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
|
||||
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
@@ -1,12 +1,5 @@
|
||||
// Test that default and negative trait implementations are gated by
|
||||
// `auto_traits` feature gate
|
||||
auto trait DummyAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy
|
||||
|
||||
struct DummyStruct;
|
||||
|
||||
auto trait AutoDummyTrait {}
|
||||
//~^ ERROR auto traits are experimental and possibly buggy
|
||||
|
||||
impl !AutoDummyTrait for DummyStruct {}
|
||||
//~^ ERROR negative trait bounds are not fully implemented; use marker types for now
|
||||
pub unsafe auto trait AnotherAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
error[E0658]: auto traits are experimental and possibly buggy
|
||||
--> $DIR/feature-gate-auto-traits.rs:6:1
|
||||
--> $DIR/feature-gate-auto-traits.rs:1:1
|
||||
|
|
||||
LL | auto trait AutoDummyTrait {}
|
||||
LL | auto trait DummyAutoTrait {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
|
||||
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: negative trait bounds are not fully implemented; use marker types for now
|
||||
--> $DIR/feature-gate-auto-traits.rs:9:6
|
||||
error[E0658]: auto traits are experimental and possibly buggy
|
||||
--> $DIR/feature-gate-auto-traits.rs:3:1
|
||||
|
|
||||
LL | impl !AutoDummyTrait for DummyStruct {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
LL | pub unsafe auto trait AnotherAutoTrait {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
|
||||
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
|
||||
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
|
||||
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// For historical reasons, negative impls don't have a proper pre-expansion feature gate.
|
||||
// We're now at least issuing a *warning* for those that only exist before macro expansion.
|
||||
// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one.
|
||||
// As part of this, move these test cases into `feature-gate-negative_impls.rs`.
|
||||
//@ check-pass
|
||||
|
||||
#[cfg(false)]
|
||||
impl !Trait for () {}
|
||||
//~^ WARN negative impls are experimental
|
||||
//~| WARN unstable syntax can change at any point in the future
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,14 @@
|
||||
warning: negative impls are experimental
|
||||
--> $DIR/soft-feature-gate-negative_impls.rs:8:6
|
||||
|
|
||||
LL | impl !Trait for () {}
|
||||
| ^
|
||||
|
|
||||
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
|
||||
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
= warning: unstable syntax can change at any point in the future, causing a hard error!
|
||||
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
trait MyTrait {}
|
||||
impl !MyTrait for u32 {} //~ ERROR negative trait bounds are not fully implemented
|
||||
|
||||
impl !MyTrait for u32 {} //~ ERROR negative impls are experimental
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error[E0658]: negative trait bounds are not fully implemented; use marker types for now
|
||||
--> $DIR/feature-gate-negative_impls.rs:2:6
|
||||
error[E0658]: negative impls are experimental
|
||||
--> $DIR/feature-gate-negative_impls.rs:3:6
|
||||
|
|
||||
LL | impl !MyTrait for u32 {}
|
||||
| ^^^^^^^^
|
||||
@@ -7,6 +7,7 @@ LL | impl !MyTrait for u32 {}
|
||||
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
|
||||
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
= help: use marker types for now
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user