diff options
| author | bors <bors@rust-lang.org> | 2018-08-21 20:33:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-21 20:33:31 +0000 |
| commit | d0d81b7fc1421859ba0218e8a437af29ae3b0967 (patch) | |
| tree | a9708466f9330e1ebc110f2e82a62905665de54b /src/libsyntax | |
| parent | 2d6d3acf4f6f405af1fcf178300a0728496de138 (diff) | |
| parent | 82619ea2bdb3e1107a1832a31aabcf1b3dd9126c (diff) | |
| download | rust-d0d81b7fc1421859ba0218e8a437af29ae3b0967.tar.gz rust-d0d81b7fc1421859ba0218e8a437af29ae3b0967.zip | |
Auto merge of #53471 - petrochenkov:biattr2, r=oli-obk
resolve: Some macro resolution refactoring Work towards completing https://github.com/rust-lang/rust/pull/50911#issuecomment-411605393 The last commit also fixes https://github.com/rust-lang/rust/issues/53269 by not using `def_id()` on `Def::Err` and also fixes https://github.com/rust-lang/rust/issues/53512.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 15 |
2 files changed, 14 insertions, 20 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 154fe11dd35..c9925b41498 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -727,10 +727,12 @@ pub trait Resolver { fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<Attribute>, allow_derive: bool) -> Option<Attribute>; - fn resolve_invoc(&mut self, invoc: &Invocation, scope: Mark, force: bool) - -> Result<Option<Lrc<SyntaxExtension>>, Determinacy>; - fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool) - -> Result<Lrc<SyntaxExtension>, Determinacy>; + fn resolve_macro_invocation(&mut self, invoc: &Invocation, scope: Mark, force: bool) + -> Result<Option<Lrc<SyntaxExtension>>, Determinacy>; + fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, scope: Mark, + derives_in_scope: &[ast::Path], force: bool) + -> Result<Lrc<SyntaxExtension>, Determinacy>; + fn check_unused_macros(&self); } @@ -761,12 +763,13 @@ impl Resolver for DummyResolver { fn resolve_imports(&mut self) {} fn find_legacy_attr_invoc(&mut self, _attrs: &mut Vec<Attribute>, _allow_derive: bool) -> Option<Attribute> { None } - fn resolve_invoc(&mut self, _invoc: &Invocation, _scope: Mark, _force: bool) - -> Result<Option<Lrc<SyntaxExtension>>, Determinacy> { + fn resolve_macro_invocation(&mut self, _invoc: &Invocation, _scope: Mark, _force: bool) + -> Result<Option<Lrc<SyntaxExtension>>, Determinacy> { Err(Determinacy::Determined) } - fn resolve_macro(&mut self, _scope: Mark, _path: &ast::Path, _kind: MacroKind, - _force: bool) -> Result<Lrc<SyntaxExtension>, Determinacy> { + fn resolve_macro_path(&mut self, _path: &ast::Path, _kind: MacroKind, _scope: Mark, + _derives_in_scope: &[ast::Path], _force: bool) + -> Result<Lrc<SyntaxExtension>, Determinacy> { Err(Determinacy::Determined) } fn check_unused_macros(&self) {} diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 06e4087171a..97279e00869 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -243,15 +243,6 @@ impl Invocation { InvocationKind::Derive { ref path, .. } => path.span, } } - - pub fn path(&self) -> Option<&Path> { - match self.kind { - InvocationKind::Bang { ref mac, .. } => Some(&mac.node.path), - InvocationKind::Attr { attr: Some(ref attr), .. } => Some(&attr.path), - InvocationKind::Attr { attr: None, .. } => None, - InvocationKind::Derive { ref path, .. } => Some(path), - } - } } pub struct MacroExpander<'a, 'b:'a> { @@ -343,7 +334,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let scope = if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark }; - let ext = match self.cx.resolver.resolve_invoc(&invoc, scope, force) { + let ext = match self.cx.resolver.resolve_macro_invocation(&invoc, scope, force) { Ok(ext) => Some(ext), Err(Determinacy::Determined) => None, Err(Determinacy::Undetermined) => { @@ -393,8 +384,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { for path in &traits { let mark = Mark::fresh(self.cx.current_expansion.mark); derives.push(mark); - let item = match self.cx.resolver.resolve_macro( - Mark::root(), path, MacroKind::Derive, false) { + let item = match self.cx.resolver.resolve_macro_path( + path, MacroKind::Derive, Mark::root(), &[], false) { Ok(ext) => match *ext { BuiltinDerive(..) => item_with_markers.clone(), _ => item.clone(), |
