Skip to content

Commit

Permalink
Use BTreeMap for deterministic iter order
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Aug 19, 2019
1 parent cc6dbb4 commit 3620456
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,12 +1693,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
&'a &'tcx ty::GenericPredicates<'tcx>) {
fn clean(&self, cx: &DocContext<'_>) -> Generics {
use self::WherePredicate as WP;
use std::collections::BTreeMap;

let (gens, preds) = *self;

// Don't populate `cx.impl_trait_bounds` before `clean`ning `where` clauses,
// since `Clean for ty::Predicate` would consume them.
let mut impl_trait = FxHashMap::<ImplTraitParam, Vec<GenericBound>>::default();
let mut impl_trait = BTreeMap::<ImplTraitParam, Vec<GenericBound>>::default();

// Bounds in the type_params and lifetimes fields are repeated in the
// predicates field (see rustc_typeck::collect::ty_generics), so remove
Expand Down Expand Up @@ -1777,16 +1778,14 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
})
.collect::<Vec<_>>();

// Move `TraitPredicate`s to the front.
for (_, bounds) in impl_trait.iter_mut() {
for (param, mut bounds) in impl_trait {
// Move trait bounds to the front.
bounds.sort_by_key(|b| if let GenericBound::TraitBound(..) = b {
false
} else {
true
});
}

for (param, mut bounds) in impl_trait {
if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt

/// `DefId` or parameter index (`ty::ParamTy.index`) of a synthetic type parameter
/// for `impl Trait` in argument position.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum ImplTraitParam {
DefId(DefId),
ParamIndex(u32),
Expand Down

0 comments on commit 3620456

Please sign in to comment.