ast: Mac/Macro -> MacCall
This commit is contained in:
parent
23de8275c9
commit
e809e0214e
43 changed files with 200 additions and 197 deletions
|
|
@ -4,8 +4,8 @@ use super::{BlockMode, Parser, PathStyle, Restrictions, TokenType};
|
|||
use super::{SemiColonMode, SeqSep, TokenExpectType};
|
||||
use crate::maybe_recover_from_interpolated_ty_qpath;
|
||||
|
||||
use rustc_ast::ast::{self, AttrStyle, AttrVec, CaptureBy, Field, Ident, Lit, DUMMY_NODE_ID};
|
||||
use rustc_ast::ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, Mac, Param, Ty, TyKind, UnOp};
|
||||
use rustc_ast::ast::{self, AttrStyle, AttrVec, CaptureBy, Field, Ident, Lit, UnOp, DUMMY_NODE_ID};
|
||||
use rustc_ast::ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
|
||||
use rustc_ast::ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
|
|
@ -1065,12 +1065,12 @@ impl<'a> Parser<'a> {
|
|||
// `!`, as an operator, is prefix, so we know this isn't that.
|
||||
let (hi, kind) = if self.eat(&token::Not) {
|
||||
// MACRO INVOCATION expression
|
||||
let mac = Mac {
|
||||
let mac = MacCall {
|
||||
path,
|
||||
args: self.parse_mac_args()?,
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
};
|
||||
(self.prev_token.span, ExprKind::Mac(mac))
|
||||
(self.prev_token.span, ExprKind::MacCall(mac))
|
||||
} else if self.check(&token::OpenDelim(token::Brace)) {
|
||||
if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) {
|
||||
return expr;
|
||||
|
|
|
|||
|
|
@ -4,16 +4,12 @@ use super::{FollowedByType, Parser, PathStyle};
|
|||
|
||||
use crate::maybe_whole;
|
||||
|
||||
use rustc_ast::ast::{self, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID};
|
||||
use rustc_ast::ast::{self, Async, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID};
|
||||
use rustc_ast::ast::{AssocItem, AssocItemKind, ForeignItemKind, Item, ItemKind};
|
||||
use rustc_ast::ast::{
|
||||
Async, Const, Defaultness, IsAuto, PathSegment, Unsafe, UseTree, UseTreeKind,
|
||||
};
|
||||
use rustc_ast::ast::{
|
||||
BindingMode, Block, FnDecl, FnSig, Mac, MacArgs, MacDelimiter, Param, SelfKind,
|
||||
};
|
||||
use rustc_ast::ast::{BindingMode, Block, FnDecl, FnSig, MacArgs, MacCall, MacDelimiter, Param};
|
||||
use rustc_ast::ast::{Const, Defaultness, IsAuto, PathSegment, Unsafe, UseTree, UseTreeKind};
|
||||
use rustc_ast::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData};
|
||||
use rustc_ast::ast::{FnHeader, ForeignItem, Mutability, Visibility, VisibilityKind};
|
||||
use rustc_ast::ast::{FnHeader, ForeignItem, Mutability, SelfKind, Visibility, VisibilityKind};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token;
|
||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
||||
|
|
@ -220,7 +216,7 @@ impl<'a> Parser<'a> {
|
|||
return Ok(None);
|
||||
} else if macros_allowed && self.check_path() {
|
||||
// MACRO INVOCATION ITEM
|
||||
(Ident::invalid(), ItemKind::Mac(self.parse_item_macro(vis)?))
|
||||
(Ident::invalid(), ItemKind::MacCall(self.parse_item_macro(vis)?))
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
|
@ -339,13 +335,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses an item macro, e.g., `item!();`.
|
||||
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, Mac> {
|
||||
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall> {
|
||||
let path = self.parse_path(PathStyle::Mod)?; // `foo::bar`
|
||||
self.expect(&token::Not)?; // `!`
|
||||
let args = self.parse_mac_args()?; // `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
|
||||
self.eat_semi_for_macro_if_needed(&args);
|
||||
self.complain_if_pub_macro(vis, false);
|
||||
Ok(Mac { path, args, prior_type_ascription: self.last_type_ascription })
|
||||
Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription })
|
||||
}
|
||||
|
||||
/// Recover if we parsed attributes and expected an item but there was none.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
use super::{Parser, PathStyle};
|
||||
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||
use rustc_ast::ast::{
|
||||
self, AttrVec, Attribute, FieldPat, Mac, Pat, PatKind, RangeEnd, RangeSyntax,
|
||||
};
|
||||
use rustc_ast::ast::{BindingMode, Expr, ExprKind, Ident, Mutability, Path, QSelf};
|
||||
use rustc_ast::ast::{self, AttrVec, Attribute, FieldPat, MacCall, Pat, PatKind, RangeEnd};
|
||||
use rustc_ast::ast::{BindingMode, Expr, ExprKind, Ident, Mutability, Path, QSelf, RangeSyntax};
|
||||
use rustc_ast::mut_visit::{noop_visit_mac, noop_visit_pat, MutVisitor};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token;
|
||||
|
|
@ -540,7 +538,7 @@ impl<'a> Parser<'a> {
|
|||
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
|
||||
struct AddMut(bool);
|
||||
impl MutVisitor for AddMut {
|
||||
fn visit_mac(&mut self, mac: &mut Mac) {
|
||||
fn visit_mac(&mut self, mac: &mut MacCall) {
|
||||
noop_visit_mac(mac, self);
|
||||
}
|
||||
|
||||
|
|
@ -597,8 +595,8 @@ impl<'a> Parser<'a> {
|
|||
fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind> {
|
||||
self.bump();
|
||||
let args = self.parse_mac_args()?;
|
||||
let mac = Mac { path, args, prior_type_ascription: self.last_type_ascription };
|
||||
Ok(PatKind::Mac(mac))
|
||||
let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
|
||||
Ok(PatKind::MacCall(mac))
|
||||
}
|
||||
|
||||
fn fatal_unexpected_non_pat(
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::maybe_whole;
|
|||
use crate::DirectoryOwnership;
|
||||
|
||||
use rustc_ast::ast;
|
||||
use rustc_ast::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle};
|
||||
use rustc_ast::ast::{AttrStyle, AttrVec, Attribute, MacCall, MacStmtStyle};
|
||||
use rustc_ast::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, TokenKind};
|
||||
|
|
@ -110,14 +110,14 @@ impl<'a> Parser<'a> {
|
|||
let style =
|
||||
if delim == token::Brace { MacStmtStyle::Braces } else { MacStmtStyle::NoBraces };
|
||||
|
||||
let mac = Mac { path, args, prior_type_ascription: self.last_type_ascription };
|
||||
let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
|
||||
|
||||
let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
|
||||
{
|
||||
StmtKind::Mac(P((mac, style, attrs)))
|
||||
StmtKind::MacCall(P((mac, style, attrs)))
|
||||
} else {
|
||||
// Since none of the above applied, this is an expression statement macro.
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::Mac(mac), AttrVec::new());
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
|
||||
let e = self.maybe_recover_from_bad_qpath(e, true)?;
|
||||
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
|
||||
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@ use super::{Parser, PathStyle, TokenType};
|
|||
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||
|
||||
use rustc_ast::ast::{self, BareFnTy, FnRetTy, GenericParam, Lifetime, MutTy, Ty, TyKind};
|
||||
use rustc_ast::ast::{
|
||||
GenericBound, GenericBounds, PolyTraitRef, TraitBoundModifier, TraitObjectSyntax,
|
||||
};
|
||||
use rustc_ast::ast::{Mac, Mutability};
|
||||
use rustc_ast::ast::{GenericBound, GenericBounds, MacCall, Mutability};
|
||||
use rustc_ast::ast::{PolyTraitRef, TraitBoundModifier, TraitObjectSyntax};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, PResult};
|
||||
|
|
@ -355,7 +353,7 @@ impl<'a> Parser<'a> {
|
|||
let path = self.parse_path(PathStyle::Type)?;
|
||||
if self.eat(&token::Not) {
|
||||
// Macro invocation in type position
|
||||
Ok(TyKind::Mac(Mac {
|
||||
Ok(TyKind::MacCall(MacCall {
|
||||
path,
|
||||
args: self.parse_mac_args()?,
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue