Skip to content

Commit 60a1d4e

Browse files
committed
resolve: Keep more precise traces for expanded macro resolutions
`NameBinding`s instead of `Def`s
1 parent 050bd32 commit 60a1d4e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ pub struct ModuleData<'a> {
10141014
normal_ancestor_id: DefId,
10151015

10161016
resolutions: RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>,
1017-
legacy_macro_resolutions: RefCell<Vec<(Ident, MacroKind, ParentScope<'a>, Option<Def>)>>,
1017+
legacy_macro_resolutions: RefCell<Vec<(Ident, MacroKind, ParentScope<'a>,
1018+
Option<&'a NameBinding<'a>>)>>,
10181019
macro_resolutions: RefCell<Vec<(Box<[Ident]>, Span)>>,
10191020
builtin_attrs: RefCell<Vec<(Ident, ParentScope<'a>)>>,
10201021

src/librustc_resolve/macros.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
506506

507507
def
508508
} else {
509-
let def = match self.early_resolve_ident_in_lexical_scope(path[0], MacroNS, Some(kind),
510-
parent_scope, false, force,
511-
span) {
512-
Ok(binding) => Ok(binding.def_ignoring_ambiguity()),
509+
let binding = self.early_resolve_ident_in_lexical_scope(
510+
path[0], MacroNS, Some(kind), parent_scope, false, force, span
511+
);
512+
match binding {
513+
Ok(..) => {}
514+
Err(Determinacy::Determined) => self.found_unresolved_macro = true,
513515
Err(Determinacy::Undetermined) => return Err(Determinacy::Undetermined),
514-
Err(Determinacy::Determined) => {
515-
self.found_unresolved_macro = true;
516-
Err(Determinacy::Determined)
517-
}
518-
};
516+
}
519517

520518
parent_scope.module.legacy_macro_resolutions.borrow_mut()
521-
.push((path[0], kind, parent_scope.clone(), def.ok()));
519+
.push((path[0], kind, parent_scope.clone(), binding.ok()));
522520

523-
def
521+
binding.map(|binding| binding.def_ignoring_ambiguity())
524522
}
525523
}
526524

@@ -866,15 +864,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
866864

867865
let legacy_macro_resolutions =
868866
mem::replace(&mut *module.legacy_macro_resolutions.borrow_mut(), Vec::new());
869-
for (ident, kind, parent_scope, initial_def) in legacy_macro_resolutions {
867+
for (ident, kind, parent_scope, initial_binding) in legacy_macro_resolutions {
870868
let binding = self.early_resolve_ident_in_lexical_scope(
871869
ident, MacroNS, Some(kind), &parent_scope, true, true, ident.span
872870
);
873871
match binding {
874872
Ok(binding) => {
875-
self.record_use(ident, MacroNS, binding);
876873
let def = binding.def_ignoring_ambiguity();
877-
if let Some(initial_def) = initial_def {
874+
if let Some(initial_binding) = initial_binding {
875+
self.record_use(ident, MacroNS, initial_binding);
876+
let initial_def = initial_binding.def_ignoring_ambiguity();
878877
if self.ambiguity_errors.is_empty() &&
879878
def != initial_def && def != Def::Err {
880879
// Make sure compilation does not succeed if preferred macro resolution
@@ -894,7 +893,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
894893
}
895894
}
896895
Err(..) => {
897-
assert!(initial_def.is_none());
896+
assert!(initial_binding.is_none());
898897
let bang = if kind == MacroKind::Bang { "!" } else { "" };
899898
let msg =
900899
format!("cannot find {} `{}{}` in this scope", kind.descr(), ident, bang);

0 commit comments

Comments
 (0)