]> git.lizzy.rs Git - rust.git/commitdiff
Other `legacy` -> `macro_rules`
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 13 Mar 2020 22:23:24 +0000 (01:23 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 15 Mar 2020 21:29:42 +0000 (00:29 +0300)
src/librustc_attr/builtin.rs
src/librustc_expand/mbe/macro_check.rs
src/librustc_parse/parser/item.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/lib.rs
src/librustc_resolve/macros.rs

index 08eae24da9b688185fc36f1e224b4643ff33b77e..99083cca6cb3443a6424aff1eec92335172bc74e 100644 (file)
@@ -1024,7 +1024,7 @@ pub enum TransparencyError {
 
 pub fn find_transparency(
     attrs: &[Attribute],
-    is_legacy: bool,
+    macro_rules: bool,
 ) -> (Transparency, Option<TransparencyError>) {
     let mut transparency = None;
     let mut error = None;
@@ -1049,7 +1049,7 @@ pub fn find_transparency(
             }
         }
     }
-    let fallback = if is_legacy { Transparency::SemiTransparent } else { Transparency::Opaque };
+    let fallback = if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque };
     (transparency.map_or(fallback, |t| t.0), error)
 }
 
index 6eb834beac6522f77aa00950a6ae1b29561ac73a..8c6bfbec902775e8756ac8397c38577a387114d7 100644 (file)
@@ -419,10 +419,10 @@ fn check_nested_occurrences(
             | (NestedMacroState::MacroName, &TokenTree::Delimited(_, ref del))
                 if del.delim == DelimToken::Brace =>
             {
-                let legacy = state == NestedMacroState::MacroRulesNotName;
+                let macro_rules = state == NestedMacroState::MacroRulesNotName;
                 state = NestedMacroState::Empty;
                 let rest =
-                    check_nested_macro(sess, node_id, legacy, &del.tts, &nested_macros, valid);
+                    check_nested_macro(sess, node_id, macro_rules, &del.tts, &nested_macros, valid);
                 // If we did not check the whole macro definition, then check the rest as if outside
                 // the macro definition.
                 check_nested_occurrences(
@@ -493,21 +493,21 @@ fn check_nested_occurrences(
 /// Arguments:
 /// - `sess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
-/// - `legacy` specifies whether the macro is legacy
+/// - `macro_rules` specifies whether the macro is `macro_rules`
 /// - `tts` is checked as a list of (LHS) => {RHS}
 /// - `macros` is the stack of outer macros
 /// - `valid` is set in case of errors
 fn check_nested_macro(
     sess: &ParseSess,
     node_id: NodeId,
-    legacy: bool,
+    macro_rules: bool,
     tts: &[TokenTree],
     macros: &Stack<'_, MacroState<'_>>,
     valid: &mut bool,
 ) -> usize {
     let n = tts.len();
     let mut i = 0;
-    let separator = if legacy { TokenKind::Semi } else { TokenKind::Comma };
+    let separator = if macro_rules { TokenKind::Semi } else { TokenKind::Comma };
     loop {
         // We expect 3 token trees: `(LHS) => {RHS}`. The separator is checked after.
         if i + 2 >= n
@@ -522,7 +522,7 @@ fn check_nested_macro(
         let mut binders = Binders::default();
         check_binders(sess, node_id, lhs, macros, &mut binders, &Stack::Empty, valid);
         check_occurrences(sess, node_id, rhs, macros, &binders, &Stack::Empty, valid);
-        // Since the last semicolon is optional for legacy macros and decl_macro are not terminated,
+        // Since the last semicolon is optional for `macro_rules` macros and decl_macro are not terminated,
         // we increment our checked position by how many token trees we already checked (the 3
         // above) before checking for the separator.
         i += 3;
index cb4a98a6b4f46506b662e50dca56649f3387b2cc..e927bcd07e2cd2ed1a4465ff2207664cd910e32e 100644 (file)
@@ -1270,7 +1270,7 @@ fn is_macro_rules_item(&mut self) -> bool {
             && self.look_ahead(2, |t| t.is_ident())
     }
 
-    /// Parses a legacy `macro_rules! foo { ... }` declarative macro.
+    /// Parses a `macro_rules! foo { ... }` declarative macro.
     fn parse_item_macro_rules(&mut self, vis: &Visibility) -> PResult<'a, ItemInfo> {
         self.expect_keyword(kw::MacroRules)?; // `macro_rules`
         self.expect(&token::Not)?; // `!`
index 324669963f684541863f26ce4a9b2adb8a3d9885..f7bbba28c070e8b11f4005116851dbe40a50dc2f 100644 (file)
@@ -624,7 +624,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
                     self.r.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
                 };
 
-                let used = self.process_legacy_macro_imports(item, module);
+                let used = self.process_macro_use_imports(item, module);
                 let binding =
                     (module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
                 let import = self.r.arenas.alloc_import(Import {
@@ -913,7 +913,7 @@ fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<NodeId>)
         }
     }
 
-    fn legacy_import_macro(
+    fn add_macro_use_binding(
         &mut self,
         name: ast::Name,
         binding: &'a NameBinding<'a>,
@@ -929,7 +929,7 @@ fn legacy_import_macro(
     }
 
     /// Returns `true` if we should consider the underlying `extern crate` to be used.
-    fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
+    fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
         let mut import_all = None;
         let mut single_imports = Vec::new();
         for attr in &item.attrs {
@@ -1004,7 +1004,7 @@ fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>) -> b
             module.for_each_child(self, |this, ident, ns, binding| {
                 if ns == MacroNS {
                     let imported_binding = this.r.import(binding, import);
-                    this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
+                    this.add_macro_use_binding(ident.name, imported_binding, span, allow_shadowing);
                 }
             });
         } else {
@@ -1021,7 +1021,7 @@ fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>) -> b
                     let import = macro_use_import(self, ident.span);
                     self.r.potentially_unused_imports.push(import);
                     let imported_binding = self.r.import(binding, import);
-                    self.legacy_import_macro(
+                    self.add_macro_use_binding(
                         ident.name,
                         imported_binding,
                         ident.span,
index 0d02b8ea074eedc9a1ee8b4eca17774e1297de87..c4338710478366e80cf765b526248db884b11174 100644 (file)
@@ -618,7 +618,7 @@ enum AmbiguityKind {
     Import,
     BuiltinAttr,
     DeriveHelper,
-    LegacyVsModern,
+    MacroRulesVsModularized,
     GlobVsOuter,
     GlobVsGlob,
     GlobVsExpanded,
@@ -631,7 +631,9 @@ fn descr(self) -> &'static str {
             AmbiguityKind::Import => "name vs any other name during import resolution",
             AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
             AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
-            AmbiguityKind::LegacyVsModern => "`macro_rules` vs non-`macro_rules` from other module",
+            AmbiguityKind::MacroRulesVsModularized => {
+                "`macro_rules` vs non-`macro_rules` from other module"
+            }
             AmbiguityKind::GlobVsOuter => {
                 "glob import vs any other name from outer scope during import/macro resolution"
             }
@@ -1473,7 +1475,7 @@ fn visit_scopes<T>(
         //    derives (you need to resolve the derive first to add helpers into scope), but they
         //    should be available before the derive is expanded for compatibility.
         //    It's mess in general, so we are being conservative for now.
-        // 1-3. `macro_rules` (open, not controlled), loop through legacy scopes. Have higher
+        // 1-3. `macro_rules` (open, not controlled), loop through `macro_rules` scopes. Have higher
         //    priority than prelude macros, but create ambiguities with macros in modules.
         // 1-3. Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
         //    (open, not controlled). Have higher priority than prelude macros, but create
@@ -1639,7 +1641,7 @@ fn resolve_ident_in_lexical_scope(
         for i in (0..ribs.len()).rev() {
             debug!("walk rib\n{:?}", ribs[i].bindings);
             // Use the rib kind to determine whether we are resolving parameters
-            // (modern hygiene) or local variables (legacy hygiene).
+            // (modern hygiene) or local variables (`macro_rules` hygiene).
             let rib_ident = if ribs[i].kind.contains_params() { modern_ident } else { ident };
             if let Some(res) = ribs[i].bindings.get(&rib_ident).cloned() {
                 // The ident resolves to a type parameter or local variable.
@@ -1898,7 +1900,7 @@ fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
                     break;
                 }
             }
-            // Then find the last legacy mark from the end if it exists.
+            // Then find the last semi-transparent mark from the end if it exists.
             for (mark, transparency) in iter {
                 if transparency == Transparency::SemiTransparent {
                     result = Some(mark);
@@ -2423,21 +2425,21 @@ fn set_binding_parent_module(&mut self, binding: &'a NameBinding<'a>, module: Mo
         }
     }
 
-    fn disambiguate_legacy_vs_modern(
+    fn disambiguate_macro_rules_vs_modularized(
         &self,
-        legacy: &'a NameBinding<'a>,
-        modern: &'a NameBinding<'a>,
+        macro_rules: &'a NameBinding<'a>,
+        modularized: &'a NameBinding<'a>,
     ) -> bool {
         // Some non-controversial subset of ambiguities "modern macro name" vs "macro_rules"
         // is disambiguated to mitigate regressions from macro modularization.
         // Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
         match (
-            self.binding_parent_modules.get(&PtrKey(legacy)),
-            self.binding_parent_modules.get(&PtrKey(modern)),
+            self.binding_parent_modules.get(&PtrKey(macro_rules)),
+            self.binding_parent_modules.get(&PtrKey(modularized)),
         ) {
-            (Some(legacy), Some(modern)) => {
-                legacy.normal_ancestor_id == modern.normal_ancestor_id
-                    && modern.is_ancestor_of(legacy)
+            (Some(macro_rules), Some(modularized)) => {
+                macro_rules.normal_ancestor_id == modularized.normal_ancestor_id
+                    && modularized.is_ancestor_of(macro_rules)
             }
             _ => false,
         }
index d8ef148bacff2748694cb32f548b3318e1a5875a..f4dfa037dae4d551a2bd82b15186b19114d1b2fe 100644 (file)
@@ -761,16 +761,18 @@ struct Flags: u8 {
                                     Some(AmbiguityKind::DeriveHelper)
                                 } else if innermost_flags.contains(Flags::MACRO_RULES)
                                     && flags.contains(Flags::MODULE)
-                                    && !this
-                                        .disambiguate_legacy_vs_modern(innermost_binding, binding)
+                                    && !this.disambiguate_macro_rules_vs_modularized(
+                                        innermost_binding,
+                                        binding,
+                                    )
                                     || flags.contains(Flags::MACRO_RULES)
                                         && innermost_flags.contains(Flags::MODULE)
-                                        && !this.disambiguate_legacy_vs_modern(
+                                        && !this.disambiguate_macro_rules_vs_modularized(
                                             binding,
                                             innermost_binding,
                                         )
                                 {
-                                    Some(AmbiguityKind::LegacyVsModern)
+                                    Some(AmbiguityKind::MacroRulesVsModularized)
                                 } else if innermost_binding.is_glob_import() {
                                     Some(AmbiguityKind::GlobVsOuter)
                                 } else if innermost_binding