Skip to content

Commit a18dd67

Browse files
Rollup merge of rust-lang#154527 - fmease:more-soft-gates, r=nnethercote
Emit pre-expansion feature gate warnings for negative impls and specialization Follow up to rust-lang#154475; part of rust-lang#154045. This shouldn't need any extra input from T-compiler or T-lang since it's legitimized by [MCP 535](rust-lang/compiler-team#535). However, I have a feeling that negative impls & specialization behind "`#[cfg(feature = "nightly")]`" are more prevalent in the ecosystem compared to e.g., auto traits & box patterns, so these new warnings will probably hit a bunch of users. In any case, it's only a warning for now not an error so e.g., running crater "in deny mode" or nominating for a T-lang meeting discussion would be disproportionate (esp. since T-lang [has confirmed in the past](rust-lang#116393 (comment)) that this is a T-compiler matter).
2 parents d0a10f9 + 3e658d3 commit a18dd67

27 files changed

+467
-292
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 174 additions & 187 deletions
Large diffs are not rendered by default.

compiler/rustc_parse/src/parser/item.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,18 @@ impl<'a> Parser<'a> {
248248
self.parse_use_item()?
249249
} else if self.check_fn_front_matter(check_pub, case) {
250250
// FUNCTION ITEM
251+
let defaultness = def_();
252+
if let Defaultness::Default(span) = defaultness {
253+
// Default functions should only require feature `min_specialization`. We remove the
254+
// `specialization` tag again as such spans *require* feature `specialization` to be
255+
// enabled. In a later stage, we make `specialization` imply `min_specialization`.
256+
self.psess.gated_spans.gate(sym::min_specialization, span);
257+
self.psess.gated_spans.ungate_last(sym::specialization, span);
258+
}
251259
let (ident, sig, generics, contract, body) =
252260
self.parse_fn(attrs, fn_parse_mode, lo, vis, case)?;
253261
ItemKind::Fn(Box::new(Fn {
254-
defaultness: def_(),
262+
defaultness,
255263
ident,
256264
sig,
257265
generics,
@@ -603,6 +611,7 @@ impl<'a> Parser<'a> {
603611
fn parse_polarity(&mut self) -> ast::ImplPolarity {
604612
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
605613
if self.check(exp!(Bang)) && self.look_ahead(1, |t| t.can_begin_type()) {
614+
self.psess.gated_spans.gate(sym::negative_impls, self.token.span);
606615
self.bump(); // `!`
607616
ast::ImplPolarity::Negative(self.prev_token.span)
608617
} else {
@@ -1015,6 +1024,7 @@ impl<'a> Parser<'a> {
10151024
if self.check_keyword(exp!(Default))
10161025
&& self.look_ahead(1, |t| t.is_non_raw_ident_where(|i| i.name != kw::As))
10171026
{
1027+
self.psess.gated_spans.gate(sym::specialization, self.token.span);
10181028
self.bump(); // `default`
10191029
Defaultness::Default(self.prev_token_uninterpolated_span())
10201030
} else if self.eat_keyword(exp!(Final)) {

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

tests/ui/feature-gates/soft-feature-gate-auto_traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// For historical reasons, auto traits 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.
1+
// For historical reasons, auto traits don't have an erroring 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 this pre-expansion warning into an error and remove the post-expansion gate.
44
// As part of this, move these test cases into `feature-gate-auto-traits.rs`.
55
//@ check-pass
66

tests/ui/feature-gates/soft-feature-gate-box_patterns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// For historical reasons, box patterns 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.
1+
// For historical reasons, box patterns don't have an erroring 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 this pre-expansion warning into an error and remove the post-expansion gate.
44
// As part of this, move these test cases into `feature-gate-box_patterns.rs`.
55
//@ check-pass
66

tests/ui/feature-gates/soft-feature-gate-decl_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// For historical reasons, decl macros 2.0 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.
1+
// For historical reasons, decl macros 2.0 don't have an erroring 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 this pre-expansion warning into an error and remove the post-expansion gate.
44
// As part of this, move these test cases into `feature-gate-decl_macro.rs`.
55
//@ check-pass
66

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 an erroring 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 this pre-expansion warning into an error and remove the post-expansion gate.
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() {}

0 commit comments

Comments
 (0)