11error: only `u8` can be cast into `char`
2- --> $DIR/cast-char.rs:4:23
2+ --> $DIR/cast-char.rs:12:31
33 |
4- LL | const XYZ : char = 0x1F888 as char;
5- | ^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888 }'`
4+ LL | const VALID_LOW_1 : char = 0x1000 as char; // 4096
5+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1000 }'`
66 |
77note: the lint level is defined here
88 --> $DIR/cast-char.rs:1:9
@@ -11,10 +11,127 @@ LL | #![deny(overflowing_literals)]
1111 | ^^^^^^^^^^^^^^^^^^^^
1212
1313error: only `u8` can be cast into `char`
14- --> $DIR/cast-char.rs:6:22
14+ --> $DIR/cast-char.rs:14:31
1515 |
16- LL | const XY : char = 129160 as char;
17- | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888 }'`
16+ LL | const VALID_LOW_2 : char = 0xD7FF as char; // last valid in lower range
17+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{D7FF }'`
1818
19- error: aborting due to 2 previous errors
19+ error: only `u8` can be cast into `char`
20+ --> $DIR/cast-char.rs:16:31
21+ |
22+ LL | const VALID_LOW_3: char = 0x0500 as char; // cyrillic range
23+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{500}'`
24+
25+ error: only `u8` can be cast into `char`
26+ --> $DIR/cast-char.rs:20:32
27+ |
28+ LL | const VALID_HIGH_1: char = 0xE000 as char; // first valid in upper range
29+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{E000}'`
30+
31+ error: only `u8` can be cast into `char`
32+ --> $DIR/cast-char.rs:22:32
33+ |
34+ LL | const VALID_HIGH_2: char = 0x1F888 as char; // 129160 - example from issue
35+ | ^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888}'`
36+
37+ error: only `u8` can be cast into `char`
38+ --> $DIR/cast-char.rs:24:32
39+ |
40+ LL | const VALID_HIGH_3: char = 0x10FFFF as char; // maximum valid Unicode
41+ | ^^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{10FFFF}'`
42+
43+ error: only `u8` can be cast into `char`
44+ --> $DIR/cast-char.rs:26:32
45+ |
46+ LL | const VALID_HIGH_4: char = 0xFFFD as char; // replacement character
47+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{FFFD}'`
48+
49+ error: only `u8` can be cast into `char`
50+ --> $DIR/cast-char.rs:28:32
51+ |
52+ LL | const VALID_HIGH_5: char = 0x1F600 as char; // emoji
53+ | ^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F600}'`
54+
55+ error: cannot cast `55296` to `char`
56+ --> $DIR/cast-char.rs:34:39
57+ |
58+ LL | const INVALID_SURROGATE_1: char = 0xD800 as char; // first surrogate
59+ | ^^^^^^^^^^^^^^
60+ |
61+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
62+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
63+
64+ error: cannot cast `57343` to `char`
65+ --> $DIR/cast-char.rs:36:39
66+ |
67+ LL | const INVALID_SURROGATE_2: char = 0xDFFF as char; // last surrogate
68+ | ^^^^^^^^^^^^^^
69+ |
70+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
71+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
72+
73+ error: cannot cast `56064` to `char`
74+ --> $DIR/cast-char.rs:38:39
75+ |
76+ LL | const INVALID_SURROGATE_3: char = 0xDB00 as char; // middle of surrogate range
77+ | ^^^^^^^^^^^^^^
78+ |
79+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
80+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
81+
82+ error: cannot cast `1114112` to `char`
83+ --> $DIR/cast-char.rs:42:37
84+ |
85+ LL | const INVALID_TOO_BIG_1: char = 0x110000 as char; // one more than maximum
86+ | ^^^^^^^^^^^^^^^^
87+ |
88+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
89+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
90+
91+ error: cannot cast `15698056` to `char`
92+ --> $DIR/cast-char.rs:44:37
93+ |
94+ LL | const INVALID_TOO_BIG_2: char = 0xEF8888 as char; // example from issue
95+ | ^^^^^^^^^^^^^^^^
96+ |
97+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
98+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
99+
100+ error: cannot cast `2097151` to `char`
101+ --> $DIR/cast-char.rs:46:37
102+ |
103+ LL | const INVALID_TOO_BIG_3: char = 0x1FFFFF as char; // much larger
104+ | ^^^^^^^^^^^^^^^^
105+ |
106+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
107+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
108+
109+ error: cannot cast `16777215` to `char`
110+ --> $DIR/cast-char.rs:48:37
111+ |
112+ LL | const INVALID_TOO_BIG_4: char = 0xFFFFFF as char; // 24-bit maximum
113+ | ^^^^^^^^^^^^^^^^
114+ |
115+ = note: char must be a valid Unicode scalar value (code points in ranges [0x0, 0xD7FF] or [0xE000, 0x10FFFF])
116+ = note: the gap [0xD800, 0xDFFF] is reserved for UTF-16 surrogates and is invalid
117+
118+ error: only `u8` can be cast into `char`
119+ --> $DIR/cast-char.rs:52:30
120+ |
121+ LL | const BOUNDARY_1: char = 0xD7FE as char; // valid, before surrogate
122+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{D7FE}'`
123+
124+ error: only `u8` can be cast into `char`
125+ --> $DIR/cast-char.rs:54:30
126+ |
127+ LL | const BOUNDARY_2: char = 0xE001 as char; // valid, after surrogate
128+ | ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{E001}'`
129+
130+ error: only `u8` can be cast into `char`
131+ --> $DIR/cast-char.rs:56:30
132+ |
133+ LL | const BOUNDARY_3: char = 0x10FFFE as char; // valid, near maximum
134+ | ^^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{10FFFE}'`
135+
136+ error: aborting due to 18 previous errors
20137
0 commit comments