mirror of
https://github.com/rust-lang/rust.git
synced 2026-03-19 17:08:48 +00:00
Note ref expr being cast when encounter NonScalar cast error
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
@@ -408,6 +408,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
self.expr_ty,
|
||||
fcx.ty_to_string(self.cast_ty)
|
||||
);
|
||||
|
||||
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span)
|
||||
&& matches!(self.expr.kind, ExprKind::AddrOf(..))
|
||||
{
|
||||
err.note(format!(
|
||||
"casting reference expression `{}` because `&` binds tighter than `as`",
|
||||
snippet
|
||||
));
|
||||
}
|
||||
|
||||
let mut sugg = None;
|
||||
let mut sugg_mutref = false;
|
||||
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
|
||||
|
||||
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `&for<'a, 'b> fn(&'a Event<'b>) {my_fn}` as `&
|
||||
|
|
||||
LL | ..._>) = &my_fn as _;
|
||||
| ^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
||||
|
|
||||
= note: casting reference expression `&my_fn` because `&` binds tighter than `as`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ error[E0605]: non-primitive cast: `&&[i32; 1]` as `&[_]`
|
||||
|
|
||||
LL | let _ = &&[0] as &[_];
|
||||
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
||||
|
|
||||
= note: casting reference expression `&&[0]` because `&` binds tighter than `as`
|
||||
|
||||
error[E0605]: non-primitive cast: `u32` as `Option<_>`
|
||||
--> $DIR/issue-73886.rs:4:13
|
||||
|
||||
Reference in New Issue
Block a user