Skip to content

Commit 394012b

Browse files
committed
Emit pre-expansion feature gate warning for negative impls
1 parent dd96eff commit 394012b

10 files changed

Lines changed: 46 additions & 52 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
218218
self,
219219
negative_impls,
220220
span.to(of_trait.trait_ref.path.span),
221-
"negative trait bounds are not fully implemented; \
222-
use marker types for now"
221+
"negative impls are experimental",
222+
"use marker types for now"
223223
);
224224
}
225225

@@ -614,6 +614,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
614614
soft_gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
615615
soft_gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
616616
soft_gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
617+
soft_gate_all_legacy_dont_use!(negative_impls, "negative impls are experimental");
617618
soft_gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
618619
soft_gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
619620
// tidy-alphabetical-end

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ impl<'a> Parser<'a> {
603603
fn parse_polarity(&mut self) -> ast::ImplPolarity {
604604
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
605605
if self.check(exp!(Bang)) && self.look_ahead(1, |t| t.can_begin_type()) {
606+
self.psess.gated_spans.gate(sym::negative_impls, self.token.span);
606607
self.bump(); // `!`
607608
ast::ImplPolarity::Negative(self.prev_token.span)
608609
} else {

tests/ui/auto-traits/ungated-impl.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/ui/auto-traits/ungated-impl.stderr

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
// Test that default and negative trait implementations are gated by
2-
// `auto_traits` feature gate
1+
auto trait DummyAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy
32

4-
struct DummyStruct;
5-
6-
auto trait AutoDummyTrait {}
7-
//~^ ERROR auto traits are experimental and possibly buggy
8-
9-
impl !AutoDummyTrait for DummyStruct {}
10-
//~^ ERROR negative trait bounds are not fully implemented; use marker types for now
3+
pub unsafe auto trait AnotherAutoTrait {} //~ ERROR auto traits are experimental and possibly buggy
114

125
fn main() {}

tests/ui/feature-gates/feature-gate-auto-traits.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0658]: auto traits are experimental and possibly buggy
2-
--> $DIR/feature-gate-auto-traits.rs:6:1
2+
--> $DIR/feature-gate-auto-traits.rs:1:1
33
|
4-
LL | auto trait AutoDummyTrait {}
4+
LL | auto trait DummyAutoTrait {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
88
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error[E0658]: negative trait bounds are not fully implemented; use marker types for now
12-
--> $DIR/feature-gate-auto-traits.rs:9:6
11+
error[E0658]: auto traits are experimental and possibly buggy
12+
--> $DIR/feature-gate-auto-traits.rs:3:1
1313
|
14-
LL | impl !AutoDummyTrait for DummyStruct {}
15-
| ^^^^^^^^^^^^^^^
14+
LL | pub unsafe auto trait AnotherAutoTrait {}
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
17-
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
18-
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
17+
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
18+
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error: aborting due to 2 previous errors
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// For historical reasons, negative impls don't have a proper pre-expansion feature gate.
2+
// We're now at least issuing a *warning* for those that only exist before macro expansion.
3+
// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one.
4+
// As part of this, move these test cases into `feature-gate-negative_impls.rs`.
5+
//@ check-pass
6+
7+
#[cfg(false)]
8+
impl !Trait for () {}
9+
//~^ WARN negative impls are experimental
10+
//~| WARN unstable syntax can change at any point in the future
11+
12+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: negative impls are experimental
2+
--> $DIR/soft-feature-gate-negative_impls.rs:8:6
3+
|
4+
LL | impl !Trait for () {}
5+
| ^
6+
|
7+
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
8+
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= warning: unstable syntax can change at any point in the future, causing a hard error!
11+
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
12+
13+
warning: 1 warning emitted
14+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
trait MyTrait {}
2-
impl !MyTrait for u32 {} //~ ERROR negative trait bounds are not fully implemented
2+
3+
impl !MyTrait for u32 {} //~ ERROR negative impls are experimental
4+
35
fn main() {}

tests/ui/traits/negative-impls/feature-gate-negative_impls.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
error[E0658]: negative trait bounds are not fully implemented; use marker types for now
2-
--> $DIR/feature-gate-negative_impls.rs:2:6
1+
error[E0658]: negative impls are experimental
2+
--> $DIR/feature-gate-negative_impls.rs:3:6
33
|
44
LL | impl !MyTrait for u32 {}
55
| ^^^^^^^^
66
|
77
= note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
88
= help: add `#![feature(negative_impls)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= help: use marker types for now
1011

1112
error: aborting due to 1 previous error
1213

0 commit comments

Comments
 (0)