diff options
| author | bors <bors@rust-lang.org> | 2019-11-07 07:55:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-07 07:55:39 +0000 |
| commit | 50f8aadd746ebc929a752e5ffb133936ee75c52f (patch) | |
| tree | 47453a165c08c24ca9b3224506ff74a2f8b053e5 /src/libsyntax/parse | |
| parent | 7a76fe76f756895b8cda1e10398f2268656a2e0f (diff) | |
| parent | c9eae9ea63abe57d8bb91905d5ca4cff8dd8ea56 (diff) | |
| download | rust-50f8aadd746ebc929a752e5ffb133936ee75c52f.tar.gz rust-50f8aadd746ebc929a752e5ffb133936ee75c52f.zip | |
Auto merge of #66180 - Centril:rollup-c1ji943, r=Centril
Rollup of 5 pull requests Successful merges: - #59789 (Revert two unapproved changes to rustc_typeck.) - #65752 (Use structured suggestions for missing associated items) - #65884 (syntax: ABI-oblivious grammar) - #65974 (A scheme for more macro-matcher friendly pre-expansion gating) - #66017 (Add future incompatibility lint for `array.into_iter()`) Failed merges: - #66056 (rustc_metadata: Some reorganization of the module structure) r? @ghost
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/literal.rs | 23 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 70 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/expr.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/generics.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/item.rs | 29 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/pat.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/path.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 11 |
8 files changed, 81 insertions, 102 deletions
diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index c42f4aa25cc..a8eeac59954 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -157,17 +157,18 @@ impl LitKind { } LitKind::Int(n, ty) => { let suffix = match ty { - ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()), - ast::LitIntType::Signed(ty) => Some(ty.to_symbol()), + ast::LitIntType::Unsigned(ty) => Some(ty.name()), + ast::LitIntType::Signed(ty) => Some(ty.name()), ast::LitIntType::Unsuffixed => None, }; (token::Integer, sym::integer(n), suffix) } LitKind::Float(symbol, ty) => { - (token::Float, symbol, Some(ty.to_symbol())) - } - LitKind::FloatUnsuffixed(symbol) => { - (token::Float, symbol, None) + let suffix = match ty { + ast::LitFloatType::Suffixed(ty) => Some(ty.name()), + ast::LitFloatType::Unsuffixed => None, + }; + (token::Float, symbol, suffix) } LitKind::Bool(value) => { let symbol = if value { kw::True } else { kw::False }; @@ -244,12 +245,12 @@ fn filtered_float_lit(symbol: Symbol, suffix: Option<Symbol>, base: u32) return Err(LitError::NonDecimalFloat(base)); } Ok(match suffix { - Some(suf) => match suf { - sym::f32 => LitKind::Float(symbol, ast::FloatTy::F32), - sym::f64 => LitKind::Float(symbol, ast::FloatTy::F64), + Some(suf) => LitKind::Float(symbol, ast::LitFloatType::Suffixed(match suf { + sym::f32 => ast::FloatTy::F32, + sym::f64 => ast::FloatTy::F64, _ => return Err(LitError::InvalidFloatSuffix), - } - None => LitKind::FloatUnsuffixed(symbol) + })), + None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed) }) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7652c730e51..1284e89f195 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -12,7 +12,7 @@ mod diagnostics; use diagnostics::Error; use crate::ast::{ - self, DUMMY_NODE_ID, AttrStyle, Attribute, CrateSugar, Ident, + self, Abi, DUMMY_NODE_ID, AttrStyle, Attribute, CrateSugar, Ident, IsAsync, MacDelimiter, Mutability, StrStyle, Visibility, VisibilityKind, Unsafety, }; use crate::parse::{PResult, Directory, DirectoryOwnership}; @@ -28,7 +28,6 @@ use crate::tokenstream::{self, DelimSpan, TokenTree, TokenStream, TreeAndJoint}; use crate::ThinVec; use errors::{Applicability, DiagnosticBuilder, DiagnosticId, FatalError}; -use rustc_target::spec::abi::{self, Abi}; use syntax_pos::{Span, BytePos, DUMMY_SP, FileName}; use log::debug; @@ -1121,7 +1120,7 @@ impl<'a> Parser<'a> { self.expected_tokens.push(TokenType::Keyword(kw::Crate)); if self.is_crate_vis() { self.bump(); // `crate` - self.sess.gated_spans.crate_visibility_modifier.borrow_mut().push(self.prev_span); + self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_span); return Ok(respan(self.prev_span, VisibilityKind::Crate(CrateSugar::JustCrate))); } @@ -1206,48 +1205,41 @@ impl<'a> Parser<'a> { Ok(()) } - /// Parses `extern` followed by an optional ABI string, or nothing. + /// Parses `extern string_literal?`. + /// If `extern` is not found, the Rust ABI is used. + /// If `extern` is found and a `string_literal` does not follow, the C ABI is used. fn parse_extern_abi(&mut self) -> PResult<'a, Abi> { - if self.eat_keyword(kw::Extern) { - Ok(self.parse_opt_abi()?.unwrap_or(Abi::C)) + Ok(if self.eat_keyword(kw::Extern) { + self.parse_opt_abi()? } else { - Ok(Abi::Rust) - } + Abi::default() + }) } - /// Parses a string as an ABI spec on an extern type or module. Consumes - /// the `extern` keyword, if one is found. - fn parse_opt_abi(&mut self) -> PResult<'a, Option<Abi>> { - match self.token.kind { - token::Literal(token::Lit { kind: token::Str, symbol, suffix }) | - token::Literal(token::Lit { kind: token::StrRaw(..), symbol, suffix }) => { - self.expect_no_suffix(self.token.span, "an ABI spec", suffix); - self.bump(); - match abi::lookup(&symbol.as_str()) { - Some(abi) => Ok(Some(abi)), - None => { - self.error_on_invalid_abi(symbol); - Ok(None) - } + /// Parses a string literal as an ABI spec. + /// If one is not found, the "C" ABI is used. + fn parse_opt_abi(&mut self) -> PResult<'a, Abi> { + let span = if self.token.can_begin_literal_or_bool() { + let ast::Lit { span, kind, .. } = self.parse_lit()?; + match kind { + ast::LitKind::Str(symbol, _) => return Ok(Abi::new(symbol, span)), + ast::LitKind::Err(_) => {} + _ => { + self.struct_span_err(span, "non-string ABI literal") + .span_suggestion( + span, + "specify the ABI with a string literal", + "\"C\"".to_string(), + Applicability::MaybeIncorrect, + ) + .emit(); } } - _ => Ok(None), - } - } - - /// Emit an error where `symbol` is an invalid ABI. - fn error_on_invalid_abi(&self, symbol: Symbol) { - let prev_span = self.prev_span; - struct_span_err!( - self.sess.span_diagnostic, - prev_span, - E0703, - "invalid ABI: found `{}`", - symbol - ) - .span_label(prev_span, "invalid ABI") - .help(&format!("valid ABIs: {}", abi::all_names().join(", "))) - .emit(); + span + } else { + self.prev_span + }; + Ok(Abi::new(sym::C, span)) } /// We are parsing `async fn`. If we are on Rust 2015, emit an error. diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 97b1092452a..509e6482dcc 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -16,10 +16,10 @@ use crate::parse::token::{self, Token, TokenKind}; use crate::print::pprust; use crate::ptr::P; use crate::source_map::{self, Span}; -use crate::symbol::{kw, sym}; use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par}; use errors::Applicability; +use syntax_pos::symbol::{kw, sym}; use syntax_pos::Symbol; use std::mem; use rustc_data_structures::thin_vec::ThinVec; @@ -252,7 +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); + self.sess.gated_spans.gate(sym::type_ascription, 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 @@ -455,7 +455,7 @@ impl<'a> Parser<'a> { let e = self.parse_prefix_expr(None); let (span, e) = self.interpolated_or_expr_span(e)?; let span = lo.to(span); - self.sess.gated_spans.box_syntax.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::box_syntax, span); (span, ExprKind::Box(e)) } token::Ident(..) if self.token.is_ident_named(sym::not) => { @@ -1045,7 +1045,7 @@ impl<'a> Parser<'a> { } let span = lo.to(hi); - self.sess.gated_spans.yields.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::generators, span); } else if self.eat_keyword(kw::Let) { return self.parse_let_expr(attrs); } else if is_span_rust_2018 && self.eat_keyword(kw::Await) { @@ -1116,7 +1116,11 @@ impl<'a> Parser<'a> { Err(self.span_fatal(token.span, &msg)) } Err(err) => { - let (lit, span) = (token.expect_lit(), token.span); + let span = token.span; + let lit = match token.kind { + token::Literal(lit) => lit, + _ => unreachable!(), + }; self.bump(); self.error_literal_from_token(err, lit, span); // Pack possible quotes and prefixes from the original literal into @@ -1264,7 +1268,7 @@ impl<'a> Parser<'a> { 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.sess.gated_spans.gate(sym::label_break_value, label.ident.span); } self.expect(&token::OpenDelim(token::Brace))?; @@ -1293,7 +1297,7 @@ impl<'a> Parser<'a> { }; if asyncness.is_async() { // Feature-gate `async ||` closures. - self.sess.gated_spans.async_closure.borrow_mut().push(self.prev_span); + self.sess.gated_spans.gate(sym::async_closure, self.prev_span); } let capture_clause = self.parse_capture_clause(); @@ -1415,8 +1419,7 @@ impl<'a> Parser<'a> { if let ExprKind::Let(..) = cond.kind { // Remove the last feature gating of a `let` expression since it's stable. - let last = self.sess.gated_spans.let_chains.borrow_mut().pop(); - debug_assert_eq!(cond.span, last.unwrap()); + self.sess.gated_spans.ungate_last(sym::let_chains, cond.span); } Ok(cond) @@ -1433,7 +1436,7 @@ impl<'a> Parser<'a> { |this| this.parse_assoc_expr_with(1 + prec_let_scrutinee_needs_par(), None.into()) )?; let span = lo.to(expr.span); - self.sess.gated_spans.let_chains.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::let_chains, span); Ok(self.mk_expr(span, ExprKind::Let(pat, expr), attrs)) } @@ -1654,7 +1657,7 @@ impl<'a> Parser<'a> { Err(error) } else { let span = span_lo.to(body.span); - self.sess.gated_spans.try_blocks.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::try_blocks, 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 51caae69c86..3c094750b4d 100644 --- a/src/libsyntax/parse/parser/generics.rs +++ b/src/libsyntax/parse/parser/generics.rs @@ -3,7 +3,8 @@ use super::{Parser, PResult}; use crate::ast::{self, WhereClause, GenericParam, GenericParamKind, GenericBounds, Attribute}; use crate::parse::token; use crate::source_map::DUMMY_SP; -use crate::symbol::kw; + +use syntax_pos::symbol::{kw, sym}; impl<'a> Parser<'a> { /// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`. @@ -62,7 +63,7 @@ impl<'a> Parser<'a> { self.expect(&token::Colon)?; let ty = self.parse_ty()?; - self.sess.gated_spans.const_generics.borrow_mut().push(lo.to(self.prev_span)); + self.sess.gated_spans.gate(sym::const_generics, lo.to(self.prev_span)); Ok(GenericParam { ident, diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs index cc6235c6fc7..9d543055f23 100644 --- a/src/libsyntax/parse/parser/item.rs +++ b/src/libsyntax/parse/parser/item.rs @@ -3,7 +3,7 @@ use super::diagnostics::{Error, dummy_arg, ConsumeClosingDelim}; use crate::maybe_whole; use crate::ptr::P; -use crate::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item}; +use crate::ast::{self, Abi, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item}; use crate::ast::{ItemKind, ImplItem, ImplItemKind, TraitItem, TraitItemKind, UseTree, UseTreeKind}; use crate::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness}; use crate::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind}; @@ -17,7 +17,6 @@ use crate::ThinVec; use log::debug; use std::mem; -use rustc_target::spec::abi::Abi; use errors::{Applicability, DiagnosticBuilder, DiagnosticId, StashKey}; use syntax_pos::BytePos; @@ -111,7 +110,7 @@ impl<'a> Parser<'a> { return Ok(Some(self.parse_item_extern_crate(lo, vis, attrs)?)); } - let opt_abi = self.parse_opt_abi()?; + let abi = self.parse_opt_abi()?; if self.eat_keyword(kw::Fn) { // EXTERN FUNCTION ITEM @@ -120,12 +119,12 @@ impl<'a> Parser<'a> { unsafety: Unsafety::Normal, asyncness: respan(fn_span, IsAsync::NotAsync), constness: respan(fn_span, Constness::NotConst), - abi: opt_abi.unwrap_or(Abi::C), + abi, }; return self.parse_item_fn(lo, vis, attrs, header); } else if self.check(&token::OpenDelim(token::Brace)) { return Ok(Some( - self.parse_item_foreign_mod(lo, opt_abi, vis, attrs, extern_sp)?, + self.parse_item_foreign_mod(lo, abi, vis, attrs, extern_sp)?, )); } @@ -147,9 +146,7 @@ impl<'a> Parser<'a> { let unsafety = self.parse_unsafety(); if self.check_keyword(kw::Extern) { - self.sess.gated_spans.const_extern_fn.borrow_mut().push( - lo.to(self.token.span) - ); + self.sess.gated_spans.gate(sym::const_extern_fn, lo.to(self.token.span)); } let abi = self.parse_extern_abi()?; self.bump(); // `fn` @@ -201,7 +198,7 @@ impl<'a> Parser<'a> { unsafety, asyncness, constness: respan(fn_span, Constness::NotConst), - abi: Abi::Rust, + abi: Abi::new(sym::Rust, fn_span), }; return self.parse_item_fn(lo, vis, attrs, header); } @@ -238,7 +235,7 @@ impl<'a> Parser<'a> { unsafety: Unsafety::Normal, asyncness: respan(fn_span, IsAsync::NotAsync), constness: respan(fn_span, Constness::NotConst), - abi: Abi::Rust, + abi: Abi::new(sym::Rust, fn_span), }; return self.parse_item_fn(lo, vis, attrs, header); } @@ -832,7 +829,7 @@ impl<'a> Parser<'a> { .emit(); } - self.sess.gated_spans.trait_alias.borrow_mut().push(whole_span); + self.sess.gated_spans.gate(sym::trait_alias, whole_span); Ok((ident, ItemKind::TraitAlias(tps, bounds), None)) } else { @@ -1115,15 +1112,13 @@ impl<'a> Parser<'a> { fn parse_item_foreign_mod( &mut self, lo: Span, - opt_abi: Option<Abi>, + abi: Abi, visibility: Visibility, mut attrs: Vec<Attribute>, extern_sp: Span, ) -> PResult<'a, P<Item>> { self.expect(&token::OpenDelim(token::Brace))?; - let abi = opt_abi.unwrap_or(Abi::C); - attrs.extend(self.parse_inner_attributes()?); let mut foreign_items = vec![]; @@ -1714,7 +1709,7 @@ impl<'a> Parser<'a> { let span = lo.to(self.prev_span); if !def.legacy { - self.sess.gated_spans.decl_macro.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::decl_macro, span); } Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec()))) @@ -1801,7 +1796,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, Option<P<Item>>> { let (ident, decl, generics) = self.parse_fn_sig(ParamCfg { is_self_allowed: false, - allow_c_variadic: header.abi == Abi::C && header.unsafety == Unsafety::Unsafe, + allow_c_variadic: header.abi.symbol == sym::C && header.unsafety == Unsafety::Unsafe, is_name_required: |_| true, })?; let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; @@ -1930,7 +1925,7 @@ impl<'a> Parser<'a> { let asyncness = respan(self.prev_span, asyncness); let unsafety = self.parse_unsafety(); let (constness, unsafety, abi) = if is_const_fn { - (respan(const_span, Constness::Const), unsafety, Abi::Rust) + (respan(const_span, Constness::Const), unsafety, Abi::default()) } else { let abi = self.parse_extern_abi()?; (respan(self.prev_span, Constness::NotConst), unsafety, abi) diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index 969d5dd8374..cc8738edff7 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -8,9 +8,8 @@ use crate::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor}; use crate::parse::token::{self}; use crate::print::pprust; use crate::source_map::{respan, Span, Spanned}; -use crate::symbol::kw; use crate::ThinVec; - +use syntax_pos::symbol::{kw, sym}; use errors::{Applicability, DiagnosticBuilder}; type Expected = Option<&'static str>; @@ -52,11 +51,8 @@ impl<'a> Parser<'a> { // and no other gated or-pattern has been parsed thus far, // then we should really gate the leading `|`. // This complicated procedure is done purely for diagnostics UX. - if gated_leading_vert { - let mut or_pattern_spans = self.sess.gated_spans.or_patterns.borrow_mut(); - if or_pattern_spans.is_empty() { - or_pattern_spans.push(leading_vert_span); - } + if gated_leading_vert && self.sess.gated_spans.is_ungated(sym::or_patterns) { + self.sess.gated_spans.gate(sym::or_patterns, leading_vert_span); } Ok(pat) @@ -117,7 +113,7 @@ impl<'a> Parser<'a> { // Feature gate the or-pattern if instructed: if gate_or == GateOr::Yes { - self.sess.gated_spans.or_patterns.borrow_mut().push(or_pattern_span); + self.sess.gated_spans.gate(sym::or_patterns, or_pattern_span); } Ok(self.mk_pat(or_pattern_span, PatKind::Or(pats))) @@ -325,7 +321,7 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(kw::Box) { // Parse `box pat` let pat = self.parse_pat_with_range_pat(false, None)?; - self.sess.gated_spans.box_patterns.borrow_mut().push(lo.to(self.prev_span)); + self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_span)); PatKind::Box(pat) } else if self.can_be_ident_pat() { // Parse `ident @ pat` @@ -612,7 +608,7 @@ impl<'a> Parser<'a> { } fn excluded_range_end(&self, span: Span) -> RangeEnd { - self.sess.gated_spans.exclusive_range_pattern.borrow_mut().push(span); + self.sess.gated_spans.gate(sym::exclusive_range_pattern, span); RangeEnd::Excluded } diff --git a/src/libsyntax/parse/parser/path.rs b/src/libsyntax/parse/parser/path.rs index f9944e36e2f..4438d61d9ee 100644 --- a/src/libsyntax/parse/parser/path.rs +++ b/src/libsyntax/parse/parser/path.rs @@ -5,7 +5,7 @@ use crate::ast::{self, QSelf, Path, PathSegment, Ident, ParenthesizedArgs, Angle use crate::ast::{AnonConst, GenericArg, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode}; use crate::parse::token::{self, Token}; use crate::source_map::{Span, BytePos}; -use crate::symbol::kw; +use syntax_pos::symbol::{kw, sym}; use std::mem; use log::debug; @@ -426,7 +426,7 @@ impl<'a> Parser<'a> { // 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); + self.sess.gated_spans.gate(sym::associated_type_bounds, span); } constraints.push(AssocTyConstraint { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 03e77b199cc..6f3da344ccf 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -381,9 +381,7 @@ impl Token { match self.kind { OpenDelim(Brace) => true, Interpolated(ref nt) => match **nt { - NtExpr(..) => true, - NtBlock(..) => true, - NtLiteral(..) => true, + NtExpr(..) | NtBlock(..) | NtLiteral(..) => true, _ => false, } _ => self.can_begin_literal_or_bool(), @@ -404,13 +402,6 @@ impl Token { } } - crate fn expect_lit(&self) -> Lit { - match self.kind { - Literal(lit) => lit, - _ => panic!("`expect_lit` called on non-literal"), - } - } - /// Returns `true` if the token is any literal, a minus (which can prefix a literal, /// for example a '-42', or one of the boolean idents). pub fn can_begin_literal_or_bool(&self) -> bool { |
