Skip to content

Commit

Permalink
resolve: Keep more precise traces for expanded macro resolutions
Browse files Browse the repository at this point in the history
`NameBinding`s instead of `Def`s
  • Loading branch information
petrochenkov committed Oct 5, 2018
1 parent 050bd32 commit 60a1d4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -1014,7 +1014,8 @@ pub struct ModuleData<'a> {
normal_ancestor_id: DefId,

resolutions: RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>,
legacy_macro_resolutions: RefCell<Vec<(Ident, MacroKind, ParentScope<'a>, Option<Def>)>>,
legacy_macro_resolutions: RefCell<Vec<(Ident, MacroKind, ParentScope<'a>,
Option<&'a NameBinding<'a>>)>>,
macro_resolutions: RefCell<Vec<(Box<[Ident]>, Span)>>,
builtin_attrs: RefCell<Vec<(Ident, ParentScope<'a>)>>,

Expand Down
29 changes: 14 additions & 15 deletions src/librustc_resolve/macros.rs
Expand Up @@ -506,21 +506,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {

def
} else {
let def = match self.early_resolve_ident_in_lexical_scope(path[0], MacroNS, Some(kind),
parent_scope, false, force,
span) {
Ok(binding) => Ok(binding.def_ignoring_ambiguity()),
let binding = self.early_resolve_ident_in_lexical_scope(
path[0], MacroNS, Some(kind), parent_scope, false, force, span
);
match binding {
Ok(..) => {}
Err(Determinacy::Determined) => self.found_unresolved_macro = true,
Err(Determinacy::Undetermined) => return Err(Determinacy::Undetermined),
Err(Determinacy::Determined) => {
self.found_unresolved_macro = true;
Err(Determinacy::Determined)
}
};
}

parent_scope.module.legacy_macro_resolutions.borrow_mut()
.push((path[0], kind, parent_scope.clone(), def.ok()));
.push((path[0], kind, parent_scope.clone(), binding.ok()));

def
binding.map(|binding| binding.def_ignoring_ambiguity())
}
}

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

let legacy_macro_resolutions =
mem::replace(&mut *module.legacy_macro_resolutions.borrow_mut(), Vec::new());
for (ident, kind, parent_scope, initial_def) in legacy_macro_resolutions {
for (ident, kind, parent_scope, initial_binding) in legacy_macro_resolutions {
let binding = self.early_resolve_ident_in_lexical_scope(
ident, MacroNS, Some(kind), &parent_scope, true, true, ident.span
);
match binding {
Ok(binding) => {
self.record_use(ident, MacroNS, binding);
let def = binding.def_ignoring_ambiguity();
if let Some(initial_def) = initial_def {
if let Some(initial_binding) = initial_binding {
self.record_use(ident, MacroNS, initial_binding);
let initial_def = initial_binding.def_ignoring_ambiguity();
if self.ambiguity_errors.is_empty() &&
def != initial_def && def != Def::Err {
// Make sure compilation does not succeed if preferred macro resolution
Expand All @@ -894,7 +893,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
}
Err(..) => {
assert!(initial_def.is_none());
assert!(initial_binding.is_none());
let bang = if kind == MacroKind::Bang { "!" } else { "" };
let msg =
format!("cannot find {} `{}{}` in this scope", kind.descr(), ident, bang);
Expand Down

0 comments on commit 60a1d4e

Please sign in to comment.