Commit c144da3
committed
Implement RFC 3349, mixed utf8 literals.
Specifically:
- Allow unicode chars in b"" and br"" literals. This is done by changing
`Mode::allow_unicode_chars` to succeed on `ByteStr` and `RawByteStr`.
- Allow unicode escapes in b"" literals. This is done by changing
`Mode::allow_unicode_escapes` to succeed on `ByteStr`.
Byte string literals can already have high bytes (`\x80`..`\xff`).
Because they now also support unicode chars, they can now be mixed utf8,
so we use `unescape_mixed`/`cook_mixed` instead of
`unescape_unicode`/`cook_unicode` to process them.
A new type `Rfc3349`, is used to implement the feature gating. Values of
that type are threaded through the unescaping code to track whether
rules from rfc3349 are required for unescaping to succeed.
Test changes:
- tests/ui/mixed-utf8-literals/basic.rs: new `check-pass` UI test with
various literals exercising the new forms.
- tests/ui/attributes/key-value-non-ascii.rs: changed from a byte string
literal to a byte literal; we just need some kind of problem with a
literal to preserve the test's intent.
- tests/ui/parser/raw/raw-byte-string-literals.rs: moved the raw byte
string literal with a non-ASCII char to `basic.rs`.
- tests/ui/parser/byte-string-literals.rs: similar.
- tests/ui/parser/issues/issue-23620-invalid-escapes.rs: moved one case
fully to `basic.rs`, and one partially.
- tests/ui/parser/unicode-control-codepoints.rs: left the code
unchanged, but the errors are now about mixed-utf8-literals being
feature gated.
- tests/ui/suggestions/multibyte-escapes.rs: moved one case to
`basic.rs`.
- compiler/rustc_lexer/src/unescape/tests.rs: various adjustments
- two cases that previously failed now succeed
- added some more cases for the newly supported syntax
I wasn't sure how to handle rust-analyzer in general, so I just allowed
mixed utf8 literals everywhere without complaint.1 parent fb4bca0 commit c144da3
File tree
29 files changed
+364
-348
lines changed- compiler
- rustc_ast_passes/src
- rustc_ast/src/util
- rustc_feature/src
- rustc_lexer/src
- unescape
- rustc_parse_format/src
- rustc_parse/src/lexer
- rustc_span/src
- src
- doc/unstable-book/src/language-features
- tools
- rust-analyzer/crates
- parser/src
- syntax/src
- ast
- tidy/src
- tests/ui
- attributes
- feature-gates
- mixed-utf8-literals
- parser
- issues
- raw
- suggestions
29 files changed
+364
-348
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | | - | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| |||
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
128 | | - | |
| 132 | + | |
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| 511 | + | |
511 | 512 | | |
512 | 513 | | |
513 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
| 527 | + | |
526 | 528 | | |
527 | 529 | | |
528 | 530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
97 | 98 | | |
98 | | - | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
156 | | - | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
172 | 183 | | |
173 | 184 | | |
174 | 185 | | |
| |||
205 | 216 | | |
206 | 217 | | |
207 | 218 | | |
208 | | - | |
| 219 | + | |
209 | 220 | | |
210 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 | | |
212 | 227 | | |
213 | 228 | | |
214 | 229 | | |
215 | 230 | | |
216 | | - | |
| 231 | + | |
217 | 232 | | |
218 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
219 | 238 | | |
220 | 239 | | |
221 | 240 | | |
| |||
233 | 252 | | |
234 | 253 | | |
235 | 254 | | |
| 255 | + | |
236 | 256 | | |
237 | 257 | | |
238 | 258 | | |
| |||
262 | 282 | | |
263 | 283 | | |
264 | 284 | | |
265 | | - | |
| 285 | + | |
266 | 286 | | |
267 | 287 | | |
268 | 288 | | |
269 | 289 | | |
270 | 290 | | |
271 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
272 | 296 | | |
273 | 297 | | |
274 | 298 | | |
| |||
296 | 320 | | |
297 | 321 | | |
298 | 322 | | |
299 | | - | |
| 323 | + | |
300 | 324 | | |
301 | 325 | | |
302 | 326 | | |
| |||
322 | 346 | | |
323 | 347 | | |
324 | 348 | | |
325 | | - | |
326 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
327 | 356 | | |
328 | 357 | | |
329 | 358 | | |
330 | 359 | | |
| 360 | + | |
331 | 361 | | |
332 | | - | |
| 362 | + | |
333 | 363 | | |
334 | 364 | | |
335 | | - | |
| 365 | + | |
336 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
337 | 370 | | |
338 | 371 | | |
339 | 372 | | |
| |||
342 | 375 | | |
343 | 376 | | |
344 | 377 | | |
345 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
346 | 383 | | |
347 | 384 | | |
348 | 385 | | |
349 | 386 | | |
350 | | - | |
| 387 | + | |
351 | 388 | | |
352 | 389 | | |
353 | 390 | | |
| |||
367 | 404 | | |
368 | 405 | | |
369 | 406 | | |
370 | | - | |
| 407 | + | |
371 | 408 | | |
372 | 409 | | |
373 | 410 | | |
374 | 411 | | |
375 | | - | |
| 412 | + | |
376 | 413 | | |
377 | 414 | | |
378 | 415 | | |
379 | 416 | | |
| 417 | + | |
380 | 418 | | |
381 | 419 | | |
382 | 420 | | |
| |||
409 | 447 | | |
410 | 448 | | |
411 | 449 | | |
412 | | - | |
| 450 | + | |
413 | 451 | | |
414 | 452 | | |
415 | 453 | | |
416 | 454 | | |
417 | | - | |
| 455 | + | |
418 | 456 | | |
419 | 457 | | |
420 | 458 | | |
| |||
423 | 461 | | |
424 | 462 | | |
425 | 463 | | |
426 | | - | |
| 464 | + | |
427 | 465 | | |
428 | 466 | | |
429 | 467 | | |
430 | 468 | | |
| 469 | + | |
431 | 470 | | |
432 | 471 | | |
433 | 472 | | |
434 | | - | |
| 473 | + | |
435 | 474 | | |
436 | | - | |
| 475 | + | |
437 | 476 | | |
438 | 477 | | |
0 commit comments