From dc420a282b0cbfb717e1958bc28cc8ba0e335d6f Mon Sep 17 00:00:00 2001 From: Maybe Lapkin Date: Thu, 4 Jul 2024 16:46:00 +0200 Subject: [PATCH] Use `DiagSymbolList` for a lint diagnostic --- compiler/rustc_hir_typeck/src/cast.rs | 7 ++---- compiler/rustc_hir_typeck/src/errors.rs | 6 ++--- tests/ui/cast/ptr-to-trait-obj-add-auto.rs | 7 ++++++ .../ui/cast/ptr-to-trait-obj-add-auto.stderr | 22 ++++++++++++++++++- 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 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 @@ fn check_ptr_ptr_cast( 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 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, } #[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 = 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 + +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 = 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 + = note: `#[warn(ptr_cast_add_auto_to_object)]` on by default +