Use DiagSymbolList
for a lint diagnostic
This commit is contained in:
parent
b16f803431
commit
dc420a282b
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::type_error_struct;
|
use crate::type_error_struct;
|
||||||
use itertools::Itertools;
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed};
|
use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed};
|
||||||
use rustc_hir::{self as hir, ExprKind, LangItem};
|
use rustc_hir::{self as hir, ExprKind, LangItem};
|
||||||
@ -897,10 +896,8 @@ fn check_ptr_ptr_cast(
|
|||||||
traits_len: added.len(),
|
traits_len: added.len(),
|
||||||
traits: added
|
traits: added
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|trait_did| {
|
.map(|trait_did| tcx.def_path_str(trait_did))
|
||||||
format!("`{}`", tcx.def_path_str(trait_did))
|
.collect(),
|
||||||
})
|
|
||||||
.join(", "),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
use crate::fluent_generated as fluent;
|
use crate::fluent_generated as fluent;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
|
codes::*, Applicability, Diag, DiagArgValue, DiagSymbolList, EmissionGuarantee, IntoDiagArg,
|
||||||
SubdiagMessageOp, Subdiagnostic,
|
MultiSpan, SubdiagMessageOp, Subdiagnostic,
|
||||||
};
|
};
|
||||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
@ -258,7 +258,7 @@ pub struct LossyProvenanceInt2Ptr<'tcx> {
|
|||||||
//#[help]
|
//#[help]
|
||||||
pub struct PtrCastAddAutoToObject {
|
pub struct PtrCastAddAutoToObject {
|
||||||
pub traits_len: usize,
|
pub traits_len: usize,
|
||||||
pub traits: String,
|
pub traits: DiagSymbolList<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
@ -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!
|
//~| 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() {}
|
fn main() {}
|
||||||
|
@ -8,7 +8,16 @@ LL | x as _
|
|||||||
= note: for more information, see issue #125289 <https://github.com/rust-lang/rust/issues/125289>
|
= 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
|
= 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:
|
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
|
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: 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
|
= 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user