about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/cast.rs13
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-add-auto.rs2
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-add-auto.stderr4
3 files changed, 12 insertions, 7 deletions
diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index 887d124bd7a..c78d9e57802 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -897,10 +897,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
                                 self.span,
                                 errors::PtrCastAddAutoToObject {
                                     traits_len: added.len(),
-                                    traits: added
-                                        .into_iter()
-                                        .map(|trait_did| tcx.def_path_str(trait_did))
-                                        .collect(),
+                                    traits: {
+                                        let mut traits: Vec<_> = added
+                                            .into_iter()
+                                            .map(|trait_did| tcx.def_path_str(trait_did))
+                                            .collect();
+
+                                        traits.sort();
+                                        traits.into()
+                                    },
                                 },
                             )
                         }
diff --git a/tests/ui/cast/ptr-to-trait-obj-add-auto.rs b/tests/ui/cast/ptr-to-trait-obj-add-auto.rs
index 70293b28ee0..46e72ea0877 100644
--- a/tests/ui/cast/ptr-to-trait-obj-add-auto.rs
+++ b/tests/ui/cast/ptr-to-trait-obj-add-auto.rs
@@ -11,7 +11,7 @@ fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
 // (to test diagnostic list formatting)
 fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
     x as _
-    //~^ warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
+    //~^ warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
     //~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
 }
 
diff --git a/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr b/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr
index 175c5c98145..e5ef8bf76b4 100644
--- a/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr
+++ b/tests/ui/cast/ptr-to-trait-obj-add-auto.stderr
@@ -8,7 +8,7 @@ LL |     x as _
    = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
    = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
 
-warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
+warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
   --> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
    |
 LL |     x as _
@@ -31,7 +31,7 @@ LL |     x as _
    = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
 
 Future breakage diagnostic:
-warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
+warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
   --> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
    |
 LL |     x as _