Skip to content
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

Rollup of 10 pull requests #83573

Merged
merged 20 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
11e40ce
ExitStatus: print "exit status: {}" rather than "exit code: {}"
ijackson Mar 25, 2021
229d199
lazily calls some fns
klensy Mar 26, 2021
5b9bac2
format macro argument parsing fix
osa1 Mar 21, 2021
2afa4cc
Use DebugStruct::finish_non_exhaustive() in std.
m-ou-se Mar 27, 2021
d730153
Fix Debug implementation for RwLock{Read,Write}Guard.
m-ou-se Mar 27, 2021
7c01e6c
Derive Debug for io::Chain instead of manually implementing it.
m-ou-se Mar 27, 2021
5402abc
Improve Debug implementations of Mutex and RwLock.
m-ou-se Mar 27, 2021
5495ce0
Use detailed and shorter fs error explaination
pickfire Nov 25, 2020
d5bcdd3
Update rustup cross-compilation docs link
jonjensen Mar 27, 2021
0927580
Add regression tests for #56445
sjakobi Mar 27, 2021
1f33a6a
Rollup merge of #79399 - pickfire:patch-3, r=JohnTitor
JohnTitor Mar 27, 2021
973fb4b
Rollup merge of #83348 - osa1:issue83344, r=jackh726
JohnTitor Mar 27, 2021
3f41fdd
Rollup merge of #83462 - ijackson:exitstatus-message-wording, r=josht…
JohnTitor Mar 27, 2021
fa70398
Rollup merge of #83526 - klensy:lazy-too, r=petrochenkov
JohnTitor Mar 27, 2021
53cc806
Rollup merge of #83558 - m-ou-se:use-finish-non-exhaustive, r=jackh726
JohnTitor Mar 27, 2021
5dc29e1
Rollup merge of #83559 - m-ou-se:rwlock-guard-debug-fix, r=jackh726
JohnTitor Mar 27, 2021
8ad5f21
Rollup merge of #83560 - m-ou-se:io-chain-debug, r=sfackler
JohnTitor Mar 27, 2021
a800d7f
Rollup merge of #83561 - m-ou-se:lock-debug, r=jackh726
JohnTitor Mar 27, 2021
69acaf3
Rollup merge of #83567 - jonjensen:patch-1, r=GuillaumeGomez
JohnTitor Mar 27, 2021
1ad7c52
Rollup merge of #83569 - sjakobi:issue56445-regression-test, r=jackh726
JohnTitor Mar 27, 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
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl DiagnosticSpanLine {
h_end: usize,
) -> DiagnosticSpanLine {
DiagnosticSpanLine {
text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
text: sf.get_line(index).map_or_else(String::new, |l| l.into_owned()),
highlight_start: h_start,
highlight_end: h_end,
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ impl<'tcx> InstanceDef<'tcx> {
// drops of `Option::None` before LTO. We also respect the intent of
// `#[inline]` on `Drop::drop` implementations.
return ty.ty_adt_def().map_or(true, |adt_def| {
adt_def.destructor(tcx).map_or(adt_def.is_enum(), |dtor| {
tcx.codegen_fn_attrs(dtor.did).requests_inline()
})
adt_def.destructor(tcx).map_or_else(
|| adt_def.is_enum(),
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),
)
});
}
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ impl<'sess> OnDiskCache<'sess> {
) {
let mut current_diagnostics = self.current_diagnostics.borrow_mut();

let x = current_diagnostics.entry(dep_node_index).or_insert(Vec::new());
let x = current_diagnostics.entry(dep_node_index).or_default();

x.extend(Into::<Vec<_>>::into(diagnostics));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl OutlivesSuggestionBuilder {
debug!("Collected {:?}: {:?}", fr, outlived_fr);

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

/// Emit an intermediate note on the given `Diagnostic` if the involved regions are
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ impl<'a> Iterator for Parser<'a> {
Some(String(self.string(pos + 1)))
} else {
let arg = self.argument();
if let Some(end) = self.must_consume('}') {
let start = self.to_span_index(pos);
let end = self.to_span_index(end + 1);
if let Some(rbrace_byte_idx) = self.must_consume('}') {
let lbrace_inner_offset = self.to_span_index(pos);
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
if self.is_literal {
self.arg_places.push(start.to(end));
self.arg_places.push(
lbrace_inner_offset.to(InnerOffset(rbrace_inner_offset.0 + 1)),
);
}
}
Some(NextArgument(arg))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {

ExprKind::Call(ref callee, ref arguments) => {
self.resolve_expr(callee, Some(expr));
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or(Vec::new());
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
for (idx, argument) in arguments.iter().enumerate() {
// Constant arguments need to be treated as AnonConst since
// that is how they will be later lowered to HIR.
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
_ => None,
}
.map_or(String::new(), |res| format!("{} ", res.descr()));
.map_or_else(String::new, |res| format!("{} ", res.descr()));
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)))
};
(
Expand Down Expand Up @@ -1042,10 +1042,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
if let Some(span) = self.def_span(def_id) {
err.span_label(span, &format!("`{}` defined here", path_str));
}
let fields =
self.r.field_names.get(&def_id).map_or("/* fields */".to_string(), |fields| {
vec!["_"; fields.len()].join(", ")
});
let fields = self.r.field_names.get(&def_id).map_or_else(
|| "/* fields */".to_string(),
|fields| vec!["_"; fields.len()].join(", "),
);
err.span_suggestion(
span,
"use the tuple variant pattern syntax instead",
Expand Down
15 changes: 9 additions & 6 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
#[unstable(feature = "hash_raw_entry", issue = "56167")]
impl<K, V, S> Debug for RawEntryBuilderMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RawEntryBuilder").finish()
f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
}
}

Expand All @@ -1813,21 +1813,21 @@ impl<K: Debug, V: Debug, S> Debug for RawOccupiedEntryMut<'_, K, V, S> {
f.debug_struct("RawOccupiedEntryMut")
.field("key", self.key())
.field("value", self.get())
.finish()
.finish_non_exhaustive()
}
}

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

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

Expand Down Expand Up @@ -1867,7 +1867,10 @@ pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
#[stable(feature = "debug_hash_map", since = "1.12.0")]
impl<K: Debug, V: Debug> Debug for OccupiedEntry<'_, K, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedEntry").field("key", self.key()).field("value", self.get()).finish()
f.debug_struct("OccupiedEntry")
.field("key", self.key())
.field("value", self.get())
.finish_non_exhaustive()
}
}

Expand Down Expand Up @@ -1903,7 +1906,7 @@ impl<K: Debug, V: Debug> Debug for OccupiedError<'_, K, V> {
.field("key", self.entry.key())
.field("old_value", self.entry.get())
.field("new_value", &self.value)
.finish()
.finish_non_exhaustive()
}
}

Expand Down
8 changes: 4 additions & 4 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ impl fmt::Debug for Metadata {
.field("modified", &self.modified())
.field("accessed", &self.accessed())
.field("created", &self.created())
.finish()
.finish_non_exhaustive()
}
}

Expand Down Expand Up @@ -1677,9 +1677,9 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
/// This function will return an error in the following situations, but is not
/// limited to just these cases:
///
/// * The `from` path is not a file.
/// * The `from` file does not exist.
/// * The current process does not have the permission rights to access
/// * `from` is neither a regular file nor a symlink to a regular file.
/// * `from` does not exist.
/// * The current process does not have the permission rights to read
/// `from` or write `to`.
///
/// # Examples
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/linewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ where
"buffer",
&format_args!("{}/{}", self.inner.buffer().len(), self.inner.capacity()),
)
.finish()
.finish_non_exhaustive()
}
}
8 changes: 1 addition & 7 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ pub trait BufRead: Read {
///
/// [`chain`]: Read::chain
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Chain<T, U> {
first: T,
second: U,
Expand Down Expand Up @@ -2195,13 +2196,6 @@ impl<T, U> Chain<T, U> {
}
}

#[stable(feature = "std_debug", since = "1.16.0")]
impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Chain").field("t", &self.first).field("u", &self.second).finish()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Read, U: Read> Read for Chain<T, U> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ pub struct SyncLazy<T, F = fn() -> T> {
#[unstable(feature = "once_cell", issue = "74465")]
impl<T: fmt::Debug, F> fmt::Debug for SyncLazy<T, F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Lazy").field("cell", &self.cell).field("init", &"..").finish()
f.debug_struct("Lazy").field("cell", &self.cell).finish_non_exhaustive()
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl fmt::Debug for Child {
.field("stdin", &self.stdin)
.field("stdout", &self.stdout)
.field("stderr", &self.stderr)
.finish()
.finish_non_exhaustive()
}
}

Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ impl<T> Drop for Sender<T> {
#[stable(feature = "mpsc_debug", since = "1.8.0")]
impl<T> fmt::Debug for Sender<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Sender").finish()
f.debug_struct("Sender").finish_non_exhaustive()
}
}

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

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

Expand Down
12 changes: 8 additions & 4 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,13 @@ impl<T: ?Sized + Default> Default for Mutex<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("Mutex");
match self.try_lock() {
Ok(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(),
Ok(guard) => {
d.field("data", &&*guard);
}
Err(TryLockError::Poisoned(err)) => {
f.debug_struct("Mutex").field("data", &&**err.get_ref()).finish()
d.field("data", &&**err.get_ref());
}
Err(TryLockError::WouldBlock) => {
struct LockedPlaceholder;
Expand All @@ -453,10 +456,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
f.write_str("<locked>")
}
}

f.debug_struct("Mutex").field("data", &LockedPlaceholder).finish()
d.field("data", &LockedPlaceholder);
}
}
d.field("poisoned", &self.poison.get());
d.finish_non_exhaustive()
}
}

Expand Down
16 changes: 10 additions & 6 deletions library/std/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,13 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("RwLock");
match self.try_read() {
Ok(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(),
Ok(guard) => {
d.field("data", &&*guard);
}
Err(TryLockError::Poisoned(err)) => {
f.debug_struct("RwLock").field("data", &&**err.get_ref()).finish()
d.field("data", &&**err.get_ref());
}
Err(TryLockError::WouldBlock) => {
struct LockedPlaceholder;
Expand All @@ -434,10 +437,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
f.write_str("<locked>")
}
}

f.debug_struct("RwLock").field("data", &LockedPlaceholder).finish()
d.field("data", &LockedPlaceholder);
}
}
d.field("poisoned", &self.poison.get());
d.finish_non_exhaustive()
}
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl From<c_int> for ExitStatus {
impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(code) = self.code() {
write!(f, "exit code: {}", code)
write!(f, "exit status: {}", code)
} else if let Some(signal) = self.signal() {
if self.core_dumped() {
write!(f, "signal: {} (core dumped)", signal)
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/process/process_unix/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fn exitstatus_display_tests() {

t(0x0000f, "signal: 15");
t(0x0008b, "signal: 11 (core dumped)");
t(0x00000, "exit code: 0");
t(0x0ff00, "exit code: 255");
t(0x00000, "exit status: 0");
t(0x0ff00, "exit status: 255");

// On MacOS, 0x0137f is WIFCONTINUED, not WIFSTOPPED. Probably *BSD is similar.
// https://github.com/rust-lang/rust/pull/82749#issuecomment-790525956
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl FileType {

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

Expand Down
5 changes: 4 additions & 1 deletion library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,10 @@ impl Thread {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Thread {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Thread").field("id", &self.id()).field("name", &self.name()).finish()
f.debug_struct("Thread")
.field("id", &self.id())
.field("name", &self.name())
.finish_non_exhaustive()
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/test/src/helpers/exit_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process::ExitStatus;

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

#[cfg(unix)]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/targets/built-in.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ library built by the official Rust distributions. Most targets will need a
system linker, and possibly other things.

[rustup]: https://github.com/rust-lang/rustup
[rustup-cross]: https://github.com/rust-lang/rustup#cross-compilation
[rustup-cross]: https://rust-lang.github.io/rustup/cross-compilation.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-56445.rs:3:27
--> $DIR/issue-56445-1.rs:3:27
|
LL | #![cfg_attr(full, feature(const_generics))]
| ^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![cfg_attr(full, feature(const_generics))]
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

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