We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 60158f4 commit 2899b58Copy full SHA for 2899b58
compiler/rustc_typeck/src/check/cast.rs
@@ -359,6 +359,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
359
{
360
sugg = Some(format!("&{}", mutbl.prefix_str()));
361
}
362
+ } else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() {
363
+ if fcx
364
+ .try_coerce(
365
+ self.expr,
366
+ fcx.tcx.mk_ref(
367
+ &ty::RegionKind::ReErased,
368
+ TypeAndMut { ty: self.expr_ty, mutbl },
369
+ ),
370
+ self.cast_ty,
371
+ AllowTwoPhase::No,
372
+ )
373
+ .is_ok()
374
+ {
375
+ sugg = Some(format!("&{}", mutbl.prefix_str()));
376
+ }
377
378
if let Some(sugg) = sugg {
379
err.span_label(self.span, "invalid cast");
0 commit comments