]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #65043 - Aaron1011:fix/reexport-determinism, r=petrochenkov
authorbors <bors@rust-lang.org>
Sun, 6 Oct 2019 08:40:43 +0000 (08:40 +0000)
committerbors <bors@rust-lang.org>
Sun, 6 Oct 2019 08:40:43 +0000 (08:40 +0000)
Make re-export collection deterministic

Fixes https://github.com/rust-lang/rust/issues/65036

Previously, we were using an `FxHashMap` to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR #64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See #65042 for a long-term strategy to detect this kind of issue

1  2 
src/librustc_resolve/lib.rs

index 68d3bb00abc00d3125df312de431e0ca1c6ecd12,eaa4850f65c0ab5409e981142a1cf1e69c2ac42e..cc75961e6b1afdc215f98d9659abc544b9137138
@@@ -9,6 -9,7 +9,6 @@@
  
  #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
  
 -#![feature(inner_deref)]
  #![feature(crate_visibility_modifier)]
  #![feature(label_break_value)]
  #![feature(mem_take)]
@@@ -57,6 -58,7 +57,7 @@@ use std::{cmp, fmt, iter, ptr}
  use std::collections::BTreeSet;
  use rustc_data_structures::ptr_key::PtrKey;
  use rustc_data_structures::sync::Lrc;
+ use rustc_data_structures::fx::FxIndexMap;
  
  use diagnostics::{Suggestion, ImportSuggestion};
  use diagnostics::{find_span_of_binding_until_next_binding, extend_span_to_previous_binding};
@@@ -430,7 -432,7 +431,7 @@@ impl ModuleKind 
      }
  }
  
- type Resolutions<'a> = RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>;
+ type Resolutions<'a> = RefCell<FxIndexMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>;
  
  /// One node in the tree of modules.
  pub struct ModuleData<'a> {
@@@ -495,17 -497,6 +496,6 @@@ impl<'a> ModuleData<'a> 
          }
      }
  
-     fn for_each_child_stable<R, F>(&'a self, resolver: &mut R, mut f: F)
-         where R: AsMut<Resolver<'a>>, F: FnMut(&mut R, Ident, Namespace, &'a NameBinding<'a>)
-     {
-         let resolutions = resolver.as_mut().resolutions(self).borrow();
-         let mut resolutions = resolutions.iter().collect::<Vec<_>>();
-         resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.as_str(), ns));
-         for &(&(ident, ns), &resolution) in resolutions.iter() {
-             resolution.borrow().binding.map(|binding| f(resolver, ident, ns, binding));
-         }
-     }
      fn res(&self) -> Option<Res> {
          match self.kind {
              ModuleKind::Def(kind, def_id, _) => Some(Res::Def(kind, def_id)),