diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-08-15 03:51:12 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-08-20 23:12:36 +0300 |
| commit | 23e9a1def59ae7cc852181e9395cb467ffdbd46e (patch) | |
| tree | 87be37e28078bf2cb6cff64eaacdfd230836fa4a /src/libsyntax | |
| parent | 3a44ee68fbfa9cf436d5a1afe96427c29d2d94b9 (diff) | |
| download | rust-23e9a1def59ae7cc852181e9395cb467ffdbd46e.tar.gz rust-23e9a1def59ae7cc852181e9395cb467ffdbd46e.zip | |
resolve: Consolidate error reporting for resolved macros in `fn resolve_macro_to_def`
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 b12b2c49caa..66be1b0ae75 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(), |
