Use `DiagSymbolList` for a lint diagnostic

This commit is contained in:
Maybe Lapkin 2024-07-04 16:46:00 +02:00
parent b16f803431
commit dc420a282b
4 changed files with 33 additions and 9 deletions

View File

@ -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(),
},
)
}

View File

@ -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)]

View File

@ -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() {}

View File

@ -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