diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-08-24 21:12:13 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-08-27 00:31:55 +0300 |
| commit | ec45b87957c4158934fc3f5a821594ad0686ea4e (patch) | |
| tree | 59abaac544f9b95b121f12537476e11b62f7d8b7 /src/libsyntax/ext/base.rs | |
| parent | 9b91b9c10e3c87ed333a1e34c4f46ed68f1eee06 (diff) | |
| download | rust-ec45b87957c4158934fc3f5a821594ad0686ea4e.tar.gz rust-ec45b87957c4158934fc3f5a821594ad0686ea4e.zip | |
resolve: Block expansion of a derive container until all its derives are resolved
Also mark derive helpers as known as a part of the derive container's expansion instead of expansion of the derives themselves which may happen too late.
Diffstat (limited to 'src/libsyntax/ext/base.rs')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a63c4181d5e..f0397558a1d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -11,6 +11,7 @@ use crate::ptr::P; use crate::symbol::{kw, sym, Ident, Symbol}; use crate::{ThinVec, MACRO_ARGUMENTS}; use crate::tokenstream::{self, TokenStream, TokenTree}; +use crate::visit::Visitor; use errors::{DiagnosticBuilder, DiagnosticId}; use smallvec::{smallvec, SmallVec}; @@ -72,6 +73,17 @@ impl Annotatable { } } + pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) { + match self { + Annotatable::Item(item) => visitor.visit_item(item), + Annotatable::TraitItem(trait_item) => visitor.visit_trait_item(trait_item), + Annotatable::ImplItem(impl_item) => visitor.visit_impl_item(impl_item), + Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item), + Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt), + Annotatable::Expr(expr) => visitor.visit_expr(expr), + } + } + pub fn expect_item(self) -> P<ast::Item> { match self { Annotatable::Item(i) => i, @@ -637,6 +649,12 @@ impl SyntaxExtension { pub type NamedSyntaxExtension = (Name, SyntaxExtension); +/// Result of resolving a macro invocation. +pub enum InvocationRes { + Single(Lrc<SyntaxExtension>), + DeriveContainer(Vec<Lrc<SyntaxExtension>>), +} + /// Error type that denotes indeterminacy. pub struct Indeterminate; @@ -664,7 +682,7 @@ pub trait Resolver { fn resolve_macro_invocation( &mut self, invoc: &Invocation, eager_expansion_root: ExpnId, force: bool - ) -> Result<Option<Lrc<SyntaxExtension>>, Indeterminate>; + ) -> Result<InvocationRes, Indeterminate>; fn check_unused_macros(&self); |
