Skip to content

Commit 3c049e2

Browse files
committed
reword suggestion message
1 parent 24dcfaf commit 3c049e2

File tree

9 files changed

+16
-13
lines changed

9 files changed

+16
-13
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,20 @@ impl<'a, 'tcx> CastCheck<'tcx> {
381381
if self.expr_ty.is_numeric() {
382382
if self.expr_ty == fcx.tcx.types.u32 {
383383
err.multipart_suggestion(
384-
"try `char::from_u32` instead",
384+
"consider using `char::from_u32` instead",
385385
vec![
386386
(self.expr_span.shrink_to_lo(), "char::from_u32(".to_string()),
387387
(self.expr_span.shrink_to_hi().to(self.cast_span), ")".to_string()),
388388
],
389389
Applicability::MachineApplicable,
390390
);
391391
} else if self.expr_ty == fcx.tcx.types.i8 {
392-
err.span_help(self.span, "try casting from `u8` instead");
392+
err.span_help(self.span, "consider casting from `u8` instead");
393393
} else {
394-
err.span_help(self.span, "try `char::from_u32` instead (via a `u32`)");
394+
err.span_help(
395+
self.span,
396+
"consider using `char::from_u32` instead (via a `u32`)",
397+
);
395398
};
396399
}
397400
err.emit();
@@ -643,7 +646,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
643646
let mtstr = mt.prefix_str();
644647
err.span_suggestion_verbose(
645648
self.cast_span.shrink_to_lo(),
646-
"try casting to a reference instead",
649+
"consider casting to a reference instead",
647650
format!("&{mtstr}"),
648651
Applicability::MachineApplicable,
649652
);

tests/ui/cast/cast-to-slice.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0620]: cast to unsized type: `&[u8]` as `[char]`
44
LL | "example".as_bytes() as [char];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: try casting to a reference instead
7+
help: consider casting to a reference instead
88
|
99
LL | "example".as_bytes() as &[char];
1010
| +
@@ -15,7 +15,7 @@ error[E0620]: cast to unsized type: `&[u8]` as `[char]`
1515
LL | arr as [char];
1616
| ^^^^^^^^^^^^^
1717
|
18-
help: try casting to a reference instead
18+
help: consider casting to a reference instead
1919
|
2020
LL | arr as &[char];
2121
| +

tests/ui/cast/cast-to-unsized-trait-object-suggestion.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0620]: cast to unsized type: `&{integer}` as `dyn Send`
44
LL | &1 as dyn Send;
55
| ^^^^^^^^^^^^^^
66
|
7-
help: try casting to a reference instead
7+
help: consider casting to a reference instead
88
|
99
LL | &1 as &dyn Send;
1010
| +

tests/ui/consts/const-eval/const-eval-overflow-4b.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ error[E0604]: only `u8` can be cast as `char`, not `i8`
2323
LL | : [u32; 5i8 as char as usize]
2424
| ^^^^^^^^^^^ invalid cast
2525
|
26-
help: try casting from `u8` instead
26+
help: consider casting from `u8` instead
2727
--> $DIR/const-eval-overflow-4b.rs:24:13
2828
|
2929
LL | : [u32; 5i8 as char as usize]

tests/ui/error-codes/E0604.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
44
LL | 1u32 as char;
55
| ^^^^^^^^^^^^ invalid cast
66
|
7-
help: try `char::from_u32` instead
7+
help: consider using `char::from_u32` instead
88
|
99
LL - 1u32 as char;
1010
LL + char::from_u32(1u32);

tests/ui/error-codes/E0620.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0620]: cast to unsized type: `&[usize; 2]` as `[usize]`
44
LL | let _foo = &[1_usize, 2] as [usize];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: try casting to a reference instead
7+
help: consider casting to a reference instead
88
|
99
LL | let _foo = &[1_usize, 2] as &[usize];
1010
| +

tests/ui/error-emitter/error-festival.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
6060
LL | 0u32 as char;
6161
| ^^^^^^^^^^^^ invalid cast
6262
|
63-
help: try `char::from_u32` instead
63+
help: consider using `char::from_u32` instead
6464
|
6565
LL - 0u32 as char;
6666
LL + char::from_u32(0u32);

tests/ui/issues/issue-17441.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0620]: cast to unsized type: `&[usize; 2]` as `[usize]`
44
LL | let _foo = &[1_usize, 2] as [usize];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: try casting to a reference instead
7+
help: consider casting to a reference instead
88
|
99
LL | let _foo = &[1_usize, 2] as &[usize];
1010
| +

tests/ui/mismatched_types/cast-rfc0401.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ error[E0604]: only `u8` can be cast as `char`, not `u32`
106106
LL | let _ = 0x61u32 as char;
107107
| ^^^^^^^^^^^^^^^ invalid cast
108108
|
109-
help: try `char::from_u32` instead
109+
help: consider using `char::from_u32` instead
110110
|
111111
LL - let _ = 0x61u32 as char;
112112
LL + let _ = char::from_u32(0x61u32);

0 commit comments

Comments
 (0)