Skip to content

Commit 56de9da

Browse files
committed
Sort trait names before printing
1 parent a1f20f1 commit 56de9da

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
897897
self.span,
898898
errors::PtrCastAddAutoToObject {
899899
traits_len: added.len(),
900-
traits: added
901-
.into_iter()
902-
.map(|trait_did| tcx.def_path_str(trait_did))
903-
.collect(),
900+
traits: {
901+
let mut traits: Vec<_> = added
902+
.into_iter()
903+
.map(|trait_did| tcx.def_path_str(trait_did))
904+
.collect();
905+
906+
traits.sort();
907+
traits.into()
908+
},
904909
},
905910
)
906911
}

tests/ui/cast/ptr-to-trait-obj-add-auto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
1111
// (to test diagnostic list formatting)
1212
fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
1313
x as _
14-
//~^ warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
14+
//~^ warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
1515
//~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1616
}
1717

tests/ui/cast/ptr-to-trait-obj-add-auto.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | x as _
88
= note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
99
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
1010

11-
warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
11+
warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
1212
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
1313
|
1414
LL | x as _
@@ -31,7 +31,7 @@ LL | x as _
3131
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
3232

3333
Future breakage diagnostic:
34-
warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
34+
warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
3535
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
3636
|
3737
LL | x as _

0 commit comments

Comments
 (0)