Skip to content

Commit 4ad3230

Browse files
authored
Rollup merge of #108900 - bvanjoi:issue-108275, r=petrochenkov
fix(lexer): print whitespace warning for \x0c - close #108275 - discussion: #108403
2 parents bee8473 + d223c26 commit 4ad3230

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

compiler/rustc_lexer/src/unescape.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ where
298298
}
299299
let tail = &tail[first_non_space..];
300300
if let Some(c) = tail.chars().nth(0) {
301-
// For error reporting, we would like the span to contain the character that was not
302-
// skipped. The +1 is necessary to account for the leading \ that started the escape.
303-
let end = start + first_non_space + c.len_utf8() + 1;
304301
if c.is_whitespace() {
302+
// For error reporting, we would like the span to contain the character that was not
303+
// skipped. The +1 is necessary to account for the leading \ that started the escape.
304+
let end = start + first_non_space + c.len_utf8() + 1;
305305
callback(start..end, Err(EscapeError::UnskippedWhitespaceWarning));
306306
}
307307
}

compiler/rustc_parse/locales/en-US.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ parse_zero_chars = empty character literal
709709
parse_lone_slash = invalid trailing slash in literal
710710
.label = {parse_lone_slash}
711711
712-
parse_unskipped_whitespace = non-ASCII whitespace symbol '{$ch}' is not skipped
712+
parse_unskipped_whitespace = whitespace symbol '{$ch}' is not skipped
713713
.label = {parse_unskipped_whitespace}
714714
715715
parse_multiple_skipped_lines = multiple lines skipped by escaped newline

tests/ui/str/str-escape.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
// check-pass
2+
// ignore-tidy-tab
3+
24
fn main() {
35
let s = "\
46
57
";
68
//~^^^ WARNING multiple lines skipped by escaped newline
9+
assert_eq!(s, "");
10+
711
let s = "foo\
812
  bar
913
";
10-
//~^^^ WARNING non-ASCII whitespace symbol '\u{a0}' is not skipped
14+
//~^^^ WARNING whitespace symbol '\u{a0}' is not skipped
15+
assert_eq!(s, "foo  bar\n ");
16+
17+
let s = "a\
18+
b";
19+
assert_eq!(s, "ab");
20+
21+
let s = "a\
22+
b";
23+
assert_eq!(s, "ab");
24+
25+
let s = "a\
26+
b";
27+
//~^^ WARNING whitespace symbol '\u{c}' is not skipped
28+
// '\x0c' is ASCII whitespace, but it may not need skipped
29+
// discussion: https://github.com/rust-lang/rust/pull/108403
30+
assert_eq!(s, "a\x0cb");
1131
}

tests/ui/str/str-escape.stderr

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
warning: multiple lines skipped by escaped newline
2-
--> $DIR/str-escape.rs:3:14
2+
--> $DIR/str-escape.rs:5:14
33
|
44
LL | let s = "\
55
| ______________^
66
LL | |
77
LL | | ";
88
| |_____________^ skipping everything up to and including this point
99

10-
warning: non-ASCII whitespace symbol '\u{a0}' is not skipped
11-
--> $DIR/str-escape.rs:7:17
10+
warning: whitespace symbol '\u{a0}' is not skipped
11+
--> $DIR/str-escape.rs:11:17
1212
|
1313
LL | let s = "foo\
1414
| _________________^
1515
LL | |   bar
16-
| | ^ non-ASCII whitespace symbol '\u{a0}' is not skipped
16+
| | ^ whitespace symbol '\u{a0}' is not skipped
1717
| |___|
1818
|
1919

20-
warning: 2 warnings emitted
20+
warning: whitespace symbol '\u{c}' is not skipped
21+
--> $DIR/str-escape.rs:25:15
22+
|
23+
LL | let s = "a\
24+
| _______________^
25+
LL | | b";
26+
| | ^- whitespace symbol '\u{c}' is not skipped
27+
| |____|
28+
|
29+
30+
warning: 3 warnings emitted
2131

0 commit comments

Comments
 (0)