Skip to content

Commit f39205b

Browse files
committed
Auto merge of #66004 - eddyb:revert-early-gate, r=petrochenkov
Partially revert the early feature-gatings added in #65742. The intent here is to address #65860 ASAP (in time for beta, ideally), while leaving as much of #65742 around as possible, to make it easier to re-enable later. Therefore, I've only kept the parts of the revert that re-add the old (i.e. non-early) feature-gating checks that were removed in #65742, and the test reverts. I've disabled the new early feature-gating checks from #65742 entirely for now, but it would be easy to put them behind a `-Z` flag, or turn them into warnings, which would allow us to keep tests for both the early and late versions of the checks - assuming that's desirable. cc @nikomatsakis @Mark-Simulacrum @Centril
2 parents 87cbf0a + 27e01a1 commit f39205b

32 files changed

+160
-151
lines changed

src/libsyntax/feature_gate/check.rs

+110-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ use super::accepted::ACCEPTED_FEATURES;
33
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
44
use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
55

6-
use crate::ast::{self, NodeId, PatKind, VariantData};
6+
use crate::ast::{
7+
self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind,
8+
PatKind, RangeEnd, VariantData,
9+
};
710
use crate::attr::{self, check_builtin_attribute};
11+
use crate::source_map::Spanned;
812
use crate::edition::{ALL_EDITIONS, Edition};
913
use crate::visit::{self, FnKind, Visitor};
1014
use crate::parse::token;
@@ -153,6 +157,9 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
153157

154158
}
155159

160+
const EXPLAIN_BOX_SYNTAX: &str =
161+
"box expression syntax is experimental; you can call `Box::new` instead";
162+
156163
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
157164
"attributes on expressions are experimental";
158165

@@ -439,6 +446,20 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
439446
"auto traits are experimental and possibly buggy");
440447
}
441448

449+
ast::ItemKind::TraitAlias(..) => {
450+
gate_feature_post!(
451+
&self,
452+
trait_alias,
453+
i.span,
454+
"trait aliases are experimental"
455+
);
456+
}
457+
458+
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
459+
let msg = "`macro` is experimental";
460+
gate_feature_post!(&self, decl_macro, i.span, msg);
461+
}
462+
442463
ast::ItemKind::OpaqueTy(..) => {
443464
gate_feature_post!(
444465
&self,
@@ -502,6 +523,37 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
502523
}
503524
}
504525

526+
fn visit_expr(&mut self, e: &'a ast::Expr) {
527+
match e.kind {
528+
ast::ExprKind::Box(_) => {
529+
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
530+
}
531+
ast::ExprKind::Type(..) => {
532+
// To avoid noise about type ascription in common syntax errors, only emit if it
533+
// is the *only* error.
534+
if self.parse_sess.span_diagnostic.err_count() == 0 {
535+
gate_feature_post!(&self, type_ascription, e.span,
536+
"type ascription is experimental");
537+
}
538+
}
539+
ast::ExprKind::TryBlock(_) => {
540+
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
541+
}
542+
ast::ExprKind::Block(_, opt_label) => {
543+
if let Some(label) = opt_label {
544+
gate_feature_post!(&self, label_break_value, label.ident.span,
545+
"labels on blocks are unstable");
546+
}
547+
}
548+
_ => {}
549+
}
550+
visit::walk_expr(self, e)
551+
}
552+
553+
fn visit_arm(&mut self, arm: &'a ast::Arm) {
554+
visit::walk_arm(self, arm)
555+
}
556+
505557
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
506558
match &pattern.kind {
507559
PatKind::Slice(pats) => {
@@ -521,12 +573,25 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
521573
}
522574
}
523575
}
576+
PatKind::Box(..) => {
577+
gate_feature_post!(&self, box_patterns,
578+
pattern.span,
579+
"box pattern syntax is experimental");
580+
}
581+
PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
582+
gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
583+
"exclusive range pattern syntax is experimental");
584+
}
524585
_ => {}
525586
}
526587
visit::walk_pat(self, pattern)
527588
}
528589

529-
fn visit_fn(&mut self, fn_kind: FnKind<'a>, fn_decl: &'a ast::FnDecl, span: Span, _: NodeId) {
590+
fn visit_fn(&mut self,
591+
fn_kind: FnKind<'a>,
592+
fn_decl: &'a ast::FnDecl,
593+
span: Span,
594+
_node_id: NodeId) {
530595
if let Some(header) = fn_kind.header() {
531596
// Stability of const fn methods are covered in
532597
// `visit_trait_item` and `visit_impl_item` below; this is
@@ -541,6 +606,26 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
541606
visit::walk_fn(self, fn_kind, fn_decl, span)
542607
}
543608

609+
fn visit_generic_param(&mut self, param: &'a GenericParam) {
610+
match param.kind {
611+
GenericParamKind::Const { .. } =>
612+
gate_feature_post!(&self, const_generics, param.ident.span,
613+
"const generics are unstable"),
614+
_ => {}
615+
}
616+
visit::walk_generic_param(self, param)
617+
}
618+
619+
fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
620+
match constraint.kind {
621+
AssocTyConstraintKind::Bound { .. } =>
622+
gate_feature_post!(&self, associated_type_bounds, constraint.span,
623+
"associated type bounds are unstable"),
624+
_ => {}
625+
}
626+
visit::walk_assoc_ty_constraint(self, constraint)
627+
}
628+
544629
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
545630
match ti.kind {
546631
ast::TraitItemKind::Method(ref sig, ref block) => {
@@ -598,6 +683,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
598683
}
599684
visit::walk_impl_item(self, ii)
600685
}
686+
687+
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
688+
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node {
689+
gate_feature_post!(&self, crate_visibility_modifier, vis.span,
690+
"`crate` visibility modifier is experimental");
691+
}
692+
visit::walk_vis(self, vis)
693+
}
601694
}
602695

603696
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
@@ -783,6 +876,21 @@ pub fn check_crate(krate: &ast::Crate,
783876
gate_all!(yields, generators, "yield syntax is experimental");
784877
gate_all!(or_patterns, "or-patterns syntax is experimental");
785878
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
879+
880+
// All uses of `gate_all!` below this point were added in #65742,
881+
// and subsequently disabled (with the non-early gating readded).
882+
macro_rules! gate_all {
883+
($gate:ident, $msg:literal) => {
884+
// FIXME(eddyb) do something more useful than always
885+
// disabling these uses of early feature-gatings.
886+
if false {
887+
for span in &*parse_sess.gated_spans.$gate.borrow() {
888+
gate_feature!(&visitor, $gate, *span, $msg);
889+
}
890+
}
891+
}
892+
}
893+
786894
gate_all!(trait_alias, "trait aliases are experimental");
787895
gate_all!(associated_type_bounds, "associated type bounds are unstable");
788896
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");

src/test/ui/const-generics/const-param-in-trait-ungated.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: const generics are unstable
2-
--> $DIR/const-param-in-trait-ungated.rs:1:13
2+
--> $DIR/const-param-in-trait-ungated.rs:1:19
33
|
44
LL | trait Trait<const T: ()> {}
5-
| ^^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable

src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: const generics are unstable
2-
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:13
2+
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19
33
|
44
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
5-
| ^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable

src/test/ui/const-generics/issues/issue-60263.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: const generics are unstable
2-
--> $DIR/issue-60263.rs:1:10
2+
--> $DIR/issue-60263.rs:1:16
33
|
44
LL | struct B<const I: u8>;
5-
| ^^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable

src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs

-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,3 @@ fn main() {
7070
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
7171
// let _: &dyn Tr1<As1: Copy> = &S1;
7272
}
73-
74-
macro_rules! accept_path { ($p:path) => {} }
75-
accept_path!(Iterator<Item: Ord>);
76-
//~^ ERROR associated type bounds are unstable

src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ LL | let _: impl Tr1<As1: Copy> = S1;
115115
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
116116
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
117117

118-
error[E0658]: associated type bounds are unstable
119-
--> $DIR/feature-gate-associated_type_bounds.rs:75:23
120-
|
121-
LL | accept_path!(Iterator<Item: Ord>);
122-
| ^^^^^^^^^
123-
|
124-
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
125-
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
126-
127118
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
128119
--> $DIR/feature-gate-associated_type_bounds.rs:54:14
129120
|
@@ -148,7 +139,7 @@ LL | let _: impl Tr1<As1: Copy> = S1;
148139
|
149140
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
150141

151-
error: aborting due to 17 previous errors
142+
error: aborting due to 16 previous errors
152143

153144
Some errors have detailed explanations: E0562, E0658.
154145
For more information about an error, try `rustc --explain E0562`.

src/test/ui/feature-gates/feature-gate-box_patterns.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@ fn main() {
22
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental
33
println!("x: {}", x);
44
}
5-
6-
macro_rules! accept_pat { ($p:pat) => {} }
7-
accept_pat!(box 0); //~ ERROR box pattern syntax is experimental

src/test/ui/feature-gates/feature-gate-box_patterns.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ LL | let box x = Box::new('c');
77
= note: for more information, see https://github.com/rust-lang/rust/issues/29641
88
= help: add `#![feature(box_patterns)]` to the crate attributes to enable
99

10-
error[E0658]: box pattern syntax is experimental
11-
--> $DIR/feature-gate-box_patterns.rs:7:13
12-
|
13-
LL | accept_pat!(box 0);
14-
| ^^^^^
15-
|
16-
= note: for more information, see https://github.com/rust-lang/rust/issues/29641
17-
= help: add `#![feature(box_patterns)]` to the crate attributes to enable
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

2112
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Test that the use of the box syntax is gated by `box_syntax` feature gate.
22

3-
#[cfg(FALSE)]
4-
fn foo() {
3+
fn main() {
54
let x = box 3;
65
//~^ ERROR box expression syntax is experimental; you can call `Box::new` instead
76
}
8-
9-
fn main() {}

src/test/ui/feature-gates/feature-gate-box_syntax.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: box expression syntax is experimental; you can call `Box::new` instead
2-
--> $DIR/feature-gate-box_syntax.rs:5:13
2+
--> $DIR/feature-gate-box_syntax.rs:4:13
33
|
44
LL | let x = box 3;
55
| ^^^^^

src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0658]: const generics are unstable
2-
--> $DIR/feature-gate-const_generics-ptr.rs:1:16
2+
--> $DIR/feature-gate-const_generics-ptr.rs:1:22
33
|
44
LL | struct ConstFn<const F: fn()>;
5-
| ^^^^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable
99

1010
error[E0658]: const generics are unstable
11-
--> $DIR/feature-gate-const_generics-ptr.rs:5:17
11+
--> $DIR/feature-gate-const_generics-ptr.rs:5:23
1212
|
1313
LL | struct ConstPtr<const P: *const u32>;
14-
| ^^^^^^^^^^^^^^^^^^^
14+
| ^
1515
|
1616
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
1717
= help: add `#![feature(const_generics)]` to the crate attributes to enable

src/test/ui/feature-gates/feature-gate-const_generics.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ fn foo<const X: ()>() {} //~ ERROR const generics are unstable
22

33
struct Foo<const X: usize>([(); X]); //~ ERROR const generics are unstable
44

5-
macro_rules! accept_item { ($i:item) => {} }
6-
accept_item! {
7-
impl<const X: ()> A {} //~ ERROR const generics are unstable
8-
}
9-
105
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
error[E0658]: const generics are unstable
2-
--> $DIR/feature-gate-const_generics.rs:1:8
2+
--> $DIR/feature-gate-const_generics.rs:1:14
33
|
44
LL | fn foo<const X: ()>() {}
5-
| ^^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable
99

1010
error[E0658]: const generics are unstable
11-
--> $DIR/feature-gate-const_generics.rs:3:12
11+
--> $DIR/feature-gate-const_generics.rs:3:18
1212
|
1313
LL | struct Foo<const X: usize>([(); X]);
14-
| ^^^^^^^^^^^^^^
14+
| ^
1515
|
1616
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
1717
= help: add `#![feature(const_generics)]` to the crate attributes to enable
1818

19-
error[E0658]: const generics are unstable
20-
--> $DIR/feature-gate-const_generics.rs:7:10
21-
|
22-
LL | impl<const X: ()> A {}
23-
| ^^^^^^^^^^^
24-
|
25-
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
26-
= help: add `#![feature(const_generics)]` to the crate attributes to enable
27-
28-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
2920

3021
For more information about this error, try `rustc --explain E0658`.

src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ crate struct Bender { //~ ERROR `crate` visibility modifier is experimental
55
water: bool,
66
}
77

8-
macro_rules! accept_vis { ($v:vis) => {} }
9-
accept_vis!(crate); //~ ERROR `crate` visibility modifier is experimental
10-
118
fn main() {}

src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ LL | crate struct Bender {
77
= note: for more information, see https://github.com/rust-lang/rust/issues/53120
88
= help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable
99

10-
error[E0658]: `crate` visibility modifier is experimental
11-
--> $DIR/feature-gate-crate_visibility_modifier.rs:9:13
12-
|
13-
LL | accept_vis!(crate);
14-
| ^^^^^
15-
|
16-
= note: for more information, see https://github.com/rust-lang/rust/issues/53120
17-
= help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

2112
For more information about this error, try `rustc --explain E0658`.

src/test/ui/feature-gates/feature-gate-decl_macro.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22

33
macro m() {} //~ ERROR `macro` is experimental
44

5-
macro_rules! accept_item { ($i:item) => {} }
6-
accept_item! {
7-
macro m() {} //~ ERROR `macro` is experimental
8-
}
95
fn main() {}

0 commit comments

Comments
 (0)