From 56de9da1f8bbde9dad8ed79dcf45f73e08f0354f Mon Sep 17 00:00:00 2001 From: Maybe Lapkin Date: Thu, 4 Jul 2024 18:38:18 +0200 Subject: [PATCH] Sort trait names before printing --- compiler/rustc_hir_typeck/src/cast.rs | 13 +++++++++---- tests/ui/cast/ptr-to-trait-obj-add-auto.rs | 2 +- tests/ui/cast/ptr-to-trait-obj-add-auto.stderr | 4 ++-- 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 @@ fn check_ptr_ptr_cast( 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 = 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 _