Skip to content

Rollup of 7 pull requests #87943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5056844
Implement Extend<(A, B)> for (impl Extend<A>, impl Extend<B>)
Seppel3210 May 30, 2021
b5e9275
Rewrite Iterator::unzip in terms of (A, B)::extend
Seppel3210 May 30, 2021
c8f5d6d
Merge branch 'master' of https://github.com/rust-lang/rust
Seppel3210 Jun 12, 2021
96b7d07
Mention nested unzip in its documentation
Seppel3210 Jun 14, 2021
7b90759
Add documentation/example to Extend impl
Seppel3210 Jun 20, 2021
3d0c5d0
Update library/core/src/iter/traits/collect.rs
yaahc Aug 3, 2021
260f9b9
Link to edition guide instead of issues for 2021 lints.
m-ou-se Aug 9, 2021
62b8a5e
Reduce verbosity of RUSTC_LOG
jackh726 Aug 10, 2021
b7b0291
Move some UI tests to more suitable subdirs
JohnTitor Jul 29, 2021
107ed0a
Update books
ehuss Aug 10, 2021
e62cd40
Update cargo
ehuss Aug 10, 2021
a03fbfe
Warn when an escaped newline skips multiple lines
jesyspa Jul 31, 2021
2dff700
Update format string tests to explicitly escape multiple newlines
jesyspa Jul 31, 2021
efe069c
Add UI tests for string escape warnings.
jesyspa Aug 11, 2021
07aacf5
Renamed variable str -> tail for clarity
jesyspa Aug 11, 2021
9979921
Rollup merge of #85835 - Seppel3210:master, r=yaahc
JohnTitor Aug 11, 2021
76a4510
Rollup merge of #87600 - JohnTitor:classify-ui-tests, r=petrochenkov
JohnTitor Aug 11, 2021
94cb4e7
Rollup merge of #87671 - jesyspa:issue-87319-multiple-newlines, r=est…
JohnTitor Aug 11, 2021
3144602
Rollup merge of #87885 - m-ou-se:edition-guide-links, r=rylev
JohnTitor Aug 11, 2021
10a567e
Rollup merge of #87903 - jackh726:logging-cleanup, r=oli-obk
JohnTitor Aug 11, 2021
a290246
Rollup merge of #87925 - ehuss:update-books, r=ehuss
JohnTitor Aug 11, 2021
dd6ff48
Rollup merge of #87928 - ehuss:update-cargo, r=ehuss
JohnTitor Aug 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Warn when an escaped newline skips multiple lines
  • Loading branch information
jesyspa committed Aug 11, 2021
commit a03fbfe2ff3e7dd03af42d337b11552e782e2dc4
9 changes: 9 additions & 0 deletions compiler/rustc_lexer/src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ pub enum EscapeError {
/// After a line ending with '\', the next line contains whitespace
/// characters that are not skipped.
UnskippedWhitespaceWarning,

/// After a line ending with '\', multiple lines are skipped.
MultipleSkippedLinesWarning,
}

impl EscapeError {
/// Returns true for actual errors, as opposed to warnings.
pub fn is_fatal(&self) -> bool {
match self {
EscapeError::UnskippedWhitespaceWarning => false,
EscapeError::MultipleSkippedLinesWarning => false,
_ => true,
}
}
Expand Down Expand Up @@ -320,6 +324,11 @@ where
.bytes()
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
.unwrap_or(str.len());
if str[1..first_non_space].contains('\n') {
// The +1 accounts for the escaping slash.
let end = start + first_non_space + 1;
callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning));
}
let tail = &str[first_non_space..];
if let Some(c) = tail.chars().nth(0) {
// For error reporting, we would like the span to contain the character that was not
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_lexer/src/unescape/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ fn test_unescape_str_warn() {
assert_eq!(unescaped, expected);
}

// Check we can handle escaped newlines at the end of a file.
check("\\\n", &[]);
check("\\\n ", &[]);

check(
"\\\n \u{a0} x",
&[
Expand All @@ -115,6 +119,7 @@ fn test_unescape_str_warn() {
(6..7, Ok('x')),
],
);
check("\\\n \n x", &[(0..7, Err(EscapeError::MultipleSkippedLinesWarning)), (7..8, Ok('x'))]);
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ pub(crate) fn emit_unescape_error(
format!("non-ASCII whitespace symbol '{}' is not skipped", c.escape_unicode());
handler.struct_span_warn(span, &msg).span_label(char_span, &msg).emit();
}
EscapeError::MultipleSkippedLinesWarning => {
let msg = "multiple lines skipped by escaped newline";
let bottom_msg = "skipping everything up to and including this point";
handler.struct_span_warn(span, msg).span_label(span, bottom_msg).emit();
}
}
}

Expand Down