about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Lapkin <waffle.lapkin@gmail.com>2024-07-04 16:46:00 +0200
committerMaybe Lapkin <waffle.lapkin@gmail.com>2024-07-04 17:57:31 +0200
commitdc420a282b0cbfb717e1958bc28cc8ba0e335d6f (patch)
treee5bf0991cf6f51c62b8236d1053b0b424655681a
parentb16f8034316d4cd1d4a8766899d8cf30f7d73730 (diff)
downloadrust-dc420a282b0cbfb717e1958bc28cc8ba0e335d6f.tar.gz
rust-dc420a282b0cbfb717e1958bc28cc8ba0e335d6f.zip
Use `DiagSymbolList` for a lint diagnostic
-rw-r--r--compiler/rustc_hir_typeck/src/cast.rs7
-rw-r--r--compiler/rustc_hir_typeck/src/errors.rs6
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-add-auto.rs7
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-add-auto.stderr22
4 files changed, 33 insertions, 9 deletions
diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index 5787208516d..840a139b9bf 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -32,7 +32,6 @@ use super::FnCtxt;
 
 use crate::errors;
 use crate::type_error_struct;
-use itertools::Itertools;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed};
 use rustc_hir::{self as hir, ExprKind, LangItem};
@@ -897,10 +896,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
                                     traits_len: added.len(),
                                     traits: added
                                         .into_iter()
-                                        .map(|trait_did| {
-                                            format!("`{}`", tcx.def_path_str(trait_did))
-                                        })
-                                        .join(", "),
+                                        .map(|trait_did| tcx.def_path_str(trait_did))
+                                        .collect(),
                                 },
                             )
                         }
diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs
index 6c10047cfd4..cdc160d13fe 100644
--- a/compiler/rustc_hir_typeck/src/errors.rs
+++ b/compiler/rustc_hir_typeck/src/errors.rs
@@ -4,8 +4,8 @@ use std::borrow::Cow;
 
 use crate::fluent_generated as fluent;
 use rustc_errors::{
-    codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
-    SubdiagMessageOp, Subdiagnostic,
+    codes::*, Applicability, Diag, DiagArgValue, DiagSymbolList, EmissionGuarantee, IntoDiagArg,
+    MultiSpan, SubdiagMessageOp, Subdiagnostic,
 };
 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
 use rustc_middle::ty::{self, Ty};
@@ -258,7 +258,7 @@ pub struct LossyProvenanceInt2Ptr<'tcx> {
 //#[help]
 pub struct PtrCastAddAutoToObject {
     pub traits_len: usize,
-    pub traits: String,
+    pub traits: DiagSymbolList<String>,
 }
 
 #[derive(Subdiagnostic)]
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 75b56816984..70293b28ee0 100644
--- a/tests/ui/cast/ptr-to-trait-obj-add-auto.rs
+++ b/tests/ui/cast/ptr-to-trait-obj-add-auto.rs
@@ -8,4 +8,11 @@ fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
     //~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
 }
 
+// (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: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+}
+
 fn main() {}
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 ff8c7057c96..beb71eb100b 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,16 @@ LL |     x as _
    = note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
    = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
 
-warning: 1 warning emitted
+warning: adding auto traits `Sync`, `Send`, 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 _
+   |     ^^^^^^
+   |
+   = 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 #125289 <https://github.com/rust-lang/rust/issues/125289>
+
+warning: 2 warnings emitted
 
 Future incompatibility report: Future breakage diagnostic:
 warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on
@@ -21,3 +30,14 @@ LL |     x as _
    = note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
    = 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
+  --> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
+   |
+LL |     x as _
+   |     ^^^^^^
+   |
+   = 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 #125289 <https://github.com/rust-lang/rust/issues/125289>
+   = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
+