diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-29 02:30:53 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-07-11 00:12:07 +0300 |
| commit | a138e9d625bf83c45d3835b12d7689b730dc4e9a (patch) | |
| tree | 408540b0a11f8f3f63e86892b9d40e31aa393b3b /src/libsyntax | |
| parent | 62a1f5dbc0bbcf875b21dce643ae8b2ae971c74e (diff) | |
| download | rust-a138e9d625bf83c45d3835b12d7689b730dc4e9a.tar.gz rust-a138e9d625bf83c45d3835b12d7689b730dc4e9a.zip | |
expand: Get rid of `resolve_macro_path`
It was used to choose whether to apply derive markers like `#[rustc_copy_clone_marker]` or not, but it was called before all the data required for resolution is available, so it could work incorrectly in some corner cases (like user-defined derives name `Copy` or `Eq`). Delay the decision about markers until the proper resolution results are available instead.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 22 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 0c986574cec..267046655ff 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -680,9 +680,6 @@ pub trait Resolver { fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool) -> Result<Option<Lrc<SyntaxExtension>>, Determinacy>; - fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, invoc_id: Mark, - derives_in_scope: Vec<ast::Path>, force: bool) - -> Result<Lrc<SyntaxExtension>, Determinacy>; fn check_unused_macros(&self); } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 879069c1418..bb7d7352e05 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -208,6 +208,7 @@ pub enum InvocationKind { Derive { path: Path, item: Annotatable, + item_with_markers: Annotatable, }, } @@ -362,19 +363,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> { derives.reserve(traits.len()); invocations.reserve(traits.len()); - for path in &traits { + for path in traits { let mark = Mark::fresh(self.cx.current_expansion.mark); derives.push(mark); - let item = match self.cx.resolver.resolve_macro_path( - path, MacroKind::Derive, Mark::root(), Vec::new(), false) { - Ok(ext) => match ext.kind { - SyntaxExtensionKind::LegacyDerive(..) => item_with_markers.clone(), - _ => item.clone(), - }, - _ => item.clone(), - }; invocations.push(Invocation { - kind: InvocationKind::Derive { path: path.clone(), item }, + kind: InvocationKind::Derive { + path, + item: item.clone(), + item_with_markers: item_with_markers.clone(), + }, fragment_kind: invoc.fragment_kind, expansion_data: ExpansionData { mark, @@ -737,7 +734,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> { ext: &SyntaxExtension) -> Option<AstFragment> { let (path, item) = match invoc.kind { - InvocationKind::Derive { path, item } => (path, item), + InvocationKind::Derive { path, item, item_with_markers } => match ext.kind { + SyntaxExtensionKind::LegacyDerive(..) => (path, item_with_markers), + _ => (path, item), + } _ => unreachable!(), }; if !item.derive_allowed() { |
