From 4c947a26f2a804fefb1d74110057efd8564033f1 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:12:25 +0200 Subject: [PATCH 01/12] Revert "pre-expansion gate type_ascription" This reverts commit 15a6c09b6e8a977f2c6f5a73de01a20d00b37930. --- src/libsyntax/feature_gate/check.rs | 15 +++++++++++++++ .../feature-gates/feature-gate-type_ascription.rs | 5 +---- .../feature-gate-type_ascription.stderr | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 97b99b9392f3f..0f07bf10d656b 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -502,6 +502,21 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } + fn visit_expr(&mut self, e: &'a ast::Expr) { + match e.kind { + ast::ExprKind::Type(..) => { + // To avoid noise about type ascription in common syntax errors, only emit if it + // is the *only* error. + if self.parse_sess.span_diagnostic.err_count() == 0 { + gate_feature_post!(&self, type_ascription, e.span, + "type ascription is experimental"); + } + } + _ => {} + } + visit::walk_expr(self, e) + } + fn visit_pat(&mut self, pattern: &'a ast::Pat) { match &pattern.kind { PatKind::Slice(pats) => { diff --git a/src/test/ui/feature-gates/feature-gate-type_ascription.rs b/src/test/ui/feature-gates/feature-gate-type_ascription.rs index 655891d802c1c..7a597157300ed 100644 --- a/src/test/ui/feature-gates/feature-gate-type_ascription.rs +++ b/src/test/ui/feature-gates/feature-gate-type_ascription.rs @@ -1,8 +1,5 @@ // Type ascription is unstable -#[cfg(FALSE)] -fn foo() { +fn main() { let a = 10: u8; //~ ERROR type ascription is experimental } - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-type_ascription.stderr b/src/test/ui/feature-gates/feature-gate-type_ascription.stderr index d63d624c6c112..83f95529f0d9d 100644 --- a/src/test/ui/feature-gates/feature-gate-type_ascription.stderr +++ b/src/test/ui/feature-gates/feature-gate-type_ascription.stderr @@ -1,5 +1,5 @@ error[E0658]: type ascription is experimental - --> $DIR/feature-gate-type_ascription.rs:5:13 + --> $DIR/feature-gate-type_ascription.rs:4:13 | LL | let a = 10: u8; | ^^^^^^ From 20bfff66a95811c31990a774ee522f096d955b44 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:20:02 +0200 Subject: [PATCH 02/12] Revert "pre-expansion gate box_syntax" This reverts commit e4ed8865786a787a7b0c045f7674569b6be0e9bc. --- src/libsyntax/feature_gate/check.rs | 6 ++++++ src/test/ui/feature-gates/feature-gate-box_syntax.rs | 5 +---- src/test/ui/feature-gates/feature-gate-box_syntax.stderr | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 0f07bf10d656b..d924cb608f879 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -153,6 +153,9 @@ fn leveled_feature_err<'a, S: Into>( } +const EXPLAIN_BOX_SYNTAX: &str = + "box expression syntax is experimental; you can call `Box::new` instead"; + pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = "attributes on expressions are experimental"; @@ -504,6 +507,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_expr(&mut self, e: &'a ast::Expr) { match e.kind { + ast::ExprKind::Box(_) => { + gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX); + } ast::ExprKind::Type(..) => { // To avoid noise about type ascription in common syntax errors, only emit if it // is the *only* error. diff --git a/src/test/ui/feature-gates/feature-gate-box_syntax.rs b/src/test/ui/feature-gates/feature-gate-box_syntax.rs index c23953a9e099e..778660cc0b549 100644 --- a/src/test/ui/feature-gates/feature-gate-box_syntax.rs +++ b/src/test/ui/feature-gates/feature-gate-box_syntax.rs @@ -1,9 +1,6 @@ // Test that the use of the box syntax is gated by `box_syntax` feature gate. -#[cfg(FALSE)] -fn foo() { +fn main() { let x = box 3; //~^ ERROR box expression syntax is experimental; you can call `Box::new` instead } - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-box_syntax.stderr b/src/test/ui/feature-gates/feature-gate-box_syntax.stderr index cbafa50257706..61b0534d2dc3e 100644 --- a/src/test/ui/feature-gates/feature-gate-box_syntax.stderr +++ b/src/test/ui/feature-gates/feature-gate-box_syntax.stderr @@ -1,5 +1,5 @@ error[E0658]: box expression syntax is experimental; you can call `Box::new` instead - --> $DIR/feature-gate-box_syntax.rs:5:13 + --> $DIR/feature-gate-box_syntax.rs:4:13 | LL | let x = box 3; | ^^^^^ From 73bde2f0ce38c57255840dd879ec10475ef44f2c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:25:40 +0200 Subject: [PATCH 03/12] Revert "pre-expansion gate label_break_value" This reverts commit 137ded8ab1edf5112c45e0b6854272ae2e9d3a6d. --- src/libsyntax/feature_gate/check.rs | 6 ++++++ src/test/ui/feature-gates/feature-gate-label_break_value.rs | 5 +---- .../ui/feature-gates/feature-gate-label_break_value.stderr | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index d924cb608f879..1846ba5ed7be2 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -518,6 +518,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "type ascription is experimental"); } } + ast::ExprKind::Block(_, opt_label) => { + if let Some(label) = opt_label { + gate_feature_post!(&self, label_break_value, label.ident.span, + "labels on blocks are unstable"); + } + } _ => {} } visit::walk_expr(self, e) diff --git a/src/test/ui/feature-gates/feature-gate-label_break_value.rs b/src/test/ui/feature-gates/feature-gate-label_break_value.rs index 8d7ecd27b450f..6fc38f45517ef 100644 --- a/src/test/ui/feature-gates/feature-gate-label_break_value.rs +++ b/src/test/ui/feature-gates/feature-gate-label_break_value.rs @@ -1,8 +1,5 @@ -#[cfg(FALSE)] -pub fn foo() { +pub fn main() { 'a: { //~ ERROR labels on blocks are unstable break 'a; } } - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-label_break_value.stderr b/src/test/ui/feature-gates/feature-gate-label_break_value.stderr index 6a861d3e04f92..a417e0eec22f2 100644 --- a/src/test/ui/feature-gates/feature-gate-label_break_value.stderr +++ b/src/test/ui/feature-gates/feature-gate-label_break_value.stderr @@ -1,5 +1,5 @@ error[E0658]: labels on blocks are unstable - --> $DIR/feature-gate-label_break_value.rs:3:5 + --> $DIR/feature-gate-label_break_value.rs:2:5 | LL | 'a: { | ^^ From 8645ac4218e2c503c616ebcfccf034c07a94f405 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:28:36 +0200 Subject: [PATCH 04/12] Revert "pre-expansion gate try_blocks" This reverts commit 1935ba658c576f14397c2c7a26a6642cf08f26a6. --- src/libsyntax/feature_gate/check.rs | 3 +++ src/test/ui/feature-gates/feature-gate-try_blocks.rs | 7 ++----- src/test/ui/feature-gates/feature-gate-try_blocks.stderr | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 1846ba5ed7be2..52fb476152773 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -518,6 +518,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "type ascription is experimental"); } } + ast::ExprKind::TryBlock(_) => { + gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental"); + } ast::ExprKind::Block(_, opt_label) => { if let Some(label) = opt_label { gate_feature_post!(&self, label_break_value, label.ident.span, diff --git a/src/test/ui/feature-gates/feature-gate-try_blocks.rs b/src/test/ui/feature-gates/feature-gate-try_blocks.rs index b451ba84a1565..06cadd82c0731 100644 --- a/src/test/ui/feature-gates/feature-gate-try_blocks.rs +++ b/src/test/ui/feature-gates/feature-gate-try_blocks.rs @@ -1,12 +1,9 @@ // compile-flags: --edition 2018 -#[cfg(FALSE)] -fn foo() { - let try_result: Option<_> = try { //~ ERROR `try` blocks are unstable +pub fn main() { + let try_result: Option<_> = try { //~ ERROR `try` expression is experimental let x = 5; x }; assert_eq!(try_result, Some(5)); } - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-try_blocks.stderr b/src/test/ui/feature-gates/feature-gate-try_blocks.stderr index 44a7d9b9043fd..565f3610a2e21 100644 --- a/src/test/ui/feature-gates/feature-gate-try_blocks.stderr +++ b/src/test/ui/feature-gates/feature-gate-try_blocks.stderr @@ -1,5 +1,5 @@ -error[E0658]: `try` blocks are unstable - --> $DIR/feature-gate-try_blocks.rs:5:33 +error[E0658]: `try` expression is experimental + --> $DIR/feature-gate-try_blocks.rs:4:33 | LL | let try_result: Option<_> = try { | _________________________________^ From 4c48355c69148c49d1becc26dcc6439650a35589 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:30:25 +0200 Subject: [PATCH 05/12] Revert "pre-expansion gate exclusive_range_pattern" This reverts commit 665a876e307933c6480a6c55a3e38e88937aff2c. --- src/libsyntax/feature_gate/check.rs | 7 ++++++- .../feature-gate-exclusive-range-pattern.rs | 6 +----- .../feature-gate-exclusive-range-pattern.stderr | 15 +++------------ src/test/ui/parser/pat-tuple-4.rs | 1 + src/test/ui/parser/pat-tuple-4.stderr | 16 +++++++++++++--- src/test/ui/parser/pat-tuple-5.stderr | 4 ++-- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 52fb476152773..7c5b75387d2de 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -3,8 +3,9 @@ use super::accepted::ACCEPTED_FEATURES; use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; -use crate::ast::{self, NodeId, PatKind, VariantData}; +use crate::ast::{self, NodeId, PatKind, RangeEnd, VariantData}; use crate::attr::{self, check_builtin_attribute}; +use crate::source_map::Spanned; use crate::edition::{ALL_EDITIONS, Edition}; use crate::visit::{self, FnKind, Visitor}; use crate::parse::token; @@ -551,6 +552,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } } + PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => { + gate_feature_post!(&self, exclusive_range_pattern, pattern.span, + "exclusive range pattern syntax is experimental"); + } _ => {} } visit::walk_pat(self, pattern) diff --git a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs index 594ec73fe26f7..ded08b93fe81c 100644 --- a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs +++ b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs @@ -1,10 +1,6 @@ -#[cfg(FALSE)] -fn foo() { +pub fn main() { match 22 { 0 .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental - PATH .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental _ => {} } } - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr index 075fdbed90d6c..ee20408d1781f 100644 --- a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr +++ b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr @@ -1,21 +1,12 @@ error[E0658]: exclusive range pattern syntax is experimental - --> $DIR/feature-gate-exclusive-range-pattern.rs:4:11 + --> $DIR/feature-gate-exclusive-range-pattern.rs:3:9 | LL | 0 .. 3 => {} - | ^^ + | ^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/37854 = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable -error[E0658]: exclusive range pattern syntax is experimental - --> $DIR/feature-gate-exclusive-range-pattern.rs:5:14 - | -LL | PATH .. 3 => {} - | ^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/37854 - = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/parser/pat-tuple-4.rs b/src/test/ui/parser/pat-tuple-4.rs index 6b8c146949aec..2f03160430a22 100644 --- a/src/test/ui/parser/pat-tuple-4.rs +++ b/src/test/ui/parser/pat-tuple-4.rs @@ -4,6 +4,7 @@ fn main() { match 0 { (.. PAT) => {} //~^ ERROR `..X` range patterns are not supported + //~| ERROR exclusive range pattern syntax is experimental } } diff --git a/src/test/ui/parser/pat-tuple-4.stderr b/src/test/ui/parser/pat-tuple-4.stderr index 1962dc4ff20a8..af3ecce184649 100644 --- a/src/test/ui/parser/pat-tuple-4.stderr +++ b/src/test/ui/parser/pat-tuple-4.stderr @@ -4,8 +4,17 @@ error: `..X` range patterns are not supported LL | (.. PAT) => {} | ^^^^^^ help: try using the minimum value for the type: `MIN..PAT` +error[E0658]: exclusive range pattern syntax is experimental + --> $DIR/pat-tuple-4.rs:5:10 + | +LL | (.. PAT) => {} + | ^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/37854 + = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable + error[E0308]: mismatched types - --> $DIR/pat-tuple-4.rs:10:30 + --> $DIR/pat-tuple-4.rs:11:30 | LL | const RECOVERY_WITNESS: () = 0; | ^ expected (), found integer @@ -13,6 +22,7 @@ LL | const RECOVERY_WITNESS: () = 0; = note: expected type `()` found type `{integer}` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0308, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/parser/pat-tuple-5.stderr b/src/test/ui/parser/pat-tuple-5.stderr index 17155b4dd4954..09ebdc29a2161 100644 --- a/src/test/ui/parser/pat-tuple-5.stderr +++ b/src/test/ui/parser/pat-tuple-5.stderr @@ -5,10 +5,10 @@ LL | (PAT ..) => {} | ^^^^^^ help: try using the maximum value for the type: `PAT..MAX` error[E0658]: exclusive range pattern syntax is experimental - --> $DIR/pat-tuple-5.rs:5:14 + --> $DIR/pat-tuple-5.rs:5:10 | LL | (PAT ..) => {} - | ^^ + | ^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/37854 = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable From 680089c2d906ac33e4ae16a184fce12b610af434 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:32:40 +0200 Subject: [PATCH 06/12] Revert "pre-expansion gate box_patterns" This reverts commit 2aff6b36d7ed5c25700669a92b4a43200ee0fe6b. --- src/libsyntax/feature_gate/check.rs | 15 ++++++++++++++- .../ui/feature-gates/feature-gate-box_patterns.rs | 3 --- .../feature-gate-box_patterns.stderr | 11 +---------- .../ui/or-patterns/or-patterns-syntactic-pass.rs | 1 - src/test/ui/pattern/rest-pat-syntactic.rs | 2 -- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 7c5b75387d2de..33dfe386a4d06 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -533,6 +533,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_expr(self, e) } + fn visit_arm(&mut self, arm: &'a ast::Arm) { + visit::walk_arm(self, arm) + } + fn visit_pat(&mut self, pattern: &'a ast::Pat) { match &pattern.kind { PatKind::Slice(pats) => { @@ -552,6 +556,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } } + PatKind::Box(..) => { + gate_feature_post!(&self, box_patterns, + pattern.span, + "box pattern syntax is experimental"); + } PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => { gate_feature_post!(&self, exclusive_range_pattern, pattern.span, "exclusive range pattern syntax is experimental"); @@ -561,7 +570,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_pat(self, pattern) } - fn visit_fn(&mut self, fn_kind: FnKind<'a>, fn_decl: &'a ast::FnDecl, span: Span, _: NodeId) { + fn visit_fn(&mut self, + fn_kind: FnKind<'a>, + fn_decl: &'a ast::FnDecl, + span: Span, + _node_id: NodeId) { if let Some(header) = fn_kind.header() { // Stability of const fn methods are covered in // `visit_trait_item` and `visit_impl_item` below; this is diff --git a/src/test/ui/feature-gates/feature-gate-box_patterns.rs b/src/test/ui/feature-gates/feature-gate-box_patterns.rs index c5b926d5af28c..8bec16a974e80 100644 --- a/src/test/ui/feature-gates/feature-gate-box_patterns.rs +++ b/src/test/ui/feature-gates/feature-gate-box_patterns.rs @@ -2,6 +2,3 @@ fn main() { let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental println!("x: {}", x); } - -macro_rules! accept_pat { ($p:pat) => {} } -accept_pat!(box 0); //~ ERROR box pattern syntax is experimental diff --git a/src/test/ui/feature-gates/feature-gate-box_patterns.stderr b/src/test/ui/feature-gates/feature-gate-box_patterns.stderr index 1e47bd41e8870..d2dafe93a862f 100644 --- a/src/test/ui/feature-gates/feature-gate-box_patterns.stderr +++ b/src/test/ui/feature-gates/feature-gate-box_patterns.stderr @@ -7,15 +7,6 @@ LL | let box x = Box::new('c'); = note: for more information, see https://github.com/rust-lang/rust/issues/29641 = help: add `#![feature(box_patterns)]` to the crate attributes to enable -error[E0658]: box pattern syntax is experimental - --> $DIR/feature-gate-box_patterns.rs:7:13 - | -LL | accept_pat!(box 0); - | ^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/29641 - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/or-patterns/or-patterns-syntactic-pass.rs b/src/test/ui/or-patterns/or-patterns-syntactic-pass.rs index 9667711242ce6..5fe72caf9c1ff 100644 --- a/src/test/ui/or-patterns/or-patterns-syntactic-pass.rs +++ b/src/test/ui/or-patterns/or-patterns-syntactic-pass.rs @@ -4,7 +4,6 @@ // check-pass #![feature(or_patterns)] -#![feature(box_patterns)] fn main() {} diff --git a/src/test/ui/pattern/rest-pat-syntactic.rs b/src/test/ui/pattern/rest-pat-syntactic.rs index 45b31f6125374..9656a0b5de9ce 100644 --- a/src/test/ui/pattern/rest-pat-syntactic.rs +++ b/src/test/ui/pattern/rest-pat-syntactic.rs @@ -3,8 +3,6 @@ // check-pass -#![feature(box_patterns)] - fn main() {} macro_rules! accept_pat { From ada4a6430d7bcfb542b0c0fa6a43c9dd3291f2ff Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:35:41 +0200 Subject: [PATCH 07/12] Revert "pre-expansion gate decl_macro" This reverts commit 1f470ceac2202ecffe8a15acc1139edb9ad4a03b. --- src/libsyntax/feature_gate/check.rs | 5 +++++ src/test/ui/feature-gates/feature-gate-decl_macro.rs | 4 ---- .../ui/feature-gates/feature-gate-decl_macro.stderr | 11 +---------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 33dfe386a4d06..bcafb9e03ff0b 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -443,6 +443,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "auto traits are experimental and possibly buggy"); } + ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => { + let msg = "`macro` is experimental"; + gate_feature_post!(&self, decl_macro, i.span, msg); + } + ast::ItemKind::OpaqueTy(..) => { gate_feature_post!( &self, diff --git a/src/test/ui/feature-gates/feature-gate-decl_macro.rs b/src/test/ui/feature-gates/feature-gate-decl_macro.rs index b208a047481a4..d002c5dbbd2db 100644 --- a/src/test/ui/feature-gates/feature-gate-decl_macro.rs +++ b/src/test/ui/feature-gates/feature-gate-decl_macro.rs @@ -2,8 +2,4 @@ macro m() {} //~ ERROR `macro` is experimental -macro_rules! accept_item { ($i:item) => {} } -accept_item! { - macro m() {} //~ ERROR `macro` is experimental -} fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-decl_macro.stderr b/src/test/ui/feature-gates/feature-gate-decl_macro.stderr index c6690ebd4d917..905a1b1531044 100644 --- a/src/test/ui/feature-gates/feature-gate-decl_macro.stderr +++ b/src/test/ui/feature-gates/feature-gate-decl_macro.stderr @@ -7,15 +7,6 @@ LL | macro m() {} = note: for more information, see https://github.com/rust-lang/rust/issues/39412 = help: add `#![feature(decl_macro)]` to the crate attributes to enable -error[E0658]: `macro` is experimental - --> $DIR/feature-gate-decl_macro.rs:7:5 - | -LL | macro m() {} - | ^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/39412 - = help: add `#![feature(decl_macro)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. From 8f1eb345eacae619cf3fdeb17ef7bc6ec581fa2e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:46:29 +0200 Subject: [PATCH 08/12] Revert "pre-expansion gate const_generics" This reverts commit 49cbfa1a6f6469ddbc0e88161e52104cc87aea9b. --- src/libsyntax/feature_gate/check.rs | 12 +++++++++++- .../const-param-in-trait-ungated.stderr | 4 ++-- ...-type-depends-on-type-param-ungated.stderr | 4 ++-- .../const-generics/issues/issue-60263.stderr | 4 ++-- .../feature-gate-const_generics-ptr.stderr | 8 ++++---- .../feature-gate-const_generics.rs | 5 ----- .../feature-gate-const_generics.stderr | 19 +++++-------------- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index bcafb9e03ff0b..3a32f12b255c0 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -3,7 +3,7 @@ use super::accepted::ACCEPTED_FEATURES; use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; -use crate::ast::{self, NodeId, PatKind, RangeEnd, VariantData}; +use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; use crate::attr::{self, check_builtin_attribute}; use crate::source_map::Spanned; use crate::edition::{ALL_EDITIONS, Edition}; @@ -594,6 +594,16 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_fn(self, fn_kind, fn_decl, span) } + fn visit_generic_param(&mut self, param: &'a GenericParam) { + match param.kind { + GenericParamKind::Const { .. } => + gate_feature_post!(&self, const_generics, param.ident.span, + "const generics are unstable"), + _ => {} + } + visit::walk_generic_param(self, param) + } + fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) { match ti.kind { ast::TraitItemKind::Method(ref sig, ref block) => { diff --git a/src/test/ui/const-generics/const-param-in-trait-ungated.stderr b/src/test/ui/const-generics/const-param-in-trait-ungated.stderr index 330c93e83b5e7..cfb1f8b581c85 100644 --- a/src/test/ui/const-generics/const-param-in-trait-ungated.stderr +++ b/src/test/ui/const-generics/const-param-in-trait-ungated.stderr @@ -1,8 +1,8 @@ error[E0658]: const generics are unstable - --> $DIR/const-param-in-trait-ungated.rs:1:13 + --> $DIR/const-param-in-trait-ungated.rs:1:19 | LL | trait Trait {} - | ^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr index e34a2da24cecc..a2872ab982da4 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr @@ -1,8 +1,8 @@ error[E0658]: const generics are unstable - --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:13 + --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19 | LL | struct B(PhantomData<[T; N]>); - | ^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable diff --git a/src/test/ui/const-generics/issues/issue-60263.stderr b/src/test/ui/const-generics/issues/issue-60263.stderr index 5223c8c5137ae..fe7b6fdb1904d 100644 --- a/src/test/ui/const-generics/issues/issue-60263.stderr +++ b/src/test/ui/const-generics/issues/issue-60263.stderr @@ -1,8 +1,8 @@ error[E0658]: const generics are unstable - --> $DIR/issue-60263.rs:1:10 + --> $DIR/issue-60263.rs:1:16 | LL | struct B; - | ^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable diff --git a/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr b/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr index 790bc33e2683e..935f84b9163d3 100644 --- a/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_generics-ptr.stderr @@ -1,17 +1,17 @@ error[E0658]: const generics are unstable - --> $DIR/feature-gate-const_generics-ptr.rs:1:16 + --> $DIR/feature-gate-const_generics-ptr.rs:1:22 | LL | struct ConstFn; - | ^^^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable error[E0658]: const generics are unstable - --> $DIR/feature-gate-const_generics-ptr.rs:5:17 + --> $DIR/feature-gate-const_generics-ptr.rs:5:23 | LL | struct ConstPtr; - | ^^^^^^^^^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.rs b/src/test/ui/feature-gates/feature-gate-const_generics.rs index 0adc9902a6937..fe1ded1c4bbc4 100644 --- a/src/test/ui/feature-gates/feature-gate-const_generics.rs +++ b/src/test/ui/feature-gates/feature-gate-const_generics.rs @@ -2,9 +2,4 @@ fn foo() {} //~ ERROR const generics are unstable struct Foo([(); X]); //~ ERROR const generics are unstable -macro_rules! accept_item { ($i:item) => {} } -accept_item! { - impl A {} //~ ERROR const generics are unstable -} - fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.stderr b/src/test/ui/feature-gates/feature-gate-const_generics.stderr index f0154ed289f14..468e9c31d37e2 100644 --- a/src/test/ui/feature-gates/feature-gate-const_generics.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_generics.stderr @@ -1,30 +1,21 @@ error[E0658]: const generics are unstable - --> $DIR/feature-gate-const_generics.rs:1:8 + --> $DIR/feature-gate-const_generics.rs:1:14 | LL | fn foo() {} - | ^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable error[E0658]: const generics are unstable - --> $DIR/feature-gate-const_generics.rs:3:12 + --> $DIR/feature-gate-const_generics.rs:3:18 | LL | struct Foo([(); X]); - | ^^^^^^^^^^^^^^ + | ^ | = note: for more information, see https://github.com/rust-lang/rust/issues/44580 = help: add `#![feature(const_generics)]` to the crate attributes to enable -error[E0658]: const generics are unstable - --> $DIR/feature-gate-const_generics.rs:7:10 - | -LL | impl A {} - | ^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/44580 - = help: add `#![feature(const_generics)]` to the crate attributes to enable - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. From b05d36228ef95f4d628b7f8338ecca3b320806e4 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:48:11 +0200 Subject: [PATCH 09/12] Revert "pre-expansion gate crate_visibility_modifier" This reverts commit 04c661ba021730bc13d33c6d55cb9aad05026f36. --- src/libsyntax/feature_gate/check.rs | 8 ++++++++ .../feature-gate-crate_visibility_modifier.rs | 3 --- .../feature-gate-crate_visibility_modifier.stderr | 11 +---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 3a32f12b255c0..184a38dfaed7e 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -661,6 +661,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } visit::walk_impl_item(self, ii) } + + fn visit_vis(&mut self, vis: &'a ast::Visibility) { + if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node { + gate_feature_post!(&self, crate_visibility_modifier, vis.span, + "`crate` visibility modifier is experimental"); + } + visit::walk_vis(self, vis) + } } pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], diff --git a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs index 7517fb280ea78..0e3f6b168be6b 100644 --- a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs +++ b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs @@ -5,7 +5,4 @@ crate struct Bender { //~ ERROR `crate` visibility modifier is experimental water: bool, } -macro_rules! accept_vis { ($v:vis) => {} } -accept_vis!(crate); //~ ERROR `crate` visibility modifier is experimental - fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr index b317872cea817..1e061eced3660 100644 --- a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr +++ b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr @@ -7,15 +7,6 @@ LL | crate struct Bender { = note: for more information, see https://github.com/rust-lang/rust/issues/53120 = help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable -error[E0658]: `crate` visibility modifier is experimental - --> $DIR/feature-gate-crate_visibility_modifier.rs:9:13 - | -LL | accept_vis!(crate); - | ^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/53120 - = help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. From 56d7bb2133c82ec73fa17d9b02872feb4bf09c63 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:49:22 +0200 Subject: [PATCH 10/12] Revert "pre-expansion gate associated_type_bounds" This reverts commit c17a1fd7d0ef0f1f546445d0c8bdb11be55e4be7. --- src/libsyntax/feature_gate/check.rs | 15 ++++++++++++++- .../feature-gate-associated_type_bounds.rs | 4 ---- .../feature-gate-associated_type_bounds.stderr | 11 +---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 184a38dfaed7e..a4fc6114b9850 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -3,7 +3,10 @@ use super::accepted::ACCEPTED_FEATURES; use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; -use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; +use crate::ast::{ + self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind, + PatKind, RangeEnd, VariantData, +}; use crate::attr::{self, check_builtin_attribute}; use crate::source_map::Spanned; use crate::edition::{ALL_EDITIONS, Edition}; @@ -604,6 +607,16 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_generic_param(self, param) } + fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) { + match constraint.kind { + AssocTyConstraintKind::Bound { .. } => + gate_feature_post!(&self, associated_type_bounds, constraint.span, + "associated type bounds are unstable"), + _ => {} + } + visit::walk_assoc_ty_constraint(self, constraint) + } + fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) { match ti.kind { ast::TraitItemKind::Method(ref sig, ref block) => { diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs index 00737d8428b3d..0faa9090f4ebc 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs @@ -70,7 +70,3 @@ fn main() { // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // let _: &dyn Tr1 = &S1; } - -macro_rules! accept_path { ($p:path) => {} } -accept_path!(Iterator); -//~^ ERROR associated type bounds are unstable diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr index a7ab7614d7b78..84af2a0163ae4 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr @@ -115,15 +115,6 @@ LL | let _: impl Tr1 = S1; = note: for more information, see https://github.com/rust-lang/rust/issues/52662 = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:75:23 - | -LL | accept_path!(Iterator); - | ^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/52662 - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/feature-gate-associated_type_bounds.rs:54:14 | @@ -148,7 +139,7 @@ LL | let _: impl Tr1 = S1; | = help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable -error: aborting due to 17 previous errors +error: aborting due to 16 previous errors Some errors have detailed explanations: E0562, E0658. For more information about an error, try `rustc --explain E0562`. From 803616a73d25adbb40c604eb93d9c8689b2164e4 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 18:50:31 +0200 Subject: [PATCH 11/12] Revert "pre-expansion gate trait_alias." This reverts commit 2d182b82ce5ecfe8090ba3d4e78f1cd72c072ef1. --- src/libsyntax/feature_gate/check.rs | 9 +++++++++ src/test/ui/feature-gates/feature-gate-trait-alias.rs | 9 --------- .../ui/feature-gates/feature-gate-trait-alias.stderr | 11 +---------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index a4fc6114b9850..482605971b854 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -446,6 +446,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "auto traits are experimental and possibly buggy"); } + ast::ItemKind::TraitAlias(..) => { + gate_feature_post!( + &self, + trait_alias, + i.span, + "trait aliases are experimental" + ); + } + ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => { let msg = "`macro` is experimental"; gate_feature_post!(&self, decl_macro, i.span, msg); diff --git a/src/test/ui/feature-gates/feature-gate-trait-alias.rs b/src/test/ui/feature-gates/feature-gate-trait-alias.rs index 4b94d7d6d3bda..819085adddade 100644 --- a/src/test/ui/feature-gates/feature-gate-trait-alias.rs +++ b/src/test/ui/feature-gates/feature-gate-trait-alias.rs @@ -1,13 +1,4 @@ trait Foo = Default; //~^ ERROR trait aliases are experimental -macro_rules! accept_item { - ($i:item) => {} -} - -accept_item! { - trait Foo = Ord + Eq; - //~^ ERROR trait aliases are experimental -} - fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-trait-alias.stderr b/src/test/ui/feature-gates/feature-gate-trait-alias.stderr index b1bf6ad349129..9250e27d15807 100644 --- a/src/test/ui/feature-gates/feature-gate-trait-alias.stderr +++ b/src/test/ui/feature-gates/feature-gate-trait-alias.stderr @@ -7,15 +7,6 @@ LL | trait Foo = Default; = note: for more information, see https://github.com/rust-lang/rust/issues/41517 = help: add `#![feature(trait_alias)]` to the crate attributes to enable -error[E0658]: trait aliases are experimental - --> $DIR/feature-gate-trait-alias.rs:9:5 - | -LL | trait Foo = Ord + Eq; - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/41517 - = help: add `#![feature(trait_alias)]` to the crate attributes to enable - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. From 27e01a1f8876eda98e82d599136ca3a953f6b3fb Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 31 Oct 2019 19:34:06 +0200 Subject: [PATCH 12/12] syntax: disable the new early feature-gatings added in #65742. --- src/libsyntax/feature_gate/check.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 482605971b854..13a24ca046d51 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -876,6 +876,21 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(yields, generators, "yield syntax is experimental"); gate_all!(or_patterns, "or-patterns syntax is experimental"); gate_all!(const_extern_fn, "`const extern fn` definitions are unstable"); + + // All uses of `gate_all!` below this point were added in #65742, + // and subsequently disabled (with the non-early gating readded). + macro_rules! gate_all { + ($gate:ident, $msg:literal) => { + // FIXME(eddyb) do something more useful than always + // disabling these uses of early feature-gatings. + if false { + for span in &*parse_sess.gated_spans.$gate.borrow() { + gate_feature!(&visitor, $gate, *span, $msg); + } + } + } + } + gate_all!(trait_alias, "trait aliases are experimental"); gate_all!(associated_type_bounds, "associated type bounds are unstable"); gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");