Skip to content

Commit 10a8940

Browse files
committed
alphabetize marker traits when printed
This makes sure they are printed in a compiler-version-independent order, avoiding ui test instability.
1 parent 0b511b7 commit 10a8940

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/librustc/util/ppaux.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,26 @@ define_print! {
729729
}
730730

731731
// Builtin bounds.
732-
for did in self.auto_traits() {
732+
let mut auto_traits: Vec<_> = self.auto_traits().map(|did| {
733+
tcx.item_path_str(did)
734+
}).collect();
735+
736+
// The auto traits come ordered by `DefPathHash`. While
737+
// `DefPathHash` is *stable* in the sense that it depends on
738+
// neither the host nor the phase of the moon, it depends
739+
// "pseudorandomly" on the compiler version and the target.
740+
//
741+
// To avoid that causing instabilities in compiletest
742+
// output, sort the auto-traits alphabetically.
743+
auto_traits.sort();
744+
745+
for auto_trait in auto_traits {
733746
if !first {
734747
write!(f, " + ")?;
735748
}
736749
first = false;
737750

738-
write!(f, "{}", tcx.item_path_str(did))?;
751+
write!(f, "{}", auto_trait)?;
739752
}
740753

741754
Ok(())

src/test/ui/issues/issue-33140-traitobject-crate.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119)
1+
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
22
--> $DIR/issue-33140-traitobject-crate.rs:85:1
33
|
44
LL | unsafe impl Trait for ::std::marker::Send + Sync { }
55
| ------------------------------------------------ first implementation here
66
LL | unsafe impl Trait for ::std::marker::Send + Send + Sync { }
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
88
|
99
note: lint level defined here
1010
--> $DIR/issue-33140-traitobject-crate.rs:3:9
@@ -14,25 +14,25 @@ LL | #![warn(order_dependent_trait_objects)]
1414
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1515
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
1616

17-
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119)
17+
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
1818
--> $DIR/issue-33140-traitobject-crate.rs:86:1
1919
|
2020
LL | unsafe impl Trait for ::std::marker::Send + Send + Sync { }
2121
| ------------------------------------------------------- first implementation here
2222
LL | unsafe impl Trait for ::std::marker::Sync + Send { }
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)`
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
2424
|
2525
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2626
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
2727

28-
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`: (E0119)
28+
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
2929
--> $DIR/issue-33140-traitobject-crate.rs:88:1
3030
|
3131
LL | unsafe impl Trait for ::std::marker::Sync + Send { }
3232
| ------------------------------------------------ first implementation here
3333
LL | unsafe impl Trait for ::std::marker::Sync + Sync { }
3434
LL | unsafe impl Trait for ::std::marker::Sync + Send + Sync { }
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)`
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
3636
|
3737
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3838
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>

src/test/ui/issues/issue-33140.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0119]: conflicting implementations of trait `Trait` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`:
1+
error[E0119]: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`:
22
--> $DIR/issue-33140.rs:9:1
33
|
44
LL | impl Trait for dyn Send + Sync {
55
| ------------------------------ first implementation here
66
...
77
LL | impl Trait for dyn Sync + Send {
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
99

10-
error[E0119]: conflicting implementations of trait `Trait2` for type `(dyn std::marker::Sync + std::marker::Send + 'static)`:
10+
error[E0119]: conflicting implementations of trait `Trait2` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`:
1111
--> $DIR/issue-33140.rs:22:1
1212
|
1313
LL | impl Trait2 for dyn Send + Sync {
1414
| ------------------------------- first implementation here
1515
...
1616
LL | impl Trait2 for dyn Sync + Send + Sync {
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Sync + std::marker::Send + 'static)`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
1818

1919
error[E0592]: duplicate definitions with name `abc`
2020
--> $DIR/issue-33140.rs:29:5

0 commit comments

Comments
 (0)