1
Fork 0

Rollup merge of #115765 - asquared31415:cast_diag, r=WaffleLapkin

Add source type for invalid bool casts

Also adds tests for casting various types to `bool` that were otherwise untested.

r? `@WaffleLapkin`
This commit is contained in:
Matthias Krüger 2023-09-12 06:34:46 +02:00 committed by GitHub
commit 32cf2c4b68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 103 additions and 14 deletions

View file

@ -321,8 +321,13 @@ impl<'a, 'tcx> CastCheck<'tcx> {
.emit();
}
CastError::CastToBool => {
let mut err =
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`");
let mut err = struct_span_err!(
fcx.tcx.sess,
self.span,
E0054,
"cannot cast `{}` as `bool`",
self.expr_ty
);
if self.expr_ty.is_numeric() {
match fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {