mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Convert impossible cases in macro resolution into assertions
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
use rustc_ast::{self as ast, NodeId};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
|
||||
@@ -677,14 +677,21 @@ struct Flags: u8 {
|
||||
innermost_binding,
|
||||
binding,
|
||||
)
|
||||
|| flags.contains(Flags::MACRO_RULES)
|
||||
&& innermost_flags.contains(Flags::MODULE)
|
||||
&& !this.disambiguate_macro_rules_vs_modularized(
|
||||
binding,
|
||||
innermost_binding,
|
||||
)
|
||||
{
|
||||
Some(AmbiguityKind::MacroRulesVsModularized)
|
||||
} else if flags.contains(Flags::MACRO_RULES)
|
||||
&& innermost_flags.contains(Flags::MODULE)
|
||||
{
|
||||
// should be impossible because of visitation order in
|
||||
// visit_scopes
|
||||
//
|
||||
// we visit all macro_rules scopes (e.g. textual scope macros)
|
||||
// before we visit any modules (e.g. path-based scope macros)
|
||||
span_bug!(
|
||||
orig_ident.span,
|
||||
"ambiguous scoped macro resolutions with path-based \
|
||||
scope resolution as first candidate"
|
||||
)
|
||||
} else if innermost_binding.is_glob_import() {
|
||||
Some(AmbiguityKind::GlobVsOuter)
|
||||
} else if innermost_binding
|
||||
|
||||
@@ -2226,16 +2226,14 @@ fn disambiguate_macro_rules_vs_modularized(
|
||||
// Some non-controversial subset of ambiguities "modularized 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(¯o_rules),
|
||||
self.binding_parent_modules.get(&modularized),
|
||||
) {
|
||||
(Some(macro_rules), Some(modularized)) => {
|
||||
macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod()
|
||||
&& modularized.is_ancestor_of(*macro_rules)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
//
|
||||
// panic on index should be impossible, the only name_bindings passed in should be from
|
||||
// `resolve_ident_in_scope_set` which will always refer to a local binding from an
|
||||
// import or macro definition
|
||||
let macro_rules = &self.binding_parent_modules[¯o_rules];
|
||||
let modularized = &self.binding_parent_modules[&modularized];
|
||||
macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod()
|
||||
&& modularized.is_ancestor_of(*macro_rules)
|
||||
}
|
||||
|
||||
fn extern_prelude_get_item<'r>(
|
||||
|
||||
Reference in New Issue
Block a user