diff options
| author | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-05-09 15:30:16 +0800 |
|---|---|---|
| committer | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-05-31 12:19:55 +0800 |
| commit | 17352e6937fde53c4f75dfd8600ecff4f1077ca2 (patch) | |
| tree | b3c2e5931eb3e1f39aa6700981c3b463ad37bead /compiler | |
| parent | 31ee8400004dd9850fa11cce311e412ceadd7062 (diff) | |
| download | rust-17352e6937fde53c4f75dfd8600ecff4f1077ca2.tar.gz rust-17352e6937fde53c4f75dfd8600ecff4f1077ca2.zip | |
Note ref expr being cast when encounter NonScalar cast error
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/cast.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index c044c4f7c37..e144a6ab599 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -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() { |
