Skip to content

Commit afaf33d

Browse files
committed
Auto merge of rust-lang#83573 - JohnTitor:rollup-28jnzsr, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#79399 (Use detailed and shorter fs error explaination) - rust-lang#83348 (format macro argument parsing fix) - rust-lang#83462 (ExitStatus: print "exit status: {}" rather than "exit code: {}" on unix) - rust-lang#83526 (lazily calls some fns) - rust-lang#83558 (Use DebugStruct::finish_non_exhaustive() in std.) - rust-lang#83559 (Fix Debug implementation for RwLock{Read,Write}Guard.) - rust-lang#83560 (Derive Debug for io::Chain instead of manually implementing it.) - rust-lang#83561 (Improve Debug implementations of Mutex and RwLock.) - rust-lang#83567 (Update rustup cross-compilation docs link) - rust-lang#83569 (Add regression tests for rust-lang#56445) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1010038 + 1ad7c52 commit afaf33d

File tree

32 files changed

+132
-61
lines changed

32 files changed

+132
-61
lines changed

compiler/rustc_errors/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl DiagnosticSpanLine {
493493
h_end: usize,
494494
) -> DiagnosticSpanLine {
495495
DiagnosticSpanLine {
496-
text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
496+
text: sf.get_line(index).map_or_else(String::new, |l| l.into_owned()),
497497
highlight_start: h_start,
498498
highlight_end: h_end,
499499
}

compiler/rustc_middle/src/ty/instance.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ impl<'tcx> InstanceDef<'tcx> {
216216
// drops of `Option::None` before LTO. We also respect the intent of
217217
// `#[inline]` on `Drop::drop` implementations.
218218
return ty.ty_adt_def().map_or(true, |adt_def| {
219-
adt_def.destructor(tcx).map_or(adt_def.is_enum(), |dtor| {
220-
tcx.codegen_fn_attrs(dtor.did).requests_inline()
221-
})
219+
adt_def.destructor(tcx).map_or_else(
220+
|| adt_def.is_enum(),
221+
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),
222+
)
222223
});
223224
}
224225
tcx.codegen_fn_attrs(self.def_id()).requests_inline()

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'sess> OnDiskCache<'sess> {
525525
) {
526526
let mut current_diagnostics = self.current_diagnostics.borrow_mut();
527527

528-
let x = current_diagnostics.entry(dep_node_index).or_insert(Vec::new());
528+
let x = current_diagnostics.entry(dep_node_index).or_default();
529529

530530
x.extend(Into::<Vec<_>>::into(diagnostics));
531531
}

compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl OutlivesSuggestionBuilder {
157157
debug!("Collected {:?}: {:?}", fr, outlived_fr);
158158

159159
// Add to set of constraints for final help note.
160-
self.constraints_to_add.entry(fr).or_insert(Vec::new()).push(outlived_fr);
160+
self.constraints_to_add.entry(fr).or_default().push(outlived_fr);
161161
}
162162

163163
/// Emit an intermediate note on the given `Diagnostic` if the involved regions are

compiler/rustc_parse_format/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,13 @@ impl<'a> Iterator for Parser<'a> {
213213
Some(String(self.string(pos + 1)))
214214
} else {
215215
let arg = self.argument();
216-
if let Some(end) = self.must_consume('}') {
217-
let start = self.to_span_index(pos);
218-
let end = self.to_span_index(end + 1);
216+
if let Some(rbrace_byte_idx) = self.must_consume('}') {
217+
let lbrace_inner_offset = self.to_span_index(pos);
218+
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
219219
if self.is_literal {
220-
self.arg_places.push(start.to(end));
220+
self.arg_places.push(
221+
lbrace_inner_offset.to(InnerOffset(rbrace_inner_offset.0 + 1)),
222+
);
221223
}
222224
}
223225
Some(NextArgument(arg))

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
23272327

23282328
ExprKind::Call(ref callee, ref arguments) => {
23292329
self.resolve_expr(callee, Some(expr));
2330-
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or(Vec::new());
2330+
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
23312331
for (idx, argument) in arguments.iter().enumerate() {
23322332
// Constant arguments need to be treated as AnonConst since
23332333
// that is how they will be later lowered to HIR.

compiler/rustc_resolve/src/late/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
184184
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
185185
_ => None,
186186
}
187-
.map_or(String::new(), |res| format!("{} ", res.descr()));
187+
.map_or_else(String::new, |res| format!("{} ", res.descr()));
188188
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)))
189189
};
190190
(
@@ -1042,10 +1042,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
10421042
if let Some(span) = self.def_span(def_id) {
10431043
err.span_label(span, &format!("`{}` defined here", path_str));
10441044
}
1045-
let fields =
1046-
self.r.field_names.get(&def_id).map_or("/* fields */".to_string(), |fields| {
1047-
vec!["_"; fields.len()].join(", ")
1048-
});
1045+
let fields = self.r.field_names.get(&def_id).map_or_else(
1046+
|| "/* fields */".to_string(),
1047+
|fields| vec!["_"; fields.len()].join(", "),
1048+
);
10491049
err.span_suggestion(
10501050
span,
10511051
"use the tuple variant pattern syntax instead",

library/std/src/collections/hash/map.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
17931793
#[unstable(feature = "hash_raw_entry", issue = "56167")]
17941794
impl<K, V, S> Debug for RawEntryBuilderMut<'_, K, V, S> {
17951795
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1796-
f.debug_struct("RawEntryBuilder").finish()
1796+
f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
17971797
}
17981798
}
17991799

@@ -1813,21 +1813,21 @@ impl<K: Debug, V: Debug, S> Debug for RawOccupiedEntryMut<'_, K, V, S> {
18131813
f.debug_struct("RawOccupiedEntryMut")
18141814
.field("key", self.key())
18151815
.field("value", self.get())
1816-
.finish()
1816+
.finish_non_exhaustive()
18171817
}
18181818
}
18191819

18201820
#[unstable(feature = "hash_raw_entry", issue = "56167")]
18211821
impl<K, V, S> Debug for RawVacantEntryMut<'_, K, V, S> {
18221822
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1823-
f.debug_struct("RawVacantEntryMut").finish()
1823+
f.debug_struct("RawVacantEntryMut").finish_non_exhaustive()
18241824
}
18251825
}
18261826

18271827
#[unstable(feature = "hash_raw_entry", issue = "56167")]
18281828
impl<K, V, S> Debug for RawEntryBuilder<'_, K, V, S> {
18291829
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1830-
f.debug_struct("RawEntryBuilder").finish()
1830+
f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
18311831
}
18321832
}
18331833

@@ -1867,7 +1867,10 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
18671867
#[stable(feature = "debug_hash_map", since = "1.12.0")]
18681868
impl<K: Debug, V: Debug> Debug for OccupiedEntry<'_, K, V> {
18691869
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1870-
f.debug_struct("OccupiedEntry").field("key", self.key()).field("value", self.get()).finish()
1870+
f.debug_struct("OccupiedEntry")
1871+
.field("key", self.key())
1872+
.field("value", self.get())
1873+
.finish_non_exhaustive()
18711874
}
18721875
}
18731876

@@ -1903,7 +1906,7 @@ impl<K: Debug, V: Debug> Debug for OccupiedError<'_, K, V> {
19031906
.field("key", self.entry.key())
19041907
.field("old_value", self.entry.get())
19051908
.field("new_value", &self.value)
1906-
.finish()
1909+
.finish_non_exhaustive()
19071910
}
19081911
}
19091912

library/std/src/fs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ impl fmt::Debug for Metadata {
11541154
.field("modified", &self.modified())
11551155
.field("accessed", &self.accessed())
11561156
.field("created", &self.created())
1157-
.finish()
1157+
.finish_non_exhaustive()
11581158
}
11591159
}
11601160

@@ -1677,9 +1677,9 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
16771677
/// This function will return an error in the following situations, but is not
16781678
/// limited to just these cases:
16791679
///
1680-
/// * The `from` path is not a file.
1681-
/// * The `from` file does not exist.
1682-
/// * The current process does not have the permission rights to access
1680+
/// * `from` is neither a regular file nor a symlink to a regular file.
1681+
/// * `from` does not exist.
1682+
/// * The current process does not have the permission rights to read
16831683
/// `from` or write `to`.
16841684
///
16851685
/// # Examples

library/std/src/io/buffered/linewriter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,6 @@ where
227227
"buffer",
228228
&format_args!("{}/{}", self.inner.buffer().len(), self.inner.capacity()),
229229
)
230-
.finish()
230+
.finish_non_exhaustive()
231231
}
232232
}

library/std/src/io/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,7 @@ pub trait BufRead: Read {
21142114
///
21152115
/// [`chain`]: Read::chain
21162116
#[stable(feature = "rust1", since = "1.0.0")]
2117+
#[derive(Debug)]
21172118
pub struct Chain<T, U> {
21182119
first: T,
21192120
second: U,
@@ -2195,13 +2196,6 @@ impl<T, U> Chain<T, U> {
21952196
}
21962197
}
21972198

2198-
#[stable(feature = "std_debug", since = "1.16.0")]
2199-
impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
2200-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2201-
f.debug_struct("Chain").field("t", &self.first).field("u", &self.second).finish()
2202-
}
2203-
}
2204-
22052199
#[stable(feature = "rust1", since = "1.0.0")]
22062200
impl<T: Read, U: Read> Read for Chain<T, U> {
22072201
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {

library/std/src/lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ pub struct SyncLazy<T, F = fn() -> T> {
515515
#[unstable(feature = "once_cell", issue = "74465")]
516516
impl<T: fmt::Debug, F> fmt::Debug for SyncLazy<T, F> {
517517
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
518-
f.debug_struct("Lazy").field("cell", &self.cell).field("init", &"..").finish()
518+
f.debug_struct("Lazy").field("cell", &self.cell).finish_non_exhaustive()
519519
}
520520
}
521521

library/std/src/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl fmt::Debug for Child {
234234
.field("stdin", &self.stdin)
235235
.field("stdout", &self.stdout)
236236
.field("stderr", &self.stderr)
237-
.finish()
237+
.finish_non_exhaustive()
238238
}
239239
}
240240

library/std/src/sync/mpsc/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl<T> Drop for Sender<T> {
864864
#[stable(feature = "mpsc_debug", since = "1.8.0")]
865865
impl<T> fmt::Debug for Sender<T> {
866866
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
867-
f.debug_struct("Sender").finish()
867+
f.debug_struct("Sender").finish_non_exhaustive()
868868
}
869869
}
870870

@@ -991,7 +991,7 @@ impl<T> Drop for SyncSender<T> {
991991
#[stable(feature = "mpsc_debug", since = "1.8.0")]
992992
impl<T> fmt::Debug for SyncSender<T> {
993993
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
994-
f.debug_struct("SyncSender").finish()
994+
f.debug_struct("SyncSender").finish_non_exhaustive()
995995
}
996996
}
997997

@@ -1470,7 +1470,7 @@ impl<T> Drop for Receiver<T> {
14701470
#[stable(feature = "mpsc_debug", since = "1.8.0")]
14711471
impl<T> fmt::Debug for Receiver<T> {
14721472
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1473-
f.debug_struct("Receiver").finish()
1473+
f.debug_struct("Receiver").finish_non_exhaustive()
14741474
}
14751475
}
14761476

library/std/src/sync/mutex.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,13 @@ impl<T: ?Sized + Default> Default for Mutex<T> {
441441
#[stable(feature = "rust1", since = "1.0.0")]
442442
impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
443443
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
444+
let mut d = f.debug_struct("Mutex");
444445
match self.try_lock() {
445-
Ok(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(),
446+
Ok(guard) => {
447+
d.field("data", &&*guard);
448+
}
446449
Err(TryLockError::Poisoned(err)) => {
447-
f.debug_struct("Mutex").field("data", &&**err.get_ref()).finish()
450+
d.field("data", &&**err.get_ref());
448451
}
449452
Err(TryLockError::WouldBlock) => {
450453
struct LockedPlaceholder;
@@ -453,10 +456,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
453456
f.write_str("<locked>")
454457
}
455458
}
456-
457-
f.debug_struct("Mutex").field("data", &LockedPlaceholder).finish()
459+
d.field("data", &LockedPlaceholder);
458460
}
459461
}
462+
d.field("poisoned", &self.poison.get());
463+
d.finish_non_exhaustive()
460464
}
461465
}
462466

library/std/src/sync/rwlock.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,13 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock<T> {
422422
#[stable(feature = "rust1", since = "1.0.0")]
423423
impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
424424
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
425+
let mut d = f.debug_struct("RwLock");
425426
match self.try_read() {
426-
Ok(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(),
427+
Ok(guard) => {
428+
d.field("data", &&*guard);
429+
}
427430
Err(TryLockError::Poisoned(err)) => {
428-
f.debug_struct("RwLock").field("data", &&**err.get_ref()).finish()
431+
d.field("data", &&**err.get_ref());
429432
}
430433
Err(TryLockError::WouldBlock) => {
431434
struct LockedPlaceholder;
@@ -434,10 +437,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
434437
f.write_str("<locked>")
435438
}
436439
}
437-
438-
f.debug_struct("RwLock").field("data", &LockedPlaceholder).finish()
440+
d.field("data", &LockedPlaceholder);
439441
}
440442
}
443+
d.field("poisoned", &self.poison.get());
444+
d.finish_non_exhaustive()
441445
}
442446
}
443447

@@ -473,7 +477,7 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
473477
#[stable(feature = "std_debug", since = "1.16.0")]
474478
impl<T: fmt::Debug> fmt::Debug for RwLockReadGuard<'_, T> {
475479
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
476-
f.debug_struct("RwLockReadGuard").field("lock", &self.lock).finish()
480+
(**self).fmt(f)
477481
}
478482
}
479483

@@ -487,7 +491,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'_, T> {
487491
#[stable(feature = "std_debug", since = "1.16.0")]
488492
impl<T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'_, T> {
489493
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
490-
f.debug_struct("RwLockWriteGuard").field("lock", &self.lock).finish()
494+
(**self).fmt(f)
491495
}
492496
}
493497

library/std/src/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl From<c_int> for ExitStatus {
535535
impl fmt::Display for ExitStatus {
536536
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
537537
if let Some(code) = self.code() {
538-
write!(f, "exit code: {}", code)
538+
write!(f, "exit status: {}", code)
539539
} else if let Some(signal) = self.signal() {
540540
if self.core_dumped() {
541541
write!(f, "signal: {} (core dumped)", signal)

library/std/src/sys/unix/process/process_unix/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fn exitstatus_display_tests() {
99

1010
t(0x0000f, "signal: 15");
1111
t(0x0008b, "signal: 11 (core dumped)");
12-
t(0x00000, "exit code: 0");
13-
t(0x0ff00, "exit code: 255");
12+
t(0x00000, "exit status: 0");
13+
t(0x0ff00, "exit status: 255");
1414

1515
// On MacOS, 0x0137f is WIFCONTINUED, not WIFSTOPPED. Probably *BSD is similar.
1616
// https://github.com/rust-lang/rust/pull/82749#issuecomment-790525956

library/std/src/sys/wasi/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl FileType {
130130

131131
impl fmt::Debug for ReadDir {
132132
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133-
f.debug_struct("ReadDir").finish()
133+
f.debug_struct("ReadDir").finish_non_exhaustive()
134134
}
135135
}
136136

library/std/src/thread/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,10 @@ impl Thread {
11761176
#[stable(feature = "rust1", since = "1.0.0")]
11771177
impl fmt::Debug for Thread {
11781178
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1179-
f.debug_struct("Thread").field("id", &self.id()).field("name", &self.name()).finish()
1179+
f.debug_struct("Thread")
1180+
.field("id", &self.id())
1181+
.field("name", &self.name())
1182+
.finish_non_exhaustive()
11801183
}
11811184
}
11821185

library/test/src/helpers/exit_code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::process::ExitStatus;
44

55
#[cfg(not(unix))]
66
pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
7-
status.code().ok_or("received no exit code from child process".into())
7+
status.code().ok_or_else(|| "received no exit code from child process".into())
88
}
99

1010
#[cfg(unix)]

src/doc/rustc/src/targets/built-in.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ library built by the official Rust distributions. Most targets will need a
1212
system linker, and possibly other things.
1313

1414
[rustup]: https://github.com/rust-lang/rustup
15-
[rustup-cross]: https://github.com/rust-lang/rustup#cross-compilation
15+
[rustup-cross]: https://rust-lang.github.io/rustup/cross-compilation.html

src/test/ui/const-generics/issues/issue-56445.full.stderr src/test/ui/const-generics/issues/issue-56445-1.full.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/issue-56445.rs:3:27
2+
--> $DIR/issue-56445-1.rs:3:27
33
|
44
LL | #![cfg_attr(full, feature(const_generics))]
55
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #![cfg_attr(full, feature(const_generics))]
88
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
99

1010
error[E0771]: use of non-static lifetime `'a` in const generic
11-
--> $DIR/issue-56445.rs:8:26
11+
--> $DIR/issue-56445-1.rs:8:26
1212
|
1313
LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
1414
| ^^

0 commit comments

Comments
 (0)