]> git.lizzy.rs Git - rust.git/commitdiff
expand: Get rid of `resolve_macro_path`
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 28 Jun 2019 23:30:53 +0000 (02:30 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 10 Jul 2019 21:12:07 +0000 (00:12 +0300)
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.

src/librustc_resolve/macros.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/expand.rs

index a3e00bcb81a9f555fc76cda1b14881f6cb5da210..61300e3ee3cee21b7fb29f06ade81f0db9c2a67b 100644 (file)
@@ -242,13 +242,6 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force
         Ok(Some(ext))
     }
 
-    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> {
-        let parent_scope = self.invoc_parent_scope(invoc_id, derives_in_scope);
-        Ok(self.resolve_macro_to_res(path, kind, &parent_scope, false, force)?.1)
-    }
-
     fn check_unused_macros(&self) {
         for (&node_id, &span) in self.unused_macros.iter() {
             self.session.buffer_lint(
index 0c986574cece4c7721df544d4cdf814f503d9c7c..267046655ffdc4a2301eca844bc5790f13f5ddda 100644 (file)
@@ -680,9 +680,6 @@ fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFra
 
     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);
 }
index 879069c1418e47e5465597f86963f90c632208a9..bb7d7352e055af821e7fedac52620e641e6a1e86 100644 (file)
@@ -208,6 +208,7 @@ pub enum InvocationKind {
     Derive {
         path: Path,
         item: Annotatable,
+        item_with_markers: Annotatable,
     },
 }
 
@@ -362,19 +363,15 @@ fn expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
 
                     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 @@ fn expand_derive_invoc(&mut self,
                            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() {