diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-25 06:18:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-25 06:18:09 +0200 |
| commit | d6a18b6baf40b48abce2de5747d187a7bbad293d (patch) | |
| tree | c633afa2e2d4a69ce731623362fad60a23e526bb /src/libsyntax/parse/parser | |
| parent | fb602c7e4f5f01203c63e9c6939efa8c8f7c962a (diff) | |
| parent | 15a6c09b6e8a977f2c6f5a73de01a20d00b37930 (diff) | |
| download | rust-d6a18b6baf40b48abce2de5747d187a7bbad293d.tar.gz rust-d6a18b6baf40b48abce2de5747d187a7bbad293d.zip | |
Rollup merge of #65742 - Centril:gate-pre-expansion-subset, r=davidtwco
Pre-expansion gate most of the things This is a subset of https://github.com/rust-lang/rust/pull/64672. A crater run has already been done and this PR implements conclusions according to https://github.com/rust-lang/rust/pull/64672#issuecomment-542703363. r? @davidtwco cc @petrochenkov
Diffstat (limited to 'src/libsyntax/parse/parser')
| -rw-r--r-- | src/libsyntax/parse/parser/expr.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/generics.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/item.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/pat.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/path.rs | 12 |
5 files changed, 62 insertions, 15 deletions
diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 67a530ec683..97b1092452a 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -252,6 +252,7 @@ impl<'a> Parser<'a> { self.last_type_ascription = Some((self.prev_span, maybe_path)); lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?; + self.sess.gated_spans.type_ascription.borrow_mut().push(lhs.span); continue } else if op == AssocOp::DotDot || op == AssocOp::DotDotEq { // If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to @@ -453,7 +454,9 @@ impl<'a> Parser<'a> { self.bump(); let e = self.parse_prefix_expr(None); let (span, e) = self.interpolated_or_expr_span(e)?; - (lo.to(span), ExprKind::Box(e)) + let span = lo.to(span); + self.sess.gated_spans.box_syntax.borrow_mut().push(span); + (span, ExprKind::Box(e)) } token::Ident(..) if self.token.is_ident_named(sym::not) => { // `not` is just an ordinary identifier in Rust-the-language, @@ -1260,6 +1263,10 @@ impl<'a> Parser<'a> { blk_mode: BlockCheckMode, outer_attrs: ThinVec<Attribute>, ) -> PResult<'a, P<Expr>> { + if let Some(label) = opt_label { + self.sess.gated_spans.label_break_value.borrow_mut().push(label.ident.span); + } + self.expect(&token::OpenDelim(token::Brace))?; let mut attrs = outer_attrs; @@ -1646,7 +1653,9 @@ impl<'a> Parser<'a> { error.emit(); Err(error) } else { - Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs)) + let span = span_lo.to(body.span); + self.sess.gated_spans.try_blocks.borrow_mut().push(span); + Ok(self.mk_expr(span, ExprKind::TryBlock(body), attrs)) } } diff --git a/src/libsyntax/parse/parser/generics.rs b/src/libsyntax/parse/parser/generics.rs index bfcb0042a75..51caae69c86 100644 --- a/src/libsyntax/parse/parser/generics.rs +++ b/src/libsyntax/parse/parser/generics.rs @@ -55,11 +55,15 @@ impl<'a> Parser<'a> { } fn parse_const_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, GenericParam> { + let lo = self.token.span; + self.expect_keyword(kw::Const)?; let ident = self.parse_ident()?; self.expect(&token::Colon)?; let ty = self.parse_ty()?; + self.sess.gated_spans.const_generics.borrow_mut().push(lo.to(self.prev_span)); + Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs index 73bd80e2a21..95bddb5afdd 100644 --- a/src/libsyntax/parse/parser/item.rs +++ b/src/libsyntax/parse/parser/item.rs @@ -211,7 +211,7 @@ impl<'a> Parser<'a> { { // UNSAFE TRAIT ITEM self.bump(); // `unsafe` - let info = self.parse_item_trait(Unsafety::Unsafe)?; + let info = self.parse_item_trait(lo, Unsafety::Unsafe)?; return self.mk_item_with_info(attrs, lo, vis, info); } @@ -289,7 +289,7 @@ impl<'a> Parser<'a> { && self.is_keyword_ahead(1, &[kw::Trait])) { // TRAIT ITEM - let info = self.parse_item_trait(Unsafety::Normal)?; + let info = self.parse_item_trait(lo, Unsafety::Normal)?; return self.mk_item_with_info(attrs, lo, vis, info); } @@ -780,7 +780,7 @@ impl<'a> Parser<'a> { } /// Parses `auto? trait Foo { ... }` or `trait Foo = Bar;`. - fn parse_item_trait(&mut self, unsafety: Unsafety) -> PResult<'a, ItemInfo> { + fn parse_item_trait(&mut self, lo: Span, unsafety: Unsafety) -> PResult<'a, ItemInfo> { // Parse optional `auto` prefix. let is_auto = if self.eat_keyword(kw::Auto) { IsAuto::Yes @@ -793,29 +793,43 @@ impl<'a> Parser<'a> { let mut tps = self.parse_generics()?; // Parse optional colon and supertrait bounds. - let bounds = if self.eat(&token::Colon) { + let had_colon = self.eat(&token::Colon); + let span_at_colon = self.prev_span; + let bounds = if had_colon { self.parse_generic_bounds(Some(self.prev_span))? } else { Vec::new() }; + let span_before_eq = self.prev_span; if self.eat(&token::Eq) { // It's a trait alias. + if had_colon { + let span = span_at_colon.to(span_before_eq); + self.struct_span_err(span, "bounds are not allowed on trait aliases") + .emit(); + } + let bounds = self.parse_generic_bounds(None)?; tps.where_clause = self.parse_where_clause()?; self.expect(&token::Semi)?; + + let whole_span = lo.to(self.prev_span); if is_auto == IsAuto::Yes { let msg = "trait aliases cannot be `auto`"; - self.struct_span_err(self.prev_span, msg) - .span_label(self.prev_span, msg) + self.struct_span_err(whole_span, msg) + .span_label(whole_span, msg) .emit(); } if unsafety != Unsafety::Normal { let msg = "trait aliases cannot be `unsafe`"; - self.struct_span_err(self.prev_span, msg) - .span_label(self.prev_span, msg) + self.struct_span_err(whole_span, msg) + .span_label(whole_span, msg) .emit(); } + + self.sess.gated_spans.trait_alias.borrow_mut().push(whole_span); + Ok((ident, ItemKind::TraitAlias(tps, bounds), None)) } else { // It's a normal trait. @@ -1692,6 +1706,11 @@ impl<'a> Parser<'a> { }; let span = lo.to(self.prev_span); + + if !def.legacy { + self.sess.gated_spans.decl_macro.borrow_mut().push(span); + } + Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec()))) } diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index af795e51792..969d5dd8374 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -324,7 +324,9 @@ impl<'a> Parser<'a> { self.parse_pat_ident(BindingMode::ByRef(mutbl))? } else if self.eat_keyword(kw::Box) { // Parse `box pat` - PatKind::Box(self.parse_pat_with_range_pat(false, None)?) + let pat = self.parse_pat_with_range_pat(false, None)?; + self.sess.gated_spans.box_patterns.borrow_mut().push(lo.to(self.prev_span)); + PatKind::Box(pat) } else if self.can_be_ident_pat() { // Parse `ident @ pat` // This can give false positives and parse nullary enums, @@ -609,6 +611,11 @@ impl<'a> Parser<'a> { Ok(PatKind::Mac(mac)) } + fn excluded_range_end(&self, span: Span) -> RangeEnd { + self.sess.gated_spans.exclusive_range_pattern.borrow_mut().push(span); + RangeEnd::Excluded + } + /// Parse a range pattern `$path $form $end?` where `$form = ".." | "..." | "..=" ;`. /// The `$path` has already been parsed and the next token is the `$form`. fn parse_pat_range_starting_with_path( @@ -618,7 +625,7 @@ impl<'a> Parser<'a> { path: Path ) -> PResult<'a, PatKind> { let (end_kind, form) = match self.token.kind { - token::DotDot => (RangeEnd::Excluded, ".."), + token::DotDot => (self.excluded_range_end(self.token.span), ".."), token::DotDotDot => (RangeEnd::Included(RangeSyntax::DotDotDot), "..."), token::DotDotEq => (RangeEnd::Included(RangeSyntax::DotDotEq), "..="), _ => panic!("can only parse `..`/`...`/`..=` for ranges (checked above)"), @@ -641,7 +648,7 @@ impl<'a> Parser<'a> { } else if self.eat(&token::DotDotEq) { (RangeEnd::Included(RangeSyntax::DotDotEq), "..=") } else if self.eat(&token::DotDot) { - (RangeEnd::Excluded, "..") + (self.excluded_range_end(op_span), "..") } else { panic!("impossible case: we already matched on a range-operator token") }; diff --git a/src/libsyntax/parse/parser/path.rs b/src/libsyntax/parse/parser/path.rs index 639d61a2b5c..77709a22953 100644 --- a/src/libsyntax/parse/parser/path.rs +++ b/src/libsyntax/parse/parser/path.rs @@ -404,8 +404,9 @@ impl<'a> Parser<'a> { // Parse lifetime argument. args.push(GenericArg::Lifetime(self.expect_lifetime())); misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints); - } else if self.check_ident() && self.look_ahead(1, - |t| t == &token::Eq || t == &token::Colon) { + } else if self.check_ident() + && self.look_ahead(1, |t| t == &token::Eq || t == &token::Colon) + { // Parse associated type constraint. let lo = self.token.span; let ident = self.parse_ident()?; @@ -420,7 +421,14 @@ impl<'a> Parser<'a> { } else { unreachable!(); }; + let span = lo.to(self.prev_span); + + // Gate associated type bounds, e.g., `Iterator<Item: Ord>`. + if let AssocTyConstraintKind::Bound { .. } = kind { + self.sess.gated_spans.associated_type_bounds.borrow_mut().push(span); + } + constraints.push(AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, |
