Rollup merge of #37198 - jseyfried:future_proof_macros_11, r=nrc

macros 1.1: future proofing and cleanup

This PR
 - uses the macro namespace for custom derives (instead of a dedicated custom derive namespace),
 - relaxes the shadowing rules for `#[macro_use]`-imported custom derives to match the shadowing rules for ordinary `#[macro_use]`-imported macros, and
 - treats custom derive `extern crate`s like empty modules so that we can eventually allow, for example, `extern crate serde_derive; use serde_derive::Serialize;` backwards compatibly.

r? @alexcrichton
This commit is contained in:
Eduard-Mihai Burtescu
2016-10-19 08:00:00 +03:00
committed by GitHub
10 changed files with 92 additions and 95 deletions

View File

@@ -15,7 +15,7 @@ use attr::HasAttrs;
use codemap::{self, CodeMap, ExpnInfo, Spanned, respan};
use syntax_pos::{Span, ExpnId, NO_EXPANSION};
use errors::DiagnosticBuilder;
use ext::expand::{self, Invocation, Expansion};
use ext::expand::{self, Expansion};
use ext::hygiene::Mark;
use fold::{self, Folder};
use parse::{self, parser};
@@ -508,6 +508,8 @@ pub enum SyntaxExtension {
/// the block.
///
IdentTT(Box<IdentMacroExpander>, Option<Span>, bool),
CustomDerive(Box<MultiItemModifier>),
}
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
@@ -522,9 +524,8 @@ pub trait Resolver {
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>);
fn find_attr_invoc(&mut self, attrs: &mut Vec<Attribute>) -> Option<Attribute>;
fn resolve_invoc(&mut self, scope: Mark, invoc: &Invocation, force: bool)
fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, force: bool)
-> Result<Rc<SyntaxExtension>, Determinacy>;
fn resolve_derive_mode(&mut self, ident: ast::Ident) -> Option<Rc<MultiItemModifier>>;
}
#[derive(Copy, Clone, Debug)]
@@ -545,8 +546,7 @@ impl Resolver for DummyResolver {
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
fn find_attr_invoc(&mut self, _attrs: &mut Vec<Attribute>) -> Option<Attribute> { None }
fn resolve_derive_mode(&mut self, _ident: ast::Ident) -> Option<Rc<MultiItemModifier>> { None }
fn resolve_invoc(&mut self, _scope: Mark, _invoc: &Invocation, _force: bool)
fn resolve_macro(&mut self, _scope: Mark, _path: &ast::Path, _force: bool)
-> Result<Rc<SyntaxExtension>, Determinacy> {
Err(Determinacy::Determined)
}