diff options
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r-- | compiler/rustc_ast/src/ast.rs | 15 | ||||
-rw-r--r-- | compiler/rustc_ast/src/expand/mod.rs | 17 | ||||
-rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 1 | ||||
-rw-r--r-- | compiler/rustc_ast/src/token.rs | 1 | ||||
-rw-r--r-- | compiler/rustc_ast/src/tokenstream.rs | 15 | ||||
-rw-r--r-- | compiler/rustc_ast/src/util/parser.rs | 4 | ||||
-rw-r--r-- | compiler/rustc_ast/src/visit.rs | 1 |
7 files changed, 50 insertions, 4 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 4360fbeb9..a7198fbf8 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1295,6 +1295,7 @@ impl Expr { ExprKind::Yield(..) => ExprPrecedence::Yield, ExprKind::Yeet(..) => ExprPrecedence::Yeet, ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs, + ExprKind::Become(..) => ExprPrecedence::Become, ExprKind::Err => ExprPrecedence::Err, } } @@ -1515,6 +1516,11 @@ pub enum ExprKind { /// with an optional value to be returned. Yeet(Option<P<Expr>>), + /// A tail call return, with the value to be returned. + /// + /// While `.0` must be a function call, we check this later, after parsing. + Become(P<Expr>), + /// Bytes included via `include_bytes!` /// Added for optimization purposes to avoid the need to escape /// large binary blobs - should always behave like [`ExprKind::Lit`] @@ -2646,6 +2652,15 @@ pub struct NormalAttr { pub tokens: Option<LazyAttrTokenStream>, } +impl NormalAttr { + pub fn from_ident(ident: Ident) -> Self { + Self { + item: AttrItem { path: Path::from_ident(ident), args: AttrArgs::Empty, tokens: None }, + tokens: None, + } + } +} + #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct AttrItem { pub path: Path, diff --git a/compiler/rustc_ast/src/expand/mod.rs b/compiler/rustc_ast/src/expand/mod.rs index 2ee1bfe0a..942347383 100644 --- a/compiler/rustc_ast/src/expand/mod.rs +++ b/compiler/rustc_ast/src/expand/mod.rs @@ -1,3 +1,20 @@ //! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`. +use rustc_span::{def_id::DefId, symbol::Ident}; + +use crate::MetaItem; + pub mod allocator; + +#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] +pub struct StrippedCfgItem<ModId = DefId> { + pub parent_module: ModId, + pub name: Ident, + pub cfg: MetaItem, +} + +impl<ModId> StrippedCfgItem<ModId> { + pub fn map_mod_id<New>(self, f: impl FnOnce(ModId) -> New) -> StrippedCfgItem<New> { + StrippedCfgItem { parent_module: f(self.parent_module), name: self.name, cfg: self.cfg } + } +} diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 66b94d12a..53a9c9a04 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1457,6 +1457,7 @@ pub fn noop_visit_expr<T: MutVisitor>( ExprKind::Yeet(expr) => { visit_opt(expr, |expr| vis.visit_expr(expr)); } + ExprKind::Become(expr) => vis.visit_expr(expr), ExprKind::InlineAsm(asm) => vis.visit_inline_asm(asm), ExprKind::FormatArgs(fmt) => vis.visit_format_args(fmt), ExprKind::OffsetOf(container, fields) => { diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 7ef39f802..6646fa944 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -11,6 +11,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_macros::HashStable_Generic; use rustc_span::symbol::{kw, sym}; +#[cfg_attr(not(bootstrap), allow(hidden_glob_reexports))] use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{self, edition::Edition, Span, DUMMY_SP}; use std::borrow::Cow; diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index db296aa44..ca4a739ab 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -25,7 +25,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::{Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; -use std::{fmt, iter}; +use std::{fmt, iter, mem}; /// When the main Rust parser encounters a syntax-extension invocation, it /// parses the arguments to the invocation as a token tree. This is a very @@ -410,8 +410,17 @@ impl TokenStream { t1.next().is_none() && t2.next().is_none() } - pub fn map_enumerated<F: FnMut(usize, &TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream { - TokenStream(Lrc::new(self.0.iter().enumerate().map(|(i, tree)| f(i, tree)).collect())) + /// Applies the supplied function to each `TokenTree` and its index in `self`, returning a new `TokenStream` + /// + /// It is equivalent to `TokenStream::new(self.trees().cloned().enumerate().map(|(i, tt)| f(i, tt)).collect())`. + pub fn map_enumerated_owned( + mut self, + mut f: impl FnMut(usize, TokenTree) -> TokenTree, + ) -> TokenStream { + let owned = Lrc::make_mut(&mut self.0); // clone if necessary + // rely on vec's in-place optimizations to avoid another allocation + *owned = mem::take(owned).into_iter().enumerate().map(|(i, tree)| f(i, tree)).collect(); + self } /// Create a token stream containing a single token with alone spacing. diff --git a/compiler/rustc_ast/src/util/parser.rs b/compiler/rustc_ast/src/util/parser.rs index 35afd5423..096077e09 100644 --- a/compiler/rustc_ast/src/util/parser.rs +++ b/compiler/rustc_ast/src/util/parser.rs @@ -245,6 +245,7 @@ pub enum ExprPrecedence { Ret, Yield, Yeet, + Become, Range, @@ -298,7 +299,8 @@ impl ExprPrecedence { | ExprPrecedence::Continue | ExprPrecedence::Ret | ExprPrecedence::Yield - | ExprPrecedence::Yeet => PREC_JUMP, + | ExprPrecedence::Yeet + | ExprPrecedence::Become => PREC_JUMP, // `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to // parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 275692ad5..d9de5b8e1 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -908,6 +908,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { ExprKind::Yeet(optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); } + ExprKind::Become(expr) => visitor.visit_expr(expr), ExprKind::MacCall(mac) => visitor.visit_mac_call(mac), ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression), ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm), |