Rollup merge of #57493 - euclio:deref-suggest, r=oli-obk
use structured suggestion when casting a reference
This commit is contained in:
commit
e0cea0db5d
4 changed files with 20 additions and 23 deletions
|
@ -213,8 +213,14 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||||
fcx.ty_to_string(self.expr_ty),
|
fcx.ty_to_string(self.expr_ty),
|
||||||
cast_ty));
|
cast_ty));
|
||||||
if let Ok(snippet) = fcx.sess().source_map().span_to_snippet(self.expr.span) {
|
if let Ok(snippet) = fcx.sess().source_map().span_to_snippet(self.expr.span) {
|
||||||
err.span_help(self.expr.span,
|
err.span_suggestion_with_applicability(
|
||||||
&format!("did you mean `*{}`?", snippet));
|
self.expr.span,
|
||||||
|
"dereference the expression",
|
||||||
|
format!("*{}", snippet),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
err.span_help(self.expr.span, "dereference the expression with `*`");
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,10 @@ error[E0606]: casting `&u8` as `u8` is invalid
|
||||||
--> $DIR/E0606.rs:2:5
|
--> $DIR/E0606.rs:2:5
|
||||||
|
|
|
|
||||||
LL | &0u8 as u8; //~ ERROR E0606
|
LL | &0u8 as u8; //~ ERROR E0606
|
||||||
| ^^^^^^^^^^ cannot cast `&u8` as `u8`
|
| ----^^^^^^
|
||||||
|
|
| |
|
||||||
help: did you mean `*&0u8`?
|
| cannot cast `&u8` as `u8`
|
||||||
--> $DIR/E0606.rs:2:5
|
| help: dereference the expression: `*&0u8`
|
||||||
|
|
|
||||||
LL | &0u8 as u8; //~ ERROR E0606
|
|
||||||
| ^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -60,13 +60,10 @@ error[E0606]: casting `&u8` as `u32` is invalid
|
||||||
--> $DIR/error-festival.rs:37:18
|
--> $DIR/error-festival.rs:37:18
|
||||||
|
|
|
|
||||||
LL | let y: u32 = x as u32;
|
LL | let y: u32 = x as u32;
|
||||||
| ^^^^^^^^ cannot cast `&u8` as `u32`
|
| -^^^^^^^
|
||||||
|
|
| |
|
||||||
help: did you mean `*x`?
|
| cannot cast `&u8` as `u32`
|
||||||
--> $DIR/error-festival.rs:37:18
|
| help: dereference the expression: `*x`
|
||||||
|
|
|
||||||
LL | let y: u32 = x as u32;
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
|
error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
|
||||||
--> $DIR/error-festival.rs:41:5
|
--> $DIR/error-festival.rs:41:5
|
||||||
|
|
|
@ -240,13 +240,10 @@ error[E0606]: casting `&{float}` as `f32` is invalid
|
||||||
--> $DIR/cast-rfc0401.rs:71:30
|
--> $DIR/cast-rfc0401.rs:71:30
|
||||||
|
|
|
|
||||||
LL | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid
|
LL | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid
|
||||||
| ^^^^^^^^ cannot cast `&{float}` as `f32`
|
| -^^^^^^^
|
||||||
|
|
| |
|
||||||
help: did you mean `*s`?
|
| cannot cast `&{float}` as `f32`
|
||||||
--> $DIR/cast-rfc0401.rs:71:30
|
| help: dereference the expression: `*s`
|
||||||
|
|
|
||||||
LL | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to 34 previous errors
|
error: aborting due to 34 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue