Skip to content

Commit 8c9a38f

Browse files
committed
Other legacy -> macro_rules
1 parent 3fbb254 commit 8c9a38f

File tree

6 files changed

+35
-31
lines changed

6 files changed

+35
-31
lines changed

src/librustc_attr/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub enum TransparencyError {
10241024

10251025
pub fn find_transparency(
10261026
attrs: &[Attribute],
1027-
is_legacy: bool,
1027+
macro_rules: bool,
10281028
) -> (Transparency, Option<TransparencyError>) {
10291029
let mut transparency = None;
10301030
let mut error = None;
@@ -1049,7 +1049,7 @@ pub fn find_transparency(
10491049
}
10501050
}
10511051
}
1052-
let fallback = if is_legacy { Transparency::SemiTransparent } else { Transparency::Opaque };
1052+
let fallback = if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque };
10531053
(transparency.map_or(fallback, |t| t.0), error)
10541054
}
10551055

src/librustc_expand/mbe/macro_check.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ fn check_nested_occurrences(
419419
| (NestedMacroState::MacroName, &TokenTree::Delimited(_, ref del))
420420
if del.delim == DelimToken::Brace =>
421421
{
422-
let legacy = state == NestedMacroState::MacroRulesNotName;
422+
let macro_rules = state == NestedMacroState::MacroRulesNotName;
423423
state = NestedMacroState::Empty;
424424
let rest =
425-
check_nested_macro(sess, node_id, legacy, &del.tts, &nested_macros, valid);
425+
check_nested_macro(sess, node_id, macro_rules, &del.tts, &nested_macros, valid);
426426
// If we did not check the whole macro definition, then check the rest as if outside
427427
// the macro definition.
428428
check_nested_occurrences(
@@ -493,21 +493,21 @@ fn check_nested_occurrences(
493493
/// Arguments:
494494
/// - `sess` is used to emit diagnostics and lints
495495
/// - `node_id` is used to emit lints
496-
/// - `legacy` specifies whether the macro is legacy
496+
/// - `macro_rules` specifies whether the macro is `macro_rules`
497497
/// - `tts` is checked as a list of (LHS) => {RHS}
498498
/// - `macros` is the stack of outer macros
499499
/// - `valid` is set in case of errors
500500
fn check_nested_macro(
501501
sess: &ParseSess,
502502
node_id: NodeId,
503-
legacy: bool,
503+
macro_rules: bool,
504504
tts: &[TokenTree],
505505
macros: &Stack<'_, MacroState<'_>>,
506506
valid: &mut bool,
507507
) -> usize {
508508
let n = tts.len();
509509
let mut i = 0;
510-
let separator = if legacy { TokenKind::Semi } else { TokenKind::Comma };
510+
let separator = if macro_rules { TokenKind::Semi } else { TokenKind::Comma };
511511
loop {
512512
// We expect 3 token trees: `(LHS) => {RHS}`. The separator is checked after.
513513
if i + 2 >= n
@@ -522,7 +522,7 @@ fn check_nested_macro(
522522
let mut binders = Binders::default();
523523
check_binders(sess, node_id, lhs, macros, &mut binders, &Stack::Empty, valid);
524524
check_occurrences(sess, node_id, rhs, macros, &binders, &Stack::Empty, valid);
525-
// Since the last semicolon is optional for legacy macros and decl_macro are not terminated,
525+
// Since the last semicolon is optional for `macro_rules` macros and decl_macro are not terminated,
526526
// we increment our checked position by how many token trees we already checked (the 3
527527
// above) before checking for the separator.
528528
i += 3;

src/librustc_parse/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ impl<'a> Parser<'a> {
12701270
&& self.look_ahead(2, |t| t.is_ident())
12711271
}
12721272

1273-
/// Parses a legacy `macro_rules! foo { ... }` declarative macro.
1273+
/// Parses a `macro_rules! foo { ... }` declarative macro.
12741274
fn parse_item_macro_rules(&mut self, vis: &Visibility) -> PResult<'a, ItemInfo> {
12751275
self.expect_keyword(kw::MacroRules)?; // `macro_rules`
12761276
self.expect(&token::Not)?; // `!`

src/librustc_resolve/build_reduced_graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
624624
self.r.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
625625
};
626626

627-
let used = self.process_legacy_macro_imports(item, module);
627+
let used = self.process_macro_use_imports(item, module);
628628
let binding =
629629
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
630630
let import = self.r.arenas.alloc_import(Import {
@@ -913,7 +913,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
913913
}
914914
}
915915

916-
fn legacy_import_macro(
916+
fn add_macro_use_binding(
917917
&mut self,
918918
name: ast::Name,
919919
binding: &'a NameBinding<'a>,
@@ -929,7 +929,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
929929
}
930930

931931
/// Returns `true` if we should consider the underlying `extern crate` to be used.
932-
fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
932+
fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
933933
let mut import_all = None;
934934
let mut single_imports = Vec::new();
935935
for attr in &item.attrs {
@@ -1004,7 +1004,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10041004
module.for_each_child(self, |this, ident, ns, binding| {
10051005
if ns == MacroNS {
10061006
let imported_binding = this.r.import(binding, import);
1007-
this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
1007+
this.add_macro_use_binding(ident.name, imported_binding, span, allow_shadowing);
10081008
}
10091009
});
10101010
} else {
@@ -1021,7 +1021,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10211021
let import = macro_use_import(self, ident.span);
10221022
self.r.potentially_unused_imports.push(import);
10231023
let imported_binding = self.r.import(binding, import);
1024-
self.legacy_import_macro(
1024+
self.add_macro_use_binding(
10251025
ident.name,
10261026
imported_binding,
10271027
ident.span,

src/librustc_resolve/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ enum AmbiguityKind {
618618
Import,
619619
BuiltinAttr,
620620
DeriveHelper,
621-
LegacyVsModern,
621+
MacroRulesVsModularized,
622622
GlobVsOuter,
623623
GlobVsGlob,
624624
GlobVsExpanded,
@@ -631,7 +631,9 @@ impl AmbiguityKind {
631631
AmbiguityKind::Import => "name vs any other name during import resolution",
632632
AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
633633
AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
634-
AmbiguityKind::LegacyVsModern => "`macro_rules` vs non-`macro_rules` from other module",
634+
AmbiguityKind::MacroRulesVsModularized => {
635+
"`macro_rules` vs non-`macro_rules` from other module"
636+
}
635637
AmbiguityKind::GlobVsOuter => {
636638
"glob import vs any other name from outer scope during import/macro resolution"
637639
}
@@ -1473,7 +1475,7 @@ impl<'a> Resolver<'a> {
14731475
// derives (you need to resolve the derive first to add helpers into scope), but they
14741476
// should be available before the derive is expanded for compatibility.
14751477
// It's mess in general, so we are being conservative for now.
1476-
// 1-3. `macro_rules` (open, not controlled), loop through legacy scopes. Have higher
1478+
// 1-3. `macro_rules` (open, not controlled), loop through `macro_rules` scopes. Have higher
14771479
// priority than prelude macros, but create ambiguities with macros in modules.
14781480
// 1-3. Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
14791481
// (open, not controlled). Have higher priority than prelude macros, but create
@@ -1639,7 +1641,7 @@ impl<'a> Resolver<'a> {
16391641
for i in (0..ribs.len()).rev() {
16401642
debug!("walk rib\n{:?}", ribs[i].bindings);
16411643
// Use the rib kind to determine whether we are resolving parameters
1642-
// (modern hygiene) or local variables (legacy hygiene).
1644+
// (modern hygiene) or local variables (`macro_rules` hygiene).
16431645
let rib_ident = if ribs[i].kind.contains_params() { modern_ident } else { ident };
16441646
if let Some(res) = ribs[i].bindings.get(&rib_ident).cloned() {
16451647
// The ident resolves to a type parameter or local variable.
@@ -1898,7 +1900,7 @@ impl<'a> Resolver<'a> {
18981900
break;
18991901
}
19001902
}
1901-
// Then find the last legacy mark from the end if it exists.
1903+
// Then find the last semi-transparent mark from the end if it exists.
19021904
for (mark, transparency) in iter {
19031905
if transparency == Transparency::SemiTransparent {
19041906
result = Some(mark);
@@ -2423,21 +2425,21 @@ impl<'a> Resolver<'a> {
24232425
}
24242426
}
24252427

2426-
fn disambiguate_legacy_vs_modern(
2428+
fn disambiguate_macro_rules_vs_modularized(
24272429
&self,
2428-
legacy: &'a NameBinding<'a>,
2429-
modern: &'a NameBinding<'a>,
2430+
macro_rules: &'a NameBinding<'a>,
2431+
modularized: &'a NameBinding<'a>,
24302432
) -> bool {
24312433
// Some non-controversial subset of ambiguities "modern macro name" vs "macro_rules"
24322434
// is disambiguated to mitigate regressions from macro modularization.
24332435
// Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
24342436
match (
2435-
self.binding_parent_modules.get(&PtrKey(legacy)),
2436-
self.binding_parent_modules.get(&PtrKey(modern)),
2437+
self.binding_parent_modules.get(&PtrKey(macro_rules)),
2438+
self.binding_parent_modules.get(&PtrKey(modularized)),
24372439
) {
2438-
(Some(legacy), Some(modern)) => {
2439-
legacy.normal_ancestor_id == modern.normal_ancestor_id
2440-
&& modern.is_ancestor_of(legacy)
2440+
(Some(macro_rules), Some(modularized)) => {
2441+
macro_rules.normal_ancestor_id == modularized.normal_ancestor_id
2442+
&& modularized.is_ancestor_of(macro_rules)
24412443
}
24422444
_ => false,
24432445
}

src/librustc_resolve/macros.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -761,16 +761,18 @@ impl<'a> Resolver<'a> {
761761
Some(AmbiguityKind::DeriveHelper)
762762
} else if innermost_flags.contains(Flags::MACRO_RULES)
763763
&& flags.contains(Flags::MODULE)
764-
&& !this
765-
.disambiguate_legacy_vs_modern(innermost_binding, binding)
764+
&& !this.disambiguate_macro_rules_vs_modularized(
765+
innermost_binding,
766+
binding,
767+
)
766768
|| flags.contains(Flags::MACRO_RULES)
767769
&& innermost_flags.contains(Flags::MODULE)
768-
&& !this.disambiguate_legacy_vs_modern(
770+
&& !this.disambiguate_macro_rules_vs_modularized(
769771
binding,
770772
innermost_binding,
771773
)
772774
{
773-
Some(AmbiguityKind::LegacyVsModern)
775+
Some(AmbiguityKind::MacroRulesVsModularized)
774776
} else if innermost_binding.is_glob_import() {
775777
Some(AmbiguityKind::GlobVsOuter)
776778
} else if innermost_binding

0 commit comments

Comments
 (0)