Skip to content

Commit

Permalink
Auto merge of #87948 - JohnTitor:rollup-efmgyl8, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #85835 (Implement Extend<(A, B)> for (Extend<A>, Extend<B>))
 - #87671 (Warn when an escaped newline skips multiple lines)
 - #87878 (:arrow_up: rust-analyzer)
 - #87903 (Reduce verbosity of tracing output of  RUSTC_LOG)
 - #87925 (Update books)
 - #87928 (Update cargo)
 - #87942 (set the executable bit on pre-commit.sh)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 12, 2021
2 parents eb2226b + 334f09b commit 4e90017
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ dependencies = [

[[package]]
name = "cargo-platform"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"serde",
]
Expand Down Expand Up @@ -1723,9 +1723,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"

[[package]]
name = "jobserver"
version = "0.1.22"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
checksum = "f5ca711fd837261e14ec9e674f092cbb931d3fa1482b017ae59328ddc6f3212b"
dependencies = [
"libc",
]
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,6 @@ pub fn init_env_logger(env: &str) {
.with_indent_lines(true)
.with_ansi(color_logs)
.with_targets(true)
.with_wraparound(10)
.with_verbose_exit(true)
.with_verbose_entry(true)
.with_indent_amount(2);
#[cfg(parallel_compiler)]
let layer = layer.with_thread_ids(true).with_thread_names(true);
Expand Down
17 changes: 13 additions & 4 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 @@ -315,12 +319,17 @@ where
where
F: FnMut(Range<usize>, Result<char, EscapeError>),
{
let str = chars.as_str();
let first_non_space = str
let tail = chars.as_str();
let first_non_space = tail
.bytes()
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
.unwrap_or(str.len());
let tail = &str[first_non_space..];
.unwrap_or(tail.len());
if tail[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 = &tail[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
// skipped. The +1 is necessary to account for the leading \ that started the escape.
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
58 changes: 58 additions & 0 deletions library/core/src/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,61 @@ impl Extend<()> for () {
}
fn extend_one(&mut self, _item: ()) {}
}

#[stable(feature = "extend_for_tuple", since = "1.56.0")]
impl<A, B, ExtendA, ExtendB> Extend<(A, B)> for (ExtendA, ExtendB)
where
ExtendA: Extend<A>,
ExtendB: Extend<B>,
{
/// Allows to `extend` a tuple of collections that also implement `Extend`.
///
/// See also: [`Iterator::unzip`]
///
/// # Examples
/// ```
/// let mut tuple = (vec![0], vec![1]);
/// tuple.extend(vec![(2, 3), (4, 5), (6, 7)]);
/// assert_eq!(tuple.0, vec![0, 2, 4, 6]);
/// assert_eq!(tuple.1, vec![1, 3, 5, 7]);
///
/// // also allows for arbitrarily nested tuples
/// let mut nested_tuple = (vec![(1, -1)], vec![(2, -2)]);
/// nested_tuple.extend(vec![((3, -3), (4, -4)), ((5, -5), (6, -6))]);
///
/// assert_eq!(nested_tuple.0, vec![(1, -1), (3, -3), (5, -5)]);
/// assert_eq!(nested_tuple.1, vec![(2, -2), (4, -4), (6, -6)]);
/// ```
fn extend<T: IntoIterator<Item = (A, B)>>(&mut self, into_iter: T) {
let (a, b) = self;
let iter = into_iter.into_iter();

fn extend<'a, A, B>(
a: &'a mut impl Extend<A>,
b: &'a mut impl Extend<B>,
) -> impl FnMut((), (A, B)) + 'a {
move |(), (t, u)| {
a.extend_one(t);
b.extend_one(u);
}
}

let (lower_bound, _) = iter.size_hint();
if lower_bound > 0 {
a.extend_reserve(lower_bound);
b.extend_reserve(lower_bound);
}

iter.fold((), extend(a, b));
}

fn extend_one(&mut self, item: (A, B)) {
self.0.extend_one(item.0);
self.1.extend_one(item.1);
}

fn extend_reserve(&mut self, additional: usize) {
self.0.extend_reserve(additional);
self.1.extend_reserve(additional);
}
}
33 changes: 11 additions & 22 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,14 @@ pub trait Iterator {
///
/// assert_eq!(left, [1, 3]);
/// assert_eq!(right, [2, 4]);
///
/// // you can also unzip multiple nested tuples at once
/// let a = [(1, (2, 3)), (4, (5, 6))];
///
/// let (x, (y, z)): (Vec<_>, (Vec<_>, Vec<_>)) = a.iter().cloned().unzip();
/// assert_eq!(x, [1, 4]);
/// assert_eq!(y, [2, 5]);
/// assert_eq!(z, [3, 6]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
Expand All @@ -2849,28 +2857,9 @@ pub trait Iterator {
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
{
fn extend<'a, A, B>(
ts: &'a mut impl Extend<A>,
us: &'a mut impl Extend<B>,
) -> impl FnMut((), (A, B)) + 'a {
move |(), (t, u)| {
ts.extend_one(t);
us.extend_one(u);
}
}

let mut ts: FromA = Default::default();
let mut us: FromB = Default::default();

let (lower_bound, _) = self.size_hint();
if lower_bound > 0 {
ts.extend_reserve(lower_bound);
us.extend_reserve(lower_bound);
}

self.fold((), extend(&mut ts, &mut us));

(ts, us)
let mut unzipped: (FromA, FromB) = Default::default();
unzipped.extend(self);
unzipped
}

/// Creates an iterator which copies all of its elements.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 560 files
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide
Empty file modified src/etc/pre-commit.sh
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions src/test/ui/fmt/format-string-error-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
a");
//~^ ERROR invalid format string
format!("{ \
\
b");
//~^ ERROR invalid format string
format!(r#"{ \
Expand Down Expand Up @@ -38,12 +38,12 @@ fn main() {
{ \
\
b \
\
");
//~^^^ ERROR invalid format string
format!(r#"
raw { \
\
c"#);
//~^^^ ERROR invalid format string
format!(r#"
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/fmt/format-string-error-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ error: invalid format string: expected `'}'`, found `'b'`
|
LL | format!("{ \
| - because of this opening brace
LL |
LL | \
LL | b");
| ^ expected `}` in format string
|
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/str/str-escape.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
fn main() {
let s = "\
";
//~^^^ WARNING multiple lines skipped by escaped newline
let s = "foo\
  bar
";
//~^^^ WARNING non-ASCII whitespace symbol '\u{a0}' is not skipped
}
21 changes: 21 additions & 0 deletions src/test/ui/str/str-escape.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
warning: multiple lines skipped by escaped newline
--> $DIR/str-escape.rs:3:14
|
LL | let s = "\
| ______________^
LL | |
LL | | ";
| |_____________^ skipping everything up to and including this point

warning: non-ASCII whitespace symbol '\u{a0}' is not skipped
--> $DIR/str-escape.rs:7:17
|
LL | let s = "foo\
| _________________^
LL | |   bar
| | ^ non-ASCII whitespace symbol '\u{a0}' is not skipped
| |___|
|

warning: 2 warnings emitted

2 changes: 1 addition & 1 deletion src/tools/rust-analyzer

0 comments on commit 4e90017

Please sign in to comment.