Skip to content

Commit 3bb7c34

Browse files
committed
Revert "Rollup merge of #87596 - jesyspa:issue-87318-hidden-whitespace, r=estebank"
This reverts commit aa9e6aa, reversing changes made to 5e2655d.
1 parent 2939249 commit 3bb7c34

File tree

4 files changed

+8
-75
lines changed

4 files changed

+8
-75
lines changed

compiler/rustc_ast/src/util/literal.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ impl LitKind {
6363
unescape_literal(&s, Mode::Str, &mut |_, unescaped_char| {
6464
match unescaped_char {
6565
Ok(c) => buf.push(c),
66-
Err(err) => {
67-
if err.is_fatal() {
68-
error = Err(LitError::LexerError);
69-
}
70-
}
66+
Err(_) => error = Err(LitError::LexerError),
7167
}
7268
});
7369
error?;
@@ -87,11 +83,7 @@ impl LitKind {
8783
unescape_literal(&s, Mode::RawStr, &mut |_, unescaped_char| {
8884
match unescaped_char {
8985
Ok(c) => buf.push(c),
90-
Err(err) => {
91-
if err.is_fatal() {
92-
error = Err(LitError::LexerError);
93-
}
94-
}
86+
Err(_) => error = Err(LitError::LexerError),
9587
}
9688
});
9789
error?;
@@ -108,11 +100,7 @@ impl LitKind {
108100
unescape_byte_literal(&s, Mode::ByteStr, &mut |_, unescaped_byte| {
109101
match unescaped_byte {
110102
Ok(c) => buf.push(c),
111-
Err(err) => {
112-
if err.is_fatal() {
113-
error = Err(LitError::LexerError);
114-
}
115-
}
103+
Err(_) => error = Err(LitError::LexerError),
116104
}
117105
});
118106
error?;
@@ -126,11 +114,7 @@ impl LitKind {
126114
unescape_byte_literal(&s, Mode::RawByteStr, &mut |_, unescaped_byte| {
127115
match unescaped_byte {
128116
Ok(c) => buf.push(c),
129-
Err(err) => {
130-
if err.is_fatal() {
131-
error = Err(LitError::LexerError);
132-
}
133-
}
117+
Err(_) => error = Err(LitError::LexerError),
134118
}
135119
});
136120
error?;

compiler/rustc_lexer/src/unescape.rs

+4-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::str::Chars;
77
#[cfg(test)]
88
mod tests;
99

10-
/// Errors and warnings that can occur during string unescaping.
10+
/// Errors that can occur during string unescaping.
1111
#[derive(Debug, PartialEq, Eq)]
1212
pub enum EscapeError {
1313
/// Expected 1 char, but 0 were found.
@@ -56,20 +56,6 @@ pub enum EscapeError {
5656
NonAsciiCharInByte,
5757
/// Non-ascii character in byte string literal.
5858
NonAsciiCharInByteString,
59-
60-
/// After a line ending with '\', the next line contains whitespace
61-
/// characters that are not skipped.
62-
UnskippedWhitespaceWarning,
63-
}
64-
65-
impl EscapeError {
66-
/// Returns true for actual errors, as opposed to warnings.
67-
pub fn is_fatal(&self) -> bool {
68-
match self {
69-
EscapeError::UnskippedWhitespaceWarning => false,
70-
_ => true,
71-
}
72-
}
7359
}
7460

7561
/// Takes a contents of a literal (without quotes) and produces a
@@ -297,7 +283,7 @@ where
297283
// if unescaped '\' character is followed by '\n'.
298284
// For details see [Rust language reference]
299285
// (https://doc.rust-lang.org/reference/tokens.html#string-literals).
300-
skip_ascii_whitespace(&mut chars, start, callback);
286+
skip_ascii_whitespace(&mut chars);
301287
continue;
302288
}
303289
_ => scan_escape(first_char, &mut chars, mode),
@@ -311,25 +297,13 @@ where
311297
callback(start..end, unescaped_char);
312298
}
313299

314-
fn skip_ascii_whitespace<F>(chars: &mut Chars<'_>, start: usize, callback: &mut F)
315-
where
316-
F: FnMut(Range<usize>, Result<char, EscapeError>),
317-
{
300+
fn skip_ascii_whitespace(chars: &mut Chars<'_>) {
318301
let str = chars.as_str();
319302
let first_non_space = str
320303
.bytes()
321304
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
322305
.unwrap_or(str.len());
323-
let tail = &str[first_non_space..];
324-
if let Some(c) = tail.chars().nth(0) {
325-
// For error reporting, we would like the span to contain the character that was not
326-
// skipped. The +1 is necessary to account for the leading \ that started the escape.
327-
let end = start + first_non_space + c.len_utf8() + 1;
328-
if c.is_whitespace() {
329-
callback(start..end, Err(EscapeError::UnskippedWhitespaceWarning));
330-
}
331-
}
332-
*chars = tail.chars();
306+
*chars = str[first_non_space..].chars()
333307
}
334308
}
335309

compiler/rustc_lexer/src/unescape/tests.rs

-19
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,6 @@ fn test_unescape_char_good() {
9898
check(r"\u{1F63b}", '😻');
9999
}
100100

101-
#[test]
102-
fn test_unescape_str_warn() {
103-
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
104-
let mut unescaped = Vec::with_capacity(literal.len());
105-
unescape_literal(literal, Mode::Str, &mut |range, res| unescaped.push((range, res)));
106-
assert_eq!(unescaped, expected);
107-
}
108-
109-
check(
110-
"\\\n \u{a0} x",
111-
&[
112-
(0..5, Err(EscapeError::UnskippedWhitespaceWarning)),
113-
(3..5, Ok('\u{a0}')),
114-
(5..6, Ok(' ')),
115-
(6..7, Ok('x')),
116-
],
117-
);
118-
}
119-
120101
#[test]
121102
fn test_unescape_str_good() {
122103
fn check(literal_text: &str, expected: &str) {

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

-6
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ pub(crate) fn emit_unescape_error(
274274
let msg = "invalid trailing slash in literal";
275275
handler.struct_span_err(span, msg).span_label(span, msg).emit();
276276
}
277-
EscapeError::UnskippedWhitespaceWarning => {
278-
let (c, char_span) = last_char();
279-
let msg =
280-
format!("non-ASCII whitespace symbol '{}' is not skipped", c.escape_unicode());
281-
handler.struct_span_warn(span, &msg).span_label(char_span, &msg).emit();
282-
}
283277
}
284278
}
285279

0 commit comments

Comments
 (0)