]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/demand.rs
Rollup merge of #91245 - cameron1024:suggest-i32-u32-char-cast, r=nagisa
[rust.git] / compiler / rustc_typeck / src / check / demand.rs
index b210c78cae007989d7ea08f895bebc42dab1da13..b7e276b69656f84d397f0c74e6d0f67f618868f8 100644 (file)
@@ -1264,6 +1264,18 @@ pub fn check_for_cast(
                 }
                 true
             }
+            (
+                &ty::Uint(ty::UintTy::U32 | ty::UintTy::U64 | ty::UintTy::U128)
+                | &ty::Int(ty::IntTy::I32 | ty::IntTy::I64 | ty::IntTy::I128),
+                &ty::Char,
+            ) => {
+                err.multipart_suggestion_verbose(
+                    &format!("{}, since a `char` always occupies 4 bytes", cast_msg,),
+                    cast_suggestion,
+                    Applicability::MachineApplicable,
+                );
+                true
+            }
             _ => false,
         }
     }