pub fn find_transparency(
attrs: &[Attribute],
- is_legacy: bool,
+ macro_rules: bool,
) -> (Transparency, Option<TransparencyError>) {
let mut transparency = None;
let mut error = None;
}
}
}
- 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)
}
| (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(
/// 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
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;
&& 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)?; // `!`
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 {
}
}
- fn legacy_import_macro(
+ fn add_macro_use_binding(
&mut self,
name: ast::Name,
binding: &'a NameBinding<'a>,
}
/// 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 {
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 {
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,
Import,
BuiltinAttr,
DeriveHelper,
- LegacyVsModern,
+ MacroRulesVsModularized,
GlobVsOuter,
GlobVsGlob,
GlobVsExpanded,
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"
}
// 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
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.
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);
}
}
- 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,
}
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