Remove unhelpful comments and add helpful ones

This commit is contained in:
Maybe Lapkin 2024-07-04 17:51:36 +02:00
parent dc420a282b
commit 52ba120700
3 changed files with 7 additions and 5 deletions

View File

@ -2323,6 +2323,10 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
let src_tail = tcx.struct_tail_without_normalization(src.ty);
let dst_tail = tcx.struct_tail_without_normalization(dst.ty);
// This checks (lifetime part of) vtable validity for pointer casts,
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).
//
// Note that other checks (such as denying `dyn Send` -> `dyn Debug`) are in `rustc_hir_typeck`.
if let ty::Dynamic(src_tty, ..) = src_tail.kind()
&& let ty::Dynamic(dst_tty, ..) = dst_tail.kind()
&& src_tty.principal().is_some()

View File

@ -838,6 +838,9 @@ fn check_ptr_ptr_cast(
// Check that the traits are actually the same
// (this is required as the `Unsize` check below would allow upcasting, etc)
// N.B.: this is only correct as long as we don't support `trait A<T>: A<()>`.
//
// Note that trait upcasting goes through a different mechanism (`coerce_unsized`)
// and is unaffected by this check.
if src_principal.def_id() != dst_principal.def_id() {
return Err(CastError::DifferingKinds);
}
@ -902,10 +905,6 @@ fn check_ptr_ptr_cast(
)
}
// FIXME: ideally we'd maybe add a flag here, so that borrowck knows that
// it needs to borrowck this ptr cast. this is made annoying by the
// fact that `thir` does not have `CastKind` and mir restores it
// from types.
Ok(CastKind::PtrPtrCast)
}

View File

@ -255,7 +255,6 @@ pub struct LossyProvenanceInt2Ptr<'tcx> {
#[derive(LintDiagnostic)]
#[diag(hir_typeck_ptr_cast_add_auto_to_object)]
//#[help]
pub struct PtrCastAddAutoToObject {
pub traits_len: usize,
pub traits: DiagSymbolList<String>,