From 10a89400cf03770eec63dd007ff38ff0163216c9 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Fri, 4 Jan 2019 15:09:09 +0200 Subject: [PATCH] alphabetize marker traits when printed This makes sure they are printed in a compiler-version-independent order, avoiding ui test instability. --- src/librustc/util/ppaux.rs | 17 +++++++++++++++-- .../issues/issue-33140-traitobject-crate.stderr | 12 ++++++------ src/test/ui/issues/issue-33140.stderr | 8 ++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index b49852be38dd..c5601d442654 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -729,13 +729,26 @@ define_print! { } // Builtin bounds. - for did in self.auto_traits() { + let mut auto_traits: Vec<_> = self.auto_traits().map(|did| { + tcx.item_path_str(did) + }).collect(); + + // The auto traits come ordered by `DefPathHash`. While + // `DefPathHash` is *stable* in the sense that it depends on + // neither the host nor the phase of the moon, it depends + // "pseudorandomly" on the compiler version and the target. + // + // To avoid that causing instabilities in compiletest + // output, sort the auto-traits alphabetically. + auto_traits.sort(); + + for auto_trait in auto_traits { if !first { write!(f, " + ")?; } first = false; - write!(f, "{}", tcx.item_path_str(did))?; + write!(f, "{}", auto_trait)?; } Ok(()) diff --git a/src/test/ui/issues/issue-33140-traitobject-crate.stderr b/src/test/ui/issues/issue-33140-traitobject-crate.stderr index 28193b0eeb99..6f71e79d0ee7 100644 --- a/src/test/ui/issues/issue-33140-traitobject-crate.stderr +++ b/src/test/ui/issues/issue-33140-traitobject-crate.stderr @@ -1,10 +1,10 @@ -warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119) +warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119) --> $DIR/issue-33140-traitobject-crate.rs:85:1 | LL | unsafe impl Trait for ::std::marker::Send + Sync { } | ------------------------------------------------ first implementation here LL | unsafe impl Trait for ::std::marker::Send + Send + Sync { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` | note: lint level defined here --> $DIR/issue-33140-traitobject-crate.rs:3:9 @@ -14,25 +14,25 @@ LL | #![warn(order_dependent_trait_objects)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #56484 -warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119) +warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119) --> $DIR/issue-33140-traitobject-crate.rs:86:1 | LL | unsafe impl Trait for ::std::marker::Send + Send + Sync { } | ------------------------------------------------------- first implementation here LL | unsafe impl Trait for ::std::marker::Sync + Send { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #56484 -warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119) +warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119) --> $DIR/issue-33140-traitobject-crate.rs:88:1 | LL | unsafe impl Trait for ::std::marker::Sync + Send { } | ------------------------------------------------ first implementation here LL | unsafe impl Trait for ::std::marker::Sync + Sync { } LL | unsafe impl Trait for ::std::marker::Sync + Send + Sync { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #56484 diff --git a/src/test/ui/issues/issue-33140.stderr b/src/test/ui/issues/issue-33140.stderr index 6e63828f5f7f..e2631e971c51 100644 --- a/src/test/ui/issues/issue-33140.stderr +++ b/src/test/ui/issues/issue-33140.stderr @@ -1,20 +1,20 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: +error[E0119]: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: --> $DIR/issue-33140.rs:9:1 | LL | impl Trait for dyn Send + Sync { | ------------------------------ first implementation here ... LL | impl Trait for dyn Sync + Send { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` -error[E0119]: conflicting implementations of trait `Trait2` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: +error[E0119]: conflicting implementations of trait `Trait2` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: --> $DIR/issue-33140.rs:22:1 | LL | impl Trait2 for dyn Send + Sync { | ------------------------------- first implementation here ... LL | impl Trait2 for dyn Sync + Send + Sync { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` error[E0592]: duplicate definitions with name `abc` --> $DIR/issue-33140.rs:29:5