mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Add suggestion to borrow when casting T to *const/mut T
This commit is contained in:
parent
60158f4a7c
commit
2899b58832
@ -359,6 +359,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||||||
{
|
{
|
||||||
sugg = Some(format!("&{}", mutbl.prefix_str()));
|
sugg = Some(format!("&{}", mutbl.prefix_str()));
|
||||||
}
|
}
|
||||||
|
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() {
|
||||||
|
if fcx
|
||||||
|
.try_coerce(
|
||||||
|
self.expr,
|
||||||
|
fcx.tcx.mk_ref(
|
||||||
|
&ty::RegionKind::ReErased,
|
||||||
|
TypeAndMut { ty: self.expr_ty, mutbl },
|
||||||
|
),
|
||||||
|
self.cast_ty,
|
||||||
|
AllowTwoPhase::No,
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
sugg = Some(format!("&{}", mutbl.prefix_str()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(sugg) = sugg {
|
if let Some(sugg) = sugg {
|
||||||
err.span_label(self.span, "invalid cast");
|
err.span_label(self.span, "invalid cast");
|
||||||
|
Loading…
Reference in New Issue
Block a user