Skip to content

Commit 4e90017

Browse files
committed
Auto merge of #87948 - JohnTitor:rollup-efmgyl8, r=JohnTitor
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
2 parents eb2226b + 334f09b commit 4e90017

File tree

19 files changed

+138
-43
lines changed

19 files changed

+138
-43
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ dependencies = [
356356

357357
[[package]]
358358
name = "cargo-platform"
359-
version = "0.1.1"
359+
version = "0.1.2"
360360
dependencies = [
361361
"serde",
362362
]
@@ -1723,9 +1723,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
17231723

17241724
[[package]]
17251725
name = "jobserver"
1726-
version = "0.1.22"
1726+
version = "0.1.23"
17271727
source = "registry+https://github.com/rust-lang/crates.io-index"
1728-
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
1728+
checksum = "f5ca711fd837261e14ec9e674f092cbb931d3fa1482b017ae59328ddc6f3212b"
17291729
dependencies = [
17301730
"libc",
17311731
]

compiler/rustc_driver/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1287,9 +1287,6 @@ pub fn init_env_logger(env: &str) {
12871287
.with_indent_lines(true)
12881288
.with_ansi(color_logs)
12891289
.with_targets(true)
1290-
.with_wraparound(10)
1291-
.with_verbose_exit(true)
1292-
.with_verbose_entry(true)
12931290
.with_indent_amount(2);
12941291
#[cfg(parallel_compiler)]
12951292
let layer = layer.with_thread_ids(true).with_thread_names(true);

compiler/rustc_lexer/src/unescape.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ pub enum EscapeError {
6060
/// After a line ending with '\', the next line contains whitespace
6161
/// characters that are not skipped.
6262
UnskippedWhitespaceWarning,
63+
64+
/// After a line ending with '\', multiple lines are skipped.
65+
MultipleSkippedLinesWarning,
6366
}
6467

6568
impl EscapeError {
6669
/// Returns true for actual errors, as opposed to warnings.
6770
pub fn is_fatal(&self) -> bool {
6871
match self {
6972
EscapeError::UnskippedWhitespaceWarning => false,
73+
EscapeError::MultipleSkippedLinesWarning => false,
7074
_ => true,
7175
}
7276
}
@@ -315,12 +319,17 @@ where
315319
where
316320
F: FnMut(Range<usize>, Result<char, EscapeError>),
317321
{
318-
let str = chars.as_str();
319-
let first_non_space = str
322+
let tail = chars.as_str();
323+
let first_non_space = tail
320324
.bytes()
321325
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
322-
.unwrap_or(str.len());
323-
let tail = &str[first_non_space..];
326+
.unwrap_or(tail.len());
327+
if tail[1..first_non_space].contains('\n') {
328+
// The +1 accounts for the escaping slash.
329+
let end = start + first_non_space + 1;
330+
callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning));
331+
}
332+
let tail = &tail[first_non_space..];
324333
if let Some(c) = tail.chars().nth(0) {
325334
// For error reporting, we would like the span to contain the character that was not
326335
// skipped. The +1 is necessary to account for the leading \ that started the escape.

compiler/rustc_lexer/src/unescape/tests.rs

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ fn test_unescape_str_warn() {
106106
assert_eq!(unescaped, expected);
107107
}
108108

109+
// Check we can handle escaped newlines at the end of a file.
110+
check("\\\n", &[]);
111+
check("\\\n ", &[]);
112+
109113
check(
110114
"\\\n \u{a0} x",
111115
&[
@@ -115,6 +119,7 @@ fn test_unescape_str_warn() {
115119
(6..7, Ok('x')),
116120
],
117121
);
122+
check("\\\n \n x", &[(0..7, Err(EscapeError::MultipleSkippedLinesWarning)), (7..8, Ok('x'))]);
118123
}
119124

120125
#[test]

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+5
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ pub(crate) fn emit_unescape_error(
280280
format!("non-ASCII whitespace symbol '{}' is not skipped", c.escape_unicode());
281281
handler.struct_span_warn(span, &msg).span_label(char_span, &msg).emit();
282282
}
283+
EscapeError::MultipleSkippedLinesWarning => {
284+
let msg = "multiple lines skipped by escaped newline";
285+
let bottom_msg = "skipping everything up to and including this point";
286+
handler.struct_span_warn(span, msg).span_label(span, bottom_msg).emit();
287+
}
283288
}
284289
}
285290

library/core/src/iter/traits/collect.rs

+58
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,61 @@ impl Extend<()> for () {
360360
}
361361
fn extend_one(&mut self, _item: ()) {}
362362
}
363+
364+
#[stable(feature = "extend_for_tuple", since = "1.56.0")]
365+
impl<A, B, ExtendA, ExtendB> Extend<(A, B)> for (ExtendA, ExtendB)
366+
where
367+
ExtendA: Extend<A>,
368+
ExtendB: Extend<B>,
369+
{
370+
/// Allows to `extend` a tuple of collections that also implement `Extend`.
371+
///
372+
/// See also: [`Iterator::unzip`]
373+
///
374+
/// # Examples
375+
/// ```
376+
/// let mut tuple = (vec![0], vec![1]);
377+
/// tuple.extend(vec![(2, 3), (4, 5), (6, 7)]);
378+
/// assert_eq!(tuple.0, vec![0, 2, 4, 6]);
379+
/// assert_eq!(tuple.1, vec![1, 3, 5, 7]);
380+
///
381+
/// // also allows for arbitrarily nested tuples
382+
/// let mut nested_tuple = (vec![(1, -1)], vec![(2, -2)]);
383+
/// nested_tuple.extend(vec![((3, -3), (4, -4)), ((5, -5), (6, -6))]);
384+
///
385+
/// assert_eq!(nested_tuple.0, vec![(1, -1), (3, -3), (5, -5)]);
386+
/// assert_eq!(nested_tuple.1, vec![(2, -2), (4, -4), (6, -6)]);
387+
/// ```
388+
fn extend<T: IntoIterator<Item = (A, B)>>(&mut self, into_iter: T) {
389+
let (a, b) = self;
390+
let iter = into_iter.into_iter();
391+
392+
fn extend<'a, A, B>(
393+
a: &'a mut impl Extend<A>,
394+
b: &'a mut impl Extend<B>,
395+
) -> impl FnMut((), (A, B)) + 'a {
396+
move |(), (t, u)| {
397+
a.extend_one(t);
398+
b.extend_one(u);
399+
}
400+
}
401+
402+
let (lower_bound, _) = iter.size_hint();
403+
if lower_bound > 0 {
404+
a.extend_reserve(lower_bound);
405+
b.extend_reserve(lower_bound);
406+
}
407+
408+
iter.fold((), extend(a, b));
409+
}
410+
411+
fn extend_one(&mut self, item: (A, B)) {
412+
self.0.extend_one(item.0);
413+
self.1.extend_one(item.1);
414+
}
415+
416+
fn extend_reserve(&mut self, additional: usize) {
417+
self.0.extend_reserve(additional);
418+
self.1.extend_reserve(additional);
419+
}
420+
}

library/core/src/iter/traits/iterator.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,14 @@ pub trait Iterator {
28412841
///
28422842
/// assert_eq!(left, [1, 3]);
28432843
/// assert_eq!(right, [2, 4]);
2844+
///
2845+
/// // you can also unzip multiple nested tuples at once
2846+
/// let a = [(1, (2, 3)), (4, (5, 6))];
2847+
///
2848+
/// let (x, (y, z)): (Vec<_>, (Vec<_>, Vec<_>)) = a.iter().cloned().unzip();
2849+
/// assert_eq!(x, [1, 4]);
2850+
/// assert_eq!(y, [2, 5]);
2851+
/// assert_eq!(z, [3, 6]);
28442852
/// ```
28452853
#[stable(feature = "rust1", since = "1.0.0")]
28462854
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
@@ -2849,28 +2857,9 @@ pub trait Iterator {
28492857
FromB: Default + Extend<B>,
28502858
Self: Sized + Iterator<Item = (A, B)>,
28512859
{
2852-
fn extend<'a, A, B>(
2853-
ts: &'a mut impl Extend<A>,
2854-
us: &'a mut impl Extend<B>,
2855-
) -> impl FnMut((), (A, B)) + 'a {
2856-
move |(), (t, u)| {
2857-
ts.extend_one(t);
2858-
us.extend_one(u);
2859-
}
2860-
}
2861-
2862-
let mut ts: FromA = Default::default();
2863-
let mut us: FromB = Default::default();
2864-
2865-
let (lower_bound, _) = self.size_hint();
2866-
if lower_bound > 0 {
2867-
ts.extend_reserve(lower_bound);
2868-
us.extend_reserve(lower_bound);
2869-
}
2870-
2871-
self.fold((), extend(&mut ts, &mut us));
2872-
2873-
(ts, us)
2860+
let mut unzipped: (FromA, FromB) = Default::default();
2861+
unzipped.extend(self);
2862+
unzipped
28742863
}
28752864

28762865
/// Creates an iterator which copies all of its elements.

src/doc/book

Submodule book updated 560 files

src/doc/embedded-book

src/etc/pre-commit.sh

100644100755
File mode changed.

src/test/ui/fmt/format-string-error-2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
a");
66
//~^ ERROR invalid format string
77
format!("{ \
8-
8+
\
99
b");
1010
//~^ ERROR invalid format string
1111
format!(r#"{ \
@@ -38,12 +38,12 @@ fn main() {
3838
{ \
3939
\
4040
b \
41-
41+
\
4242
");
4343
//~^^^ ERROR invalid format string
4444
format!(r#"
4545
raw { \
46-
46+
\
4747
c"#);
4848
//~^^^ ERROR invalid format string
4949
format!(r#"

src/test/ui/fmt/format-string-error-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ error: invalid format string: expected `'}'`, found `'b'`
1919
|
2020
LL | format!("{ \
2121
| - because of this opening brace
22-
LL |
22+
LL | \
2323
LL | b");
2424
| ^ expected `}` in format string
2525
|

src/test/ui/str/str-escape.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
fn main() {
3+
let s = "\
4+
5+
";
6+
//~^^^ WARNING multiple lines skipped by escaped newline
7+
let s = "foo\
8+
  bar
9+
";
10+
//~^^^ WARNING non-ASCII whitespace symbol '\u{a0}' is not skipped
11+
}

src/test/ui/str/str-escape.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
warning: multiple lines skipped by escaped newline
2+
--> $DIR/str-escape.rs:3:14
3+
|
4+
LL | let s = "\
5+
| ______________^
6+
LL | |
7+
LL | | ";
8+
| |_____________^ skipping everything up to and including this point
9+
10+
warning: non-ASCII whitespace symbol '\u{a0}' is not skipped
11+
--> $DIR/str-escape.rs:7:17
12+
|
13+
LL | let s = "foo\
14+
| _________________^
15+
LL | |   bar
16+
| | ^ non-ASCII whitespace symbol '\u{a0}' is not skipped
17+
| |___|
18+
|
19+
20+
warning: 2 warnings emitted
21+

src/tools/rust-analyzer

0 commit comments

Comments
 (0)