expand/resolve: Turn #[derive] into a regular macro attribute
This commit is contained in:
@@ -141,7 +141,7 @@ impl Annotatable {
|
||||
}
|
||||
|
||||
crate fn into_tokens(self, sess: &ParseSess) -> TokenStream {
|
||||
nt_to_tokenstream(&self.into_nonterminal(), sess, CanSynthesizeMissingTokens::No)
|
||||
nt_to_tokenstream(&self.into_nonterminal(), sess, CanSynthesizeMissingTokens::Yes)
|
||||
}
|
||||
|
||||
pub fn expect_item(self) -> P<ast::Item> {
|
||||
@@ -234,25 +234,6 @@ impl Annotatable {
|
||||
_ => panic!("expected variant"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn derive_allowed(&self) -> bool {
|
||||
match *self {
|
||||
Annotatable::Stmt(ref stmt) => match stmt.kind {
|
||||
ast::StmtKind::Item(ref item) => matches!(
|
||||
item.kind,
|
||||
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
|
||||
),
|
||||
_ => false,
|
||||
},
|
||||
Annotatable::Item(ref item) => match item.kind {
|
||||
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..) => {
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of an expansion that may need to be retried.
|
||||
@@ -854,12 +835,6 @@ impl 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;
|
||||
|
||||
@@ -885,16 +860,29 @@ pub trait ResolverExpand {
|
||||
invoc: &Invocation,
|
||||
eager_expansion_root: ExpnId,
|
||||
force: bool,
|
||||
) -> Result<InvocationRes, Indeterminate>;
|
||||
) -> Result<Lrc<SyntaxExtension>, Indeterminate>;
|
||||
|
||||
fn check_unused_macros(&mut self);
|
||||
|
||||
/// Some parent node that is close enough to the given macro call.
|
||||
fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId;
|
||||
fn lint_node_id(&self, expn_id: ExpnId) -> NodeId;
|
||||
|
||||
// Resolver interfaces for specific built-in macros.
|
||||
/// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it?
|
||||
fn has_derive_copy(&self, expn_id: ExpnId) -> bool;
|
||||
/// Resolve paths inside the `#[derive(...)]` attribute with the given `ExpnId`.
|
||||
fn resolve_derives(
|
||||
&mut self,
|
||||
expn_id: ExpnId,
|
||||
derives: Vec<ast::Path>,
|
||||
force: bool,
|
||||
) -> Result<(), Indeterminate>;
|
||||
/// Take resolutions for paths inside the `#[derive(...)]` attribute with the given `ExpnId`
|
||||
/// back from resolver.
|
||||
fn take_derive_resolutions(
|
||||
&mut self,
|
||||
expn_id: ExpnId,
|
||||
) -> Option<Vec<(Lrc<SyntaxExtension>, ast::Path)>>;
|
||||
/// Path resolution logic for `#[cfg_accessible(path)]`.
|
||||
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user