Add note for ?Sized params in int-ptr casts diag
This commit is contained in:
parent
0a13b43612
commit
aa7c785e8a
3 changed files with 22 additions and 0 deletions
|
|
@ -572,6 +572,17 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
let metadata = known_metadata.unwrap_or("type-specific metadata");
|
||||
let known_wide = known_metadata.is_some();
|
||||
let span = self.cast_span;
|
||||
let param_note = (!known_wide)
|
||||
.then(|| match cast_ty.kind() {
|
||||
ty::RawPtr(pointee, _) => match pointee.kind() {
|
||||
ty::Param(param) => {
|
||||
Some(errors::IntToWideParamNote { param: param.name })
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
.flatten();
|
||||
fcx.dcx().emit_err(errors::IntToWide {
|
||||
span,
|
||||
metadata,
|
||||
|
|
@ -579,6 +590,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
cast_ty,
|
||||
expr_if_nightly,
|
||||
known_wide,
|
||||
param_note,
|
||||
});
|
||||
}
|
||||
CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => {
|
||||
|
|
|
|||
|
|
@ -590,6 +590,14 @@ pub(crate) struct IntToWide<'tcx> {
|
|||
)]
|
||||
pub expr_if_nightly: Option<Span>,
|
||||
pub known_wide: bool,
|
||||
#[subdiagnostic]
|
||||
pub param_note: Option<IntToWideParamNote>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note("the type parameter `{$param}` is not known to be `Sized`, so this pointer may be wide")]
|
||||
pub(crate) struct IntToWideParamNote {
|
||||
pub param: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
|
|
|||
|
|
@ -81,6 +81,8 @@ LL | let s = 0 as *const T;
|
|||
| - ^^^^^^^^ creating a `*const T` requires both an address and type-specific metadata
|
||||
| |
|
||||
| consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`
|
||||
|
|
||||
= note: the type parameter `T` is not known to be `Sized`, so this pointer may be wide
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue