From 60a1d4e6c2b23eeed79ea7ca2cbc43713d10197e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 19 Sep 2018 01:01:09 +0300 Subject: resolve: Keep more precise traces for expanded macro resolutions `NameBinding`s instead of `Def`s --- src/librustc_resolve/lib.rs | 3 ++- src/librustc_resolve/macros.rs | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b41e9625e4e..a93cc7ad751 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1014,7 +1014,8 @@ pub struct ModuleData<'a> { normal_ancestor_id: DefId, resolutions: RefCell>>>, - legacy_macro_resolutions: RefCell, Option)>>, + legacy_macro_resolutions: RefCell, + Option<&'a NameBinding<'a>>)>>, macro_resolutions: RefCell, Span)>>, builtin_attrs: RefCell)>>, diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 6c067c669cb..e0ef286a43e 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -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()) } } @@ -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 @@ -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); -- cgit 1.4.1-3-g733a5