Skip to content

Commit dc420a2

Browse files
committed
Use DiagSymbolList for a lint diagnostic
1 parent b16f803 commit dc420a2

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use super::FnCtxt;
3232

3333
use crate::errors;
3434
use crate::type_error_struct;
35-
use itertools::Itertools;
3635
use rustc_data_structures::fx::FxHashSet;
3736
use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed};
3837
use rustc_hir::{self as hir, ExprKind, LangItem};
@@ -897,10 +896,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
897896
traits_len: added.len(),
898897
traits: added
899898
.into_iter()
900-
.map(|trait_did| {
901-
format!("`{}`", tcx.def_path_str(trait_did))
902-
})
903-
.join(", "),
899+
.map(|trait_did| tcx.def_path_str(trait_did))
900+
.collect(),
904901
},
905902
)
906903
}

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::borrow::Cow;
44

55
use crate::fluent_generated as fluent;
66
use rustc_errors::{
7-
codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
8-
SubdiagMessageOp, Subdiagnostic,
7+
codes::*, Applicability, Diag, DiagArgValue, DiagSymbolList, EmissionGuarantee, IntoDiagArg,
8+
MultiSpan, SubdiagMessageOp, Subdiagnostic,
99
};
1010
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1111
use rustc_middle::ty::{self, Ty};
@@ -258,7 +258,7 @@ pub struct LossyProvenanceInt2Ptr<'tcx> {
258258
//#[help]
259259
pub struct PtrCastAddAutoToObject {
260260
pub traits_len: usize,
261-
pub traits: String,
261+
pub traits: DiagSymbolList<String>,
262262
}
263263

264264
#[derive(Subdiagnostic)]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
88
//~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
}
1010

11+
// (to test diagnostic list formatting)
12+
fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
13+
x as _
14+
//~^ warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
15+
//~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16+
}
17+
1118
fn main() {}

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

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

11-
warning: 1 warning emitted
11+
warning: adding auto traits `Sync`, `Send`, and `Unpin` to a trait object in a pointer cast may cause UB later on
12+
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
13+
|
14+
LL | x as _
15+
| ^^^^^^
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
19+
20+
warning: 2 warnings emitted
1221

1322
Future incompatibility report: Future breakage diagnostic:
1423
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 _
2130
= note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
2231
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
2332

33+
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
35+
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
36+
|
37+
LL | x as _
38+
| ^^^^^^
39+
|
40+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
41+
= note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
42+
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
43+

0 commit comments

Comments
 (0)