Skip to content

Commit d6a18b6

Browse files
authored
Rollup merge of rust-lang#65742 - Centril:gate-pre-expansion-subset, r=davidtwco
Pre-expansion gate most of the things This is a subset of rust-lang#64672. A crater run has already been done and this PR implements conclusions according to rust-lang#64672 (comment). r? @davidtwco cc @petrochenkov
2 parents fb602c7 + 15a6c09 commit d6a18b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+295
-182
lines changed

src/libstd/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220

221221
#![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))]
222222
#![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"),
223-
feature(slice_index_methods, decl_macro, coerce_unsized,
223+
feature(slice_index_methods, coerce_unsized,
224224
sgx_platform, ptr_wrapping_offset_from))]
225225
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"),
226226
feature(fixed_size_array, maybe_uninit_extra))]
@@ -251,6 +251,7 @@
251251
#![feature(container_error_extra)]
252252
#![feature(core_intrinsics)]
253253
#![feature(custom_test_frameworks)]
254+
#![feature(decl_macro)]
254255
#![feature(doc_alias)]
255256
#![feature(doc_cfg)]
256257
#![feature(doc_keyword)]

src/libsyntax/feature_gate/check.rs

+39-111
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ 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::{
7-
self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind,
8-
PatKind, RangeEnd, VariantData,
9-
};
6+
use crate::ast::{self, NodeId, PatKind, VariantData};
107
use crate::attr::{self, check_builtin_attribute};
11-
use crate::source_map::Spanned;
128
use crate::edition::{ALL_EDITIONS, Edition};
139
use crate::visit::{self, FnKind, Visitor};
1410
use crate::parse::token;
@@ -157,9 +153,6 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
157153

158154
}
159155

160-
const EXPLAIN_BOX_SYNTAX: &str =
161-
"box expression syntax is experimental; you can call `Box::new` instead";
162-
163156
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
164157
"attributes on expressions are experimental";
165158

@@ -291,6 +284,25 @@ impl<'a> PostExpansionVisitor<'a> {
291284
err.emit();
292285
}
293286
}
287+
288+
fn check_gat(&self, generics: &ast::Generics, span: Span) {
289+
if !generics.params.is_empty() {
290+
gate_feature_post!(
291+
&self,
292+
generic_associated_types,
293+
span,
294+
"generic associated types are unstable"
295+
);
296+
}
297+
if !generics.where_clause.predicates.is_empty() {
298+
gate_feature_post!(
299+
&self,
300+
generic_associated_types,
301+
span,
302+
"where clauses on associated types are unstable"
303+
);
304+
}
305+
}
294306
}
295307

296308
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
@@ -423,20 +435,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
423435
"auto traits are experimental and possibly buggy");
424436
}
425437

426-
ast::ItemKind::TraitAlias(..) => {
427-
gate_feature_post!(
428-
&self,
429-
trait_alias,
430-
i.span,
431-
"trait aliases are experimental"
432-
);
433-
}
434-
435-
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
436-
let msg = "`macro` is experimental";
437-
gate_feature_post!(&self, decl_macro, i.span, msg);
438-
}
439-
440438
ast::ItemKind::OpaqueTy(..) => {
441439
gate_feature_post!(
442440
&self,
@@ -500,37 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
500498
}
501499
}
502500

503-
fn visit_expr(&mut self, e: &'a ast::Expr) {
504-
match e.kind {
505-
ast::ExprKind::Box(_) => {
506-
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
507-
}
508-
ast::ExprKind::Type(..) => {
509-
// To avoid noise about type ascription in common syntax errors, only emit if it
510-
// is the *only* error.
511-
if self.parse_sess.span_diagnostic.err_count() == 0 {
512-
gate_feature_post!(&self, type_ascription, e.span,
513-
"type ascription is experimental");
514-
}
515-
}
516-
ast::ExprKind::TryBlock(_) => {
517-
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
518-
}
519-
ast::ExprKind::Block(_, opt_label) => {
520-
if let Some(label) = opt_label {
521-
gate_feature_post!(&self, label_break_value, label.ident.span,
522-
"labels on blocks are unstable");
523-
}
524-
}
525-
_ => {}
526-
}
527-
visit::walk_expr(self, e)
528-
}
529-
530-
fn visit_arm(&mut self, arm: &'a ast::Arm) {
531-
visit::walk_arm(self, arm)
532-
}
533-
534501
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
535502
match &pattern.kind {
536503
PatKind::Slice(pats) => {
@@ -550,25 +517,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
550517
}
551518
}
552519
}
553-
PatKind::Box(..) => {
554-
gate_feature_post!(&self, box_patterns,
555-
pattern.span,
556-
"box pattern syntax is experimental");
557-
}
558-
PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
559-
gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
560-
"exclusive range pattern syntax is experimental");
561-
}
562520
_ => {}
563521
}
564522
visit::walk_pat(self, pattern)
565523
}
566524

567-
fn visit_fn(&mut self,
568-
fn_kind: FnKind<'a>,
569-
fn_decl: &'a ast::FnDecl,
570-
span: Span,
571-
_node_id: NodeId) {
525+
fn visit_fn(&mut self, fn_kind: FnKind<'a>, fn_decl: &'a ast::FnDecl, span: Span, _: NodeId) {
572526
if let Some(header) = fn_kind.header() {
573527
// Stability of const fn methods are covered in
574528
// `visit_trait_item` and `visit_impl_item` below; this is
@@ -583,26 +537,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
583537
visit::walk_fn(self, fn_kind, fn_decl, span)
584538
}
585539

586-
fn visit_generic_param(&mut self, param: &'a GenericParam) {
587-
match param.kind {
588-
GenericParamKind::Const { .. } =>
589-
gate_feature_post!(&self, const_generics, param.ident.span,
590-
"const generics are unstable"),
591-
_ => {}
592-
}
593-
visit::walk_generic_param(self, param)
594-
}
595-
596-
fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
597-
match constraint.kind {
598-
AssocTyConstraintKind::Bound { .. } =>
599-
gate_feature_post!(&self, associated_type_bounds, constraint.span,
600-
"associated type bounds are unstable"),
601-
_ => {}
602-
}
603-
visit::walk_assoc_ty_constraint(self, constraint)
604-
}
605-
606540
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
607541
match ti.kind {
608542
ast::TraitItemKind::Method(ref sig, ref block) => {
@@ -624,14 +558,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
624558
gate_feature_post!(&self, associated_type_defaults, ti.span,
625559
"associated type defaults are unstable");
626560
}
627-
if !ti.generics.params.is_empty() {
628-
gate_feature_post!(&self, generic_associated_types, ti.span,
629-
"generic associated types are unstable");
630-
}
631-
if !ti.generics.where_clause.predicates.is_empty() {
632-
gate_feature_post!(&self, generic_associated_types, ti.span,
633-
"where clauses on associated types are unstable");
634-
}
561+
self.check_gat(&ti.generics, ti.span);
635562
}
636563
_ => {}
637564
}
@@ -661,27 +588,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
661588
);
662589
}
663590
ast::ImplItemKind::TyAlias(_) => {
664-
if !ii.generics.params.is_empty() {
665-
gate_feature_post!(&self, generic_associated_types, ii.span,
666-
"generic associated types are unstable");
667-
}
668-
if !ii.generics.where_clause.predicates.is_empty() {
669-
gate_feature_post!(&self, generic_associated_types, ii.span,
670-
"where clauses on associated types are unstable");
671-
}
591+
self.check_gat(&ii.generics, ii.span);
672592
}
673593
_ => {}
674594
}
675595
visit::walk_impl_item(self, ii)
676596
}
677-
678-
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
679-
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node {
680-
gate_feature_post!(&self, crate_visibility_modifier, vis.span,
681-
"`crate` visibility modifier is experimental");
682-
}
683-
visit::walk_vis(self, vis)
684-
}
685597
}
686598

687599
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
@@ -867,6 +779,22 @@ pub fn check_crate(krate: &ast::Crate,
867779
gate_all!(yields, generators, "yield syntax is experimental");
868780
gate_all!(or_patterns, "or-patterns syntax is experimental");
869781
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
782+
gate_all!(trait_alias, "trait aliases are experimental");
783+
gate_all!(associated_type_bounds, "associated type bounds are unstable");
784+
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
785+
gate_all!(const_generics, "const generics are unstable");
786+
gate_all!(decl_macro, "`macro` is experimental");
787+
gate_all!(box_patterns, "box pattern syntax is experimental");
788+
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
789+
gate_all!(try_blocks, "`try` blocks are unstable");
790+
gate_all!(label_break_value, "labels on blocks are unstable");
791+
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
792+
793+
// To avoid noise about type ascription in common syntax errors,
794+
// only emit if it is the *only* error. (Also check it last.)
795+
if parse_sess.span_diagnostic.err_count() == 0 {
796+
gate_all!(type_ascription, "type ascription is experimental");
797+
}
870798

871799
visit::walk_crate(&mut visitor, krate);
872800
}

src/libsyntax/parse/parser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ impl<'a> Parser<'a> {
11221122
self.expected_tokens.push(TokenType::Keyword(kw::Crate));
11231123
if self.is_crate_vis() {
11241124
self.bump(); // `crate`
1125+
self.sess.gated_spans.crate_visibility_modifier.borrow_mut().push(self.prev_span);
11251126
return Ok(respan(self.prev_span, VisibilityKind::Crate(CrateSugar::JustCrate)));
11261127
}
11271128

src/libsyntax/parse/parser/expr.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<'a> Parser<'a> {
252252
self.last_type_ascription = Some((self.prev_span, maybe_path));
253253

254254
lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?;
255+
self.sess.gated_spans.type_ascription.borrow_mut().push(lhs.span);
255256
continue
256257
} else if op == AssocOp::DotDot || op == AssocOp::DotDotEq {
257258
// If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to
@@ -453,7 +454,9 @@ impl<'a> Parser<'a> {
453454
self.bump();
454455
let e = self.parse_prefix_expr(None);
455456
let (span, e) = self.interpolated_or_expr_span(e)?;
456-
(lo.to(span), ExprKind::Box(e))
457+
let span = lo.to(span);
458+
self.sess.gated_spans.box_syntax.borrow_mut().push(span);
459+
(span, ExprKind::Box(e))
457460
}
458461
token::Ident(..) if self.token.is_ident_named(sym::not) => {
459462
// `not` is just an ordinary identifier in Rust-the-language,
@@ -1260,6 +1263,10 @@ impl<'a> Parser<'a> {
12601263
blk_mode: BlockCheckMode,
12611264
outer_attrs: ThinVec<Attribute>,
12621265
) -> PResult<'a, P<Expr>> {
1266+
if let Some(label) = opt_label {
1267+
self.sess.gated_spans.label_break_value.borrow_mut().push(label.ident.span);
1268+
}
1269+
12631270
self.expect(&token::OpenDelim(token::Brace))?;
12641271

12651272
let mut attrs = outer_attrs;
@@ -1646,7 +1653,9 @@ impl<'a> Parser<'a> {
16461653
error.emit();
16471654
Err(error)
16481655
} else {
1649-
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
1656+
let span = span_lo.to(body.span);
1657+
self.sess.gated_spans.try_blocks.borrow_mut().push(span);
1658+
Ok(self.mk_expr(span, ExprKind::TryBlock(body), attrs))
16501659
}
16511660
}
16521661

src/libsyntax/parse/parser/generics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ impl<'a> Parser<'a> {
5555
}
5656

5757
fn parse_const_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, GenericParam> {
58+
let lo = self.token.span;
59+
5860
self.expect_keyword(kw::Const)?;
5961
let ident = self.parse_ident()?;
6062
self.expect(&token::Colon)?;
6163
let ty = self.parse_ty()?;
6264

65+
self.sess.gated_spans.const_generics.borrow_mut().push(lo.to(self.prev_span));
66+
6367
Ok(GenericParam {
6468
ident,
6569
id: ast::DUMMY_NODE_ID,

0 commit comments

Comments
 (0)