Rollup merge of #93950 - T-O-R-U-S:use-modern-formatting-for-format!-macros, r=Mark-Simulacrum
Use modern formatting for format! macros This updates the standard library's documentation to use the new format_args syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored). `eprintln!("{}", e)` becomes `eprintln!("{e}")`, but `eprintln!("{}", e.kind())` remains untouched.
This commit is contained in:
commit
5a7f09d9a3
177 changed files with 724 additions and 734 deletions
|
@ -83,7 +83,7 @@ pub use alloc_crate::alloc::*;
|
|||
///
|
||||
/// fn main() {
|
||||
/// let a = Box::new(4); // Allocates from the system allocator.
|
||||
/// println!("{}", a);
|
||||
/// println!("{a}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -57,10 +57,10 @@ fn test_debug() {
|
|||
\n { fn: \"std::rt::lang_start\", file: \"rust/rt.rs\", line: 400 },\
|
||||
\n]";
|
||||
|
||||
assert_eq!(format!("{:#?}", backtrace), expected);
|
||||
assert_eq!(format!("{backtrace:#?}"), expected);
|
||||
|
||||
// Format the backtrace a second time, just to make sure lazily resolved state is stable
|
||||
assert_eq!(format!("{:#?}", backtrace), expected);
|
||||
assert_eq!(format!("{backtrace:#?}"), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -91,5 +91,5 @@ fn test_frames() {
|
|||
|
||||
let mut iter = frames.iter().zip(expected.iter());
|
||||
|
||||
assert!(iter.all(|(f, e)| format!("{:#?}", f) == *e));
|
||||
assert!(iter.all(|(f, e)| format!("{f:#?}") == *e));
|
||||
}
|
||||
|
|
|
@ -109,8 +109,8 @@ use crate::sys;
|
|||
/// let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
|
||||
/// for &book in &to_find {
|
||||
/// match book_reviews.get(book) {
|
||||
/// Some(review) => println!("{}: {}", book, review),
|
||||
/// None => println!("{} is unreviewed.", book)
|
||||
/// Some(review) => println!("{book}: {review}"),
|
||||
/// None => println!("{book} is unreviewed.")
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
@ -119,7 +119,7 @@ use crate::sys;
|
|||
///
|
||||
/// // Iterate over everything.
|
||||
/// for (book, review) in &book_reviews {
|
||||
/// println!("{}: \"{}\"", book, review);
|
||||
/// println!("{book}: \"{review}\"");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -199,7 +199,7 @@ use crate::sys;
|
|||
///
|
||||
/// // Use derived implementation to print the status of the vikings.
|
||||
/// for (viking, health) in &vikings {
|
||||
/// println!("{:?} has {} hp", viking, health);
|
||||
/// println!("{viking:?} has {health} hp");
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
|
@ -341,7 +341,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// ]);
|
||||
///
|
||||
/// for key in map.keys() {
|
||||
/// println!("{}", key);
|
||||
/// println!("{key}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -392,7 +392,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// ]);
|
||||
///
|
||||
/// for val in map.values() {
|
||||
/// println!("{}", val);
|
||||
/// println!("{val}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -419,7 +419,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// }
|
||||
///
|
||||
/// for val in map.values() {
|
||||
/// println!("{}", val);
|
||||
/// println!("{val}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
||||
|
@ -470,7 +470,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// ]);
|
||||
///
|
||||
/// for (key, val) in map.iter() {
|
||||
/// println!("key: {} val: {}", key, val);
|
||||
/// println!("key: {key} val: {val}");
|
||||
/// }
|
||||
/// ```
|
||||
#[rustc_lint_query_instability]
|
||||
|
@ -500,7 +500,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// }
|
||||
///
|
||||
/// for (key, val) in &map {
|
||||
/// println!("key: {} val: {}", key, val);
|
||||
/// println!("key: {key} val: {val}");
|
||||
/// }
|
||||
/// ```
|
||||
#[rustc_lint_query_instability]
|
||||
|
|
|
@ -515,10 +515,10 @@ fn test_show() {
|
|||
map.insert(1, 2);
|
||||
map.insert(3, 4);
|
||||
|
||||
let map_str = format!("{:?}", map);
|
||||
let map_str = format!("{map:?}");
|
||||
|
||||
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
|
||||
assert_eq!(format!("{:?}", empty), "{}");
|
||||
assert_eq!(format!("{empty:?}"), "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -702,7 +702,7 @@ fn test_entry_take_doesnt_corrupt() {
|
|||
// Test for #19292
|
||||
fn check(m: &HashMap<i32, ()>) {
|
||||
for k in m.keys() {
|
||||
assert!(m.contains_key(k), "{} is in keys() but not in the map?", k);
|
||||
assert!(m.contains_key(k), "{k} is in keys() but not in the map?");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ use super::map::{map_try_reserve_error, RandomState};
|
|||
///
|
||||
/// // Iterate over everything.
|
||||
/// for book in &books {
|
||||
/// println!("{}", book);
|
||||
/// println!("{book}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -91,7 +91,7 @@ use super::map::{map_try_reserve_error, RandomState};
|
|||
///
|
||||
/// // Use derived implementation to print the vikings.
|
||||
/// for x in &vikings {
|
||||
/// println!("{:?}", x);
|
||||
/// println!("{x:?}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -181,7 +181,7 @@ impl<T, S> HashSet<T, S> {
|
|||
///
|
||||
/// // Will print in an arbitrary order.
|
||||
/// for x in set.iter() {
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
|
@ -244,7 +244,7 @@ impl<T, S> HashSet<T, S> {
|
|||
///
|
||||
/// // print 1, 2, 3 in an arbitrary order
|
||||
/// for i in set.drain() {
|
||||
/// println!("{}", i);
|
||||
/// println!("{i}");
|
||||
/// }
|
||||
///
|
||||
/// assert!(set.is_empty());
|
||||
|
@ -525,7 +525,7 @@ where
|
|||
///
|
||||
/// // Can be seen as `a - b`.
|
||||
/// for x in a.difference(&b) {
|
||||
/// println!("{}", x); // Print 1
|
||||
/// println!("{x}"); // Print 1
|
||||
/// }
|
||||
///
|
||||
/// let diff: HashSet<_> = a.difference(&b).collect();
|
||||
|
@ -555,7 +555,7 @@ where
|
|||
///
|
||||
/// // Print 1, 4 in arbitrary order.
|
||||
/// for x in a.symmetric_difference(&b) {
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// let diff1: HashSet<_> = a.symmetric_difference(&b).collect();
|
||||
|
@ -586,7 +586,7 @@ where
|
|||
///
|
||||
/// // Print 2, 3 in arbitrary order.
|
||||
/// for x in a.intersection(&b) {
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// let intersection: HashSet<_> = a.intersection(&b).collect();
|
||||
|
@ -615,7 +615,7 @@ where
|
|||
///
|
||||
/// // Print 1, 2, 3, 4 in arbitrary order.
|
||||
/// for x in a.union(&b) {
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// let union: HashSet<_> = a.union(&b).collect();
|
||||
|
@ -1451,7 +1451,7 @@ impl<T, S> IntoIterator for HashSet<T, S> {
|
|||
///
|
||||
/// // Will print in an arbitrary order.
|
||||
/// for x in &v {
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
|
|
|
@ -301,10 +301,10 @@ fn test_show() {
|
|||
set.insert(1);
|
||||
set.insert(2);
|
||||
|
||||
let set_str = format!("{:?}", set);
|
||||
let set_str = format!("{set:?}");
|
||||
|
||||
assert!(set_str == "{1, 2}" || set_str == "{2, 1}");
|
||||
assert_eq!(format!("{:?}", empty), "{}");
|
||||
assert_eq!(format!("{empty:?}"), "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -199,7 +199,7 @@
|
|||
//! ```
|
||||
//! let vec = vec![1, 2, 3, 4];
|
||||
//! for x in vec.iter() {
|
||||
//! println!("vec contained {}", x);
|
||||
//! println!("vec contained {x:?}");
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -246,7 +246,7 @@
|
|||
//! ```
|
||||
//! let vec = vec![1, 2, 3, 4];
|
||||
//! for x in vec.iter().rev() {
|
||||
//! println!("vec contained {}", x);
|
||||
//! println!("vec contained {x:?}");
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -306,7 +306,7 @@
|
|||
//!
|
||||
//! println!("Number of occurrences of each character");
|
||||
//! for (char, count) in &count {
|
||||
//! println!("{}: {}", char, count);
|
||||
//! println!("{char}: {count}");
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -339,7 +339,7 @@
|
|||
//! // Check if they're sober enough to have another beer.
|
||||
//! if person.blood_alcohol > 0.3 {
|
||||
//! // Too drunk... for now.
|
||||
//! println!("Sorry {}, I have to cut you off", id);
|
||||
//! println!("Sorry {id}, I have to cut you off");
|
||||
//! } else {
|
||||
//! // Have another!
|
||||
//! person.blood_alcohol += 0.1;
|
||||
|
|
|
@ -118,7 +118,7 @@ pub struct VarsOs {
|
|||
/// // We will iterate through the references to the element returned by
|
||||
/// // env::vars();
|
||||
/// for (key, value) in env::vars() {
|
||||
/// println!("{}: {}", key, value);
|
||||
/// println!("{key}: {value}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -148,7 +148,7 @@ pub fn vars() -> Vars {
|
|||
/// // We will iterate through the references to the element returned by
|
||||
/// // env::vars_os();
|
||||
/// for (key, value) in env::vars_os() {
|
||||
/// println!("{:?}: {:?}", key, value);
|
||||
/// println!("{key:?}: {value:?}");
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
|
@ -212,8 +212,8 @@ impl fmt::Debug for VarsOs {
|
|||
///
|
||||
/// let key = "HOME";
|
||||
/// match env::var(key) {
|
||||
/// Ok(val) => println!("{}: {:?}", key, val),
|
||||
/// Err(e) => println!("couldn't interpret {}: {}", key, e),
|
||||
/// Ok(val) => println!("{key}: {val:?}"),
|
||||
/// Err(e) => println!("couldn't interpret {key}: {e}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
@ -252,8 +252,8 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
|
|||
///
|
||||
/// let key = "HOME";
|
||||
/// match env::var_os(key) {
|
||||
/// Some(val) => println!("{}: {:?}", key, val),
|
||||
/// None => println!("{} is not defined in the environment.", key)
|
||||
/// Some(val) => println!("{key}: {val:?}"),
|
||||
/// None => println!("{key} is not defined in the environment.")
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
|
@ -343,7 +343,7 @@ pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
|
|||
|
||||
fn _set_var(key: &OsStr, value: &OsStr) {
|
||||
os_imp::setenv(key, value).unwrap_or_else(|e| {
|
||||
panic!("failed to set environment variable `{:?}` to `{:?}`: {}", key, value, e)
|
||||
panic!("failed to set environment variable `{key:?}` to `{value:?}`: {e}")
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ pub fn remove_var<K: AsRef<OsStr>>(key: K) {
|
|||
|
||||
fn _remove_var(key: &OsStr) {
|
||||
os_imp::unsetenv(key)
|
||||
.unwrap_or_else(|e| panic!("failed to remove environment variable `{:?}`: {}", key, e))
|
||||
.unwrap_or_else(|e| panic!("failed to remove environment variable `{key:?}`: {e}"))
|
||||
}
|
||||
|
||||
/// An iterator that splits an environment variable into paths according to
|
||||
|
@ -421,7 +421,7 @@ pub struct SplitPaths<'a> {
|
|||
/// println!("'{}'", path.display());
|
||||
/// }
|
||||
/// }
|
||||
/// None => println!("{} is not defined in the environment.", key)
|
||||
/// None => println!("{key} is not defined in the environment.")
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
@ -684,7 +684,7 @@ pub fn temp_dir() -> PathBuf {
|
|||
/// match env::current_exe() {
|
||||
/// Ok(exe_path) => println!("Path of this executable is: {}",
|
||||
/// exe_path.display()),
|
||||
/// Err(e) => println!("failed to get current exe path: {}", e),
|
||||
/// Err(e) => println!("failed to get current exe path: {e}"),
|
||||
/// };
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
@ -755,7 +755,7 @@ pub struct ArgsOs {
|
|||
///
|
||||
/// // Prints each argument on a separate line
|
||||
/// for argument in env::args() {
|
||||
/// println!("{}", argument);
|
||||
/// println!("{argument}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
@ -790,7 +790,7 @@ pub fn args() -> Args {
|
|||
///
|
||||
/// // Prints each argument on a separate line
|
||||
/// for argument in env::args_os() {
|
||||
/// println!("{:?}", argument);
|
||||
/// println!("{argument:?}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
|
|
@ -96,7 +96,7 @@ pub trait Error: Debug + Display {
|
|||
/// fn main() {
|
||||
/// match get_super_error() {
|
||||
/// Err(e) => {
|
||||
/// println!("Error: {}", e);
|
||||
/// println!("Error: {e}");
|
||||
/// println!("Caused by: {}", e.source().unwrap());
|
||||
/// }
|
||||
/// _ => println!("No error"),
|
||||
|
@ -139,7 +139,7 @@ pub trait Error: Debug + Display {
|
|||
/// ```
|
||||
/// if let Err(e) = "xc".parse::<u32>() {
|
||||
/// // Print `e` itself, no need for description().
|
||||
/// eprintln!("Error: {}", e);
|
||||
/// eprintln!("Error: {e}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -1074,7 +1074,7 @@ impl<E> Report<E> {
|
|||
///
|
||||
/// let error = SuperError { source: SuperErrorSideKick };
|
||||
/// let report = Report::new(error).pretty(true);
|
||||
/// eprintln!("Error: {:?}", report);
|
||||
/// eprintln!("Error: {report:?}");
|
||||
/// ```
|
||||
///
|
||||
/// This example produces the following output:
|
||||
|
@ -1135,7 +1135,7 @@ impl<E> Report<E> {
|
|||
/// let source = SuperErrorSideKick { source };
|
||||
/// let error = SuperError { source };
|
||||
/// let report = Report::new(error).pretty(true);
|
||||
/// eprintln!("Error: {:?}", report);
|
||||
/// eprintln!("Error: {report:?}");
|
||||
/// ```
|
||||
///
|
||||
/// This example produces the following output:
|
||||
|
@ -1210,7 +1210,7 @@ impl<E> Report<E> {
|
|||
/// let source = SuperErrorSideKick::new();
|
||||
/// let error = SuperError { source };
|
||||
/// let report = Report::new(error).pretty(true).show_backtrace(true);
|
||||
/// eprintln!("Error: {:?}", report);
|
||||
/// eprintln!("Error: {report:?}");
|
||||
/// ```
|
||||
///
|
||||
/// This example produces something similar to the following output:
|
||||
|
@ -1267,7 +1267,7 @@ where
|
|||
let sources = self.error.source().into_iter().flat_map(<dyn Error>::chain);
|
||||
|
||||
for cause in sources {
|
||||
write!(f, ": {}", cause)?;
|
||||
write!(f, ": {cause}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1278,7 +1278,7 @@ where
|
|||
fn fmt_multiline(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let error = &self.error;
|
||||
|
||||
write!(f, "{}", error)?;
|
||||
write!(f, "{error}")?;
|
||||
|
||||
if let Some(cause) = error.source() {
|
||||
write!(f, "\n\nCaused by:")?;
|
||||
|
@ -1289,9 +1289,9 @@ where
|
|||
writeln!(f)?;
|
||||
let mut indented = Indented { inner: f };
|
||||
if multiple {
|
||||
write!(indented, "{: >4}: {}", ind, error)?;
|
||||
write!(indented, "{ind: >4}: {error}")?;
|
||||
} else {
|
||||
write!(indented, " {}", error)?;
|
||||
write!(indented, " {error}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1333,7 +1333,7 @@ impl Report<Box<dyn Error>> {
|
|||
let sources = self.error.source().into_iter().flat_map(<dyn Error>::chain);
|
||||
|
||||
for cause in sources {
|
||||
write!(f, ": {}", cause)?;
|
||||
write!(f, ": {cause}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1344,7 +1344,7 @@ impl Report<Box<dyn Error>> {
|
|||
fn fmt_multiline(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let error = &self.error;
|
||||
|
||||
write!(f, "{}", error)?;
|
||||
write!(f, "{error}")?;
|
||||
|
||||
if let Some(cause) = error.source() {
|
||||
write!(f, "\n\nCaused by:")?;
|
||||
|
@ -1355,9 +1355,9 @@ impl Report<Box<dyn Error>> {
|
|||
writeln!(f)?;
|
||||
let mut indented = Indented { inner: f };
|
||||
if multiple {
|
||||
write!(indented, "{: >4}: {}", ind, error)?;
|
||||
write!(indented, "{ind: >4}: {error}")?;
|
||||
} else {
|
||||
write!(indented, " {}", error)?;
|
||||
write!(indented, " {error}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ Stack backtrace:
|
|||
error.backtrace = Some(trace);
|
||||
let report = Report::new(error).pretty(true).show_backtrace(true);
|
||||
|
||||
println!("Error: {}", report);
|
||||
println!("Error: {report}");
|
||||
assert_eq!(expected.trim_end(), report.to_string());
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ Stack backtrace:
|
|||
let error = GenericError::new_with_source("Error with two sources", error);
|
||||
let report = Report::new(error).pretty(true).show_backtrace(true);
|
||||
|
||||
println!("Error: {}", report);
|
||||
println!("Error: {report}");
|
||||
assert_eq!(expected.trim_end(), report.to_string());
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ Caused by:
|
|||
1: The message goes on and on.";
|
||||
|
||||
let actual = report.to_string();
|
||||
println!("{}", actual);
|
||||
println!("{actual}");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
|
|
|
@ -1120,7 +1120,7 @@ impl fmt::Display for FromBytesWithNulError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(self.description())?;
|
||||
if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind {
|
||||
write!(f, " at byte pos {}", pos)?;
|
||||
write!(f, " at byte pos {pos}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1134,7 +1134,7 @@ impl fmt::Display for FromVecWithNulError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.error_kind {
|
||||
FromBytesWithNulErrorKind::InteriorNul(pos) => {
|
||||
write!(f, "data provided contains an interior nul byte at pos {}", pos)
|
||||
write!(f, "data provided contains an interior nul byte at pos {pos}")
|
||||
}
|
||||
FromBytesWithNulErrorKind::NotNulTerminated => {
|
||||
write!(f, "data provided is not nul terminated")
|
||||
|
|
|
@ -35,7 +35,7 @@ fn build_with_zero2() {
|
|||
#[test]
|
||||
fn formatted() {
|
||||
let s = CString::new(&b"abc\x01\x02\n\xE2\x80\xA6\xFF"[..]).unwrap();
|
||||
assert_eq!(format!("{:?}", s), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
|
||||
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1123,7 +1123,7 @@ impl Metadata {
|
|||
/// let metadata = fs::metadata("foo.txt")?;
|
||||
///
|
||||
/// if let Ok(time) = metadata.modified() {
|
||||
/// println!("{:?}", time);
|
||||
/// println!("{time:?}");
|
||||
/// } else {
|
||||
/// println!("Not supported on this platform");
|
||||
/// }
|
||||
|
@ -1158,7 +1158,7 @@ impl Metadata {
|
|||
/// let metadata = fs::metadata("foo.txt")?;
|
||||
///
|
||||
/// if let Ok(time) = metadata.accessed() {
|
||||
/// println!("{:?}", time);
|
||||
/// println!("{time:?}");
|
||||
/// } else {
|
||||
/// println!("Not supported on this platform");
|
||||
/// }
|
||||
|
@ -1190,7 +1190,7 @@ impl Metadata {
|
|||
/// let metadata = fs::metadata("foo.txt")?;
|
||||
///
|
||||
/// if let Ok(time) = metadata.created() {
|
||||
/// println!("{:?}", time);
|
||||
/// println!("{time:?}");
|
||||
/// } else {
|
||||
/// println!("Not supported on this platform or filesystem");
|
||||
/// }
|
||||
|
|
|
@ -30,7 +30,7 @@ macro_rules! check {
|
|||
($e:expr) => {
|
||||
match $e {
|
||||
Ok(t) => t,
|
||||
Err(e) => panic!("{} failed with: {}", stringify!($e), e),
|
||||
Err(e) => panic!("{} failed with: {e}", stringify!($e)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ fn file_test_directoryinfo_readdir() {
|
|||
check!(fs::create_dir(dir));
|
||||
let prefix = "foo";
|
||||
for n in 0..3 {
|
||||
let f = dir.join(&format!("{}.txt", n));
|
||||
let f = dir.join(&format!("{n}.txt"));
|
||||
let mut w = check!(File::create(&f));
|
||||
let msg_str = format!("{}{}", prefix, n.to_string());
|
||||
let msg = msg_str.as_bytes();
|
||||
|
@ -1329,7 +1329,7 @@ fn dir_entry_methods() {
|
|||
assert!(file.file_type().unwrap().is_file());
|
||||
assert!(file.metadata().unwrap().is_file());
|
||||
}
|
||||
f => panic!("unknown file name: {:?}", f),
|
||||
f => panic!("unknown file name: {f:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1340,7 +1340,7 @@ fn dir_entry_debug() {
|
|||
File::create(&tmpdir.join("b")).unwrap();
|
||||
let mut read_dir = tmpdir.path().read_dir().unwrap();
|
||||
let dir_entry = read_dir.next().unwrap().unwrap();
|
||||
let actual = format!("{:?}", dir_entry);
|
||||
let actual = format!("{dir_entry:?}");
|
||||
let expected = format!("DirEntry({:?})", dir_entry.0.path());
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
@ -1409,7 +1409,7 @@ fn metadata_access_times() {
|
|||
|| e1.kind() == ErrorKind::Unsupported
|
||||
&& e2.kind() == ErrorKind::Unsupported => {}
|
||||
(a, b) => {
|
||||
panic!("creation time must be always supported or not supported: {:?} {:?}", a, b,)
|
||||
panic!("creation time must be always supported or not supported: {a:?} {b:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ use crate::mem::MaybeUninit;
|
|||
///
|
||||
/// let mut line = String::new();
|
||||
/// let len = reader.read_line(&mut line)?;
|
||||
/// println!("First line is {} bytes long", len);
|
||||
/// println!("First line is {len} bytes long");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -457,7 +457,7 @@ impl From<ErrorKind> for Error {
|
|||
///
|
||||
/// let not_found = ErrorKind::NotFound;
|
||||
/// let error = Error::from(not_found);
|
||||
/// assert_eq!("entity not found", format!("{}", error));
|
||||
/// assert_eq!("entity not found", format!("{error}"));
|
||||
/// ```
|
||||
#[inline]
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
|
@ -561,7 +561,7 @@ impl Error {
|
|||
/// use std::io::Error;
|
||||
///
|
||||
/// let os_error = Error::last_os_error();
|
||||
/// println!("last OS error: {:?}", os_error);
|
||||
/// println!("last OS error: {os_error:?}");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
|
@ -618,7 +618,7 @@ impl Error {
|
|||
///
|
||||
/// fn print_os_error(err: &Error) {
|
||||
/// if let Some(raw_os_err) = err.raw_os_error() {
|
||||
/// println!("raw OS error: {:?}", raw_os_err);
|
||||
/// println!("raw OS error: {raw_os_err:?}");
|
||||
/// } else {
|
||||
/// println!("Not an OS error");
|
||||
/// }
|
||||
|
@ -657,7 +657,7 @@ impl Error {
|
|||
///
|
||||
/// fn print_error(err: &Error) {
|
||||
/// if let Some(inner_err) = err.get_ref() {
|
||||
/// println!("Inner error: {:?}", inner_err);
|
||||
/// println!("Inner error: {inner_err:?}");
|
||||
/// } else {
|
||||
/// println!("No inner error");
|
||||
/// }
|
||||
|
@ -731,7 +731,7 @@ impl Error {
|
|||
///
|
||||
/// fn print_error(err: &Error) {
|
||||
/// if let Some(inner_err) = err.get_ref() {
|
||||
/// println!("Inner error: {}", inner_err);
|
||||
/// println!("Inner error: {inner_err}");
|
||||
/// } else {
|
||||
/// println!("No inner error");
|
||||
/// }
|
||||
|
@ -770,7 +770,7 @@ impl Error {
|
|||
///
|
||||
/// fn print_error(err: Error) {
|
||||
/// if let Some(inner_err) = err.into_inner() {
|
||||
/// println!("Inner error: {}", inner_err);
|
||||
/// println!("Inner error: {inner_err}");
|
||||
/// } else {
|
||||
/// println!("No inner error");
|
||||
/// }
|
||||
|
@ -852,7 +852,7 @@ impl fmt::Display for Error {
|
|||
match self.repr.data() {
|
||||
ErrorData::Os(code) => {
|
||||
let detail = sys::os::error_string(code);
|
||||
write!(fmt, "{} (os error {})", detail, code)
|
||||
write!(fmt, "{detail} (os error {code})")
|
||||
}
|
||||
ErrorData::Custom(ref c) => c.error.fmt(fmt),
|
||||
ErrorData::Simple(kind) => write!(fmt, "{}", kind.as_str()),
|
||||
|
|
|
@ -161,8 +161,7 @@ impl Repr {
|
|||
// only run in libstd's tests, unless the user uses -Zbuild-std)
|
||||
debug_assert!(
|
||||
matches!(res.data(), ErrorData::Os(c) if c == code),
|
||||
"repr(os) encoding failed for {}",
|
||||
code,
|
||||
"repr(os) encoding failed for {code}"
|
||||
);
|
||||
res
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ fn test_debug_error() {
|
|||
}}",
|
||||
code, kind, msg
|
||||
);
|
||||
assert_eq!(format!("{:?}", err), expected);
|
||||
assert_eq!(format!("{err:?}"), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -65,8 +65,8 @@ fn test_const() {
|
|||
|
||||
assert_eq!(E.kind(), ErrorKind::NotFound);
|
||||
assert_eq!(E.to_string(), "hello");
|
||||
assert!(format!("{:?}", E).contains("\"hello\""));
|
||||
assert!(format!("{:?}", E).contains("NotFound"));
|
||||
assert!(format!("{E:?}").contains("\"hello\""));
|
||||
assert!(format!("{E:?}").contains("NotFound"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -101,7 +101,7 @@ fn test_simple_message_packing() {
|
|||
let e = &$err;
|
||||
// Check that the public api is right.
|
||||
assert_eq!(e.kind(), $kind);
|
||||
assert!(format!("{:?}", e).contains($msg));
|
||||
assert!(format!("{e:?}").contains($msg));
|
||||
// and we got what we expected
|
||||
assert_matches!(
|
||||
e.repr.data(),
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
//! // read a line into buffer
|
||||
//! reader.read_line(&mut buffer)?;
|
||||
//!
|
||||
//! println!("{}", buffer);
|
||||
//! println!("{buffer}");
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
@ -1035,7 +1035,7 @@ pub trait Read {
|
|||
/// fn main() -> io::Result<()> {
|
||||
/// let stdin = io::read_to_string(io::stdin())?;
|
||||
/// println!("Stdin was:");
|
||||
/// println!("{}", stdin);
|
||||
/// println!("{stdin}");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -1761,7 +1761,7 @@ pub trait Seek {
|
|||
/// .open("foo.txt").unwrap();
|
||||
///
|
||||
/// let hello = "Hello!\n";
|
||||
/// write!(f, "{}", hello).unwrap();
|
||||
/// write!(f, "{hello}").unwrap();
|
||||
/// f.rewind().unwrap();
|
||||
///
|
||||
/// let mut buf = String::new();
|
||||
|
@ -1804,7 +1804,7 @@ pub trait Seek {
|
|||
/// let mut f = File::open("foo.txt")?;
|
||||
///
|
||||
/// let len = f.stream_len()?;
|
||||
/// println!("The file is currently {} bytes long", len);
|
||||
/// println!("The file is currently {len} bytes long");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -1988,7 +1988,7 @@ pub trait BufRead: Read {
|
|||
/// let buffer = stdin.fill_buf().unwrap();
|
||||
///
|
||||
/// // work with buffer
|
||||
/// println!("{:?}", buffer);
|
||||
/// println!("{buffer:?}");
|
||||
///
|
||||
/// // ensure the bytes we worked with aren't returned again later
|
||||
/// let length = buffer.len();
|
||||
|
@ -2042,7 +2042,7 @@ pub trait BufRead: Read {
|
|||
/// let mut line = String::new();
|
||||
/// stdin.read_line(&mut line).unwrap();
|
||||
/// // work with line
|
||||
/// println!("{:?}", line);
|
||||
/// println!("{line:?}");
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "buf_read_has_data_left", reason = "recently added", issue = "86423")]
|
||||
|
|
|
@ -349,10 +349,10 @@ impl Stdin {
|
|||
/// let mut input = String::new();
|
||||
/// match io::stdin().read_line(&mut input) {
|
||||
/// Ok(n) => {
|
||||
/// println!("{} bytes read", n);
|
||||
/// println!("{}", input);
|
||||
/// println!("{n} bytes read");
|
||||
/// println!("{input}");
|
||||
/// }
|
||||
/// Err(error) => println!("error: {}", error),
|
||||
/// Err(error) => println!("error: {error}"),
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -953,7 +953,7 @@ where
|
|||
}
|
||||
|
||||
if let Err(e) = global_s().write_fmt(args) {
|
||||
panic!("failed printing to {}: {}", label, e);
|
||||
panic!("failed printing to {label}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ mod as_keyword {}
|
|||
/// }
|
||||
///
|
||||
/// assert_eq!(last, 12);
|
||||
/// println!("{}", last);
|
||||
/// println!("{last}");
|
||||
/// ```
|
||||
///
|
||||
/// A break expression is normally associated with the innermost loop enclosing the
|
||||
|
@ -72,10 +72,10 @@ mod as_keyword {}
|
|||
///
|
||||
///```rust
|
||||
/// 'outer: for i in 1..=5 {
|
||||
/// println!("outer iteration (i): {}", i);
|
||||
/// println!("outer iteration (i): {i}");
|
||||
///
|
||||
/// '_inner: for j in 1..=200 {
|
||||
/// println!(" inner iteration (j): {}", j);
|
||||
/// println!(" inner iteration (j): {j}");
|
||||
/// if j >= 3 {
|
||||
/// // breaks from inner loop, lets outer loop continue.
|
||||
/// break;
|
||||
|
@ -106,7 +106,7 @@ mod as_keyword {}
|
|||
/// };
|
||||
/// // first number in Fibonacci sequence over 10:
|
||||
/// assert_eq!(result, 13);
|
||||
/// println!("{}", result);
|
||||
/// println!("{result}");
|
||||
/// ```
|
||||
///
|
||||
/// For more details consult the [Reference on "break expression"] and the [Reference on "break and
|
||||
|
@ -200,7 +200,7 @@ mod const_keyword {}
|
|||
/// if number % 2 == 0 {
|
||||
/// continue;
|
||||
/// }
|
||||
/// println!("{}", number);
|
||||
/// println!("{number}");
|
||||
/// }
|
||||
///```
|
||||
///
|
||||
|
@ -515,7 +515,7 @@ mod fn_keyword {}
|
|||
/// }
|
||||
///
|
||||
/// for i in std::iter::repeat(5) {
|
||||
/// println!("turns out {} never stops being 5", i);
|
||||
/// println!("turns out {i} never stops being 5");
|
||||
/// break; // would loop forever otherwise
|
||||
/// }
|
||||
///
|
||||
|
@ -776,7 +776,7 @@ mod in_keyword {}
|
|||
/// let shadowing_example = true;
|
||||
/// let shadowing_example = 123.4;
|
||||
/// let shadowing_example = shadowing_example as u32;
|
||||
/// let mut shadowing_example = format!("cool! {}", shadowing_example);
|
||||
/// let mut shadowing_example = format!("cool! {shadowing_example}");
|
||||
/// shadowing_example += " something else!"; // not shadowing
|
||||
/// ```
|
||||
///
|
||||
|
@ -805,7 +805,7 @@ mod let_keyword {}
|
|||
/// let mut counter = 0;
|
||||
///
|
||||
/// while counter < 10 {
|
||||
/// println!("{}", counter);
|
||||
/// println!("{counter}");
|
||||
/// counter += 1;
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -836,7 +836,7 @@ mod let_keyword {}
|
|||
/// if i == 10 {
|
||||
/// counter = None;
|
||||
/// } else {
|
||||
/// println!("{}", i);
|
||||
/// println!("{i}");
|
||||
/// counter = Some (i + 1);
|
||||
/// }
|
||||
/// }
|
||||
|
@ -866,7 +866,7 @@ mod while_keyword {}
|
|||
///
|
||||
/// let mut i = 1;
|
||||
/// loop {
|
||||
/// println!("i is {}", i);
|
||||
/// println!("i is {i}");
|
||||
/// if i > 100 {
|
||||
/// break;
|
||||
/// }
|
||||
|
@ -920,8 +920,8 @@ mod loop_keyword {}
|
|||
///
|
||||
/// let a_number = Option::Some(10);
|
||||
/// match a_number {
|
||||
/// Some(x) if x <= 5 => println!("0 to 5 num = {}", x),
|
||||
/// Some(x @ 6..=10) => println!("6 to 10 num = {}", x),
|
||||
/// Some(x) if x <= 5 => println!("0 to 5 num = {x}"),
|
||||
/// Some(x @ 6..=10) => println!("6 to 10 num = {x}"),
|
||||
/// None => panic!(),
|
||||
/// // all other numbers
|
||||
/// _ => panic!(),
|
||||
|
@ -940,8 +940,8 @@ mod loop_keyword {}
|
|||
///
|
||||
/// let get_inner = Outer::Double(None, Some(String::new()));
|
||||
/// match get_inner {
|
||||
/// Outer::Double(None, Some(st)) => println!("{}", st),
|
||||
/// Outer::Single(opt) => println!("{:?}", opt),
|
||||
/// Outer::Double(None, Some(st)) => println!("{st}"),
|
||||
/// Outer::Single(opt) => println!("{opt:?}"),
|
||||
/// _ => panic!(),
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -988,7 +988,7 @@ mod mod_keyword {}
|
|||
///
|
||||
/// ```rust
|
||||
/// let data = vec![1, 2, 3];
|
||||
/// let closure = move || println!("captured {:?} by value", data);
|
||||
/// let closure = move || println!("captured {data:?} by value");
|
||||
///
|
||||
/// // data is no longer available, it is owned by the closure
|
||||
/// ```
|
||||
|
@ -1001,7 +1001,7 @@ mod mod_keyword {}
|
|||
/// ```rust
|
||||
/// fn create_fn() -> impl Fn() {
|
||||
/// let text = "Fn".to_owned();
|
||||
/// move || println!("This is a: {}", text)
|
||||
/// move || println!("This is a: {text}")
|
||||
/// }
|
||||
///
|
||||
/// let fn_plain = create_fn();
|
||||
|
@ -1014,7 +1014,7 @@ mod mod_keyword {}
|
|||
/// let data = vec![1, 2, 3];
|
||||
///
|
||||
/// std::thread::spawn(move || {
|
||||
/// println!("captured {:?} by value", data)
|
||||
/// println!("captured {data:?} by value")
|
||||
/// }).join().unwrap();
|
||||
///
|
||||
/// // data was moved to the spawned thread, so we cannot use it here
|
||||
|
@ -1025,7 +1025,7 @@ mod mod_keyword {}
|
|||
/// ```rust
|
||||
/// let capture = "hello".to_owned();
|
||||
/// let block = async move {
|
||||
/// println!("rust says {} from async block", capture);
|
||||
/// println!("rust says {capture} from async block");
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
|
@ -1124,7 +1124,7 @@ mod pub_keyword {}
|
|||
/// let maybe_name = Some(String::from("Alice"));
|
||||
/// // The variable 'maybe_name' is consumed here ...
|
||||
/// match maybe_name {
|
||||
/// Some(n) => println!("Hello, {}", n),
|
||||
/// Some(n) => println!("Hello, {n}"),
|
||||
/// _ => println!("Hello, world"),
|
||||
/// }
|
||||
/// // ... and is now unavailable.
|
||||
|
@ -1138,7 +1138,7 @@ mod pub_keyword {}
|
|||
/// let maybe_name = Some(String::from("Alice"));
|
||||
/// // Using `ref`, the value is borrowed, not moved ...
|
||||
/// match maybe_name {
|
||||
/// Some(ref n) => println!("Hello, {}", n),
|
||||
/// Some(ref n) => println!("Hello, {n}"),
|
||||
/// _ => println!("Hello, world"),
|
||||
/// }
|
||||
/// // ... so it's available here!
|
||||
|
@ -1423,7 +1423,7 @@ mod self_upper_keyword {}
|
|||
/// // With a strictly read-only static, references will have the same address
|
||||
/// assert_eq!(r1, r2);
|
||||
/// // A static item can be used just like a variable in many cases
|
||||
/// println!("{:?}", FOO);
|
||||
/// println!("{FOO:?}");
|
||||
/// ```
|
||||
///
|
||||
/// # Mutable `static`s
|
||||
|
@ -1675,7 +1675,7 @@ mod super_keyword {}
|
|||
/// # #![allow(dead_code)]
|
||||
/// fn debug_iter<I: Iterator>(it: I) where I::Item: std::fmt::Debug {
|
||||
/// for elem in it {
|
||||
/// println!("{:#?}", elem);
|
||||
/// println!("{elem:#?}");
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
@ -2313,7 +2313,7 @@ mod dyn_keyword {}
|
|||
/// match u {
|
||||
/// IntOrFloat { i: 10 } => println!("Found exactly ten!"),
|
||||
/// // Matching the field `f` provides an `f32`.
|
||||
/// IntOrFloat { f } => println!("Found f = {} !", f),
|
||||
/// IntOrFloat { f } => println!("Found f = {f} !"),
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -2337,7 +2337,7 @@ mod dyn_keyword {}
|
|||
/// let i = unsafe { &mut u.i };
|
||||
///
|
||||
/// *i = 10;
|
||||
/// println!("f = {} and i = {}", f, i);
|
||||
/// println!("f = {f} and i = {i}");
|
||||
/// ```
|
||||
///
|
||||
/// See the [Reference][union] for more informations on `union`s.
|
||||
|
|
|
@ -169,30 +169,30 @@ fn is_v6() {
|
|||
fn socket_v4_to_str() {
|
||||
let socket = SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 8080);
|
||||
|
||||
assert_eq!(format!("{}", socket), "192.168.0.1:8080");
|
||||
assert_eq!(format!("{:<20}", socket), "192.168.0.1:8080 ");
|
||||
assert_eq!(format!("{:>20}", socket), " 192.168.0.1:8080");
|
||||
assert_eq!(format!("{:^20}", socket), " 192.168.0.1:8080 ");
|
||||
assert_eq!(format!("{:.10}", socket), "192.168.0.");
|
||||
assert_eq!(format!("{socket}"), "192.168.0.1:8080");
|
||||
assert_eq!(format!("{socket:<20}"), "192.168.0.1:8080 ");
|
||||
assert_eq!(format!("{socket:>20}"), " 192.168.0.1:8080");
|
||||
assert_eq!(format!("{socket:^20}"), " 192.168.0.1:8080 ");
|
||||
assert_eq!(format!("{socket:.10}"), "192.168.0.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn socket_v6_to_str() {
|
||||
let mut socket = SocketAddrV6::new(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53, 0, 0);
|
||||
|
||||
assert_eq!(format!("{}", socket), "[2a02:6b8:0:1::1]:53");
|
||||
assert_eq!(format!("{:<24}", socket), "[2a02:6b8:0:1::1]:53 ");
|
||||
assert_eq!(format!("{:>24}", socket), " [2a02:6b8:0:1::1]:53");
|
||||
assert_eq!(format!("{:^24}", socket), " [2a02:6b8:0:1::1]:53 ");
|
||||
assert_eq!(format!("{:.15}", socket), "[2a02:6b8:0:1::");
|
||||
assert_eq!(format!("{socket}"), "[2a02:6b8:0:1::1]:53");
|
||||
assert_eq!(format!("{socket:<24}"), "[2a02:6b8:0:1::1]:53 ");
|
||||
assert_eq!(format!("{socket:>24}"), " [2a02:6b8:0:1::1]:53");
|
||||
assert_eq!(format!("{socket:^24}"), " [2a02:6b8:0:1::1]:53 ");
|
||||
assert_eq!(format!("{socket:.15}"), "[2a02:6b8:0:1::");
|
||||
|
||||
socket.set_scope_id(5);
|
||||
|
||||
assert_eq!(format!("{}", socket), "[2a02:6b8:0:1::1%5]:53");
|
||||
assert_eq!(format!("{:<24}", socket), "[2a02:6b8:0:1::1%5]:53 ");
|
||||
assert_eq!(format!("{:>24}", socket), " [2a02:6b8:0:1::1%5]:53");
|
||||
assert_eq!(format!("{:^24}", socket), " [2a02:6b8:0:1::1%5]:53 ");
|
||||
assert_eq!(format!("{:.18}", socket), "[2a02:6b8:0:1::1%5");
|
||||
assert_eq!(format!("{socket}"), "[2a02:6b8:0:1::1%5]:53");
|
||||
assert_eq!(format!("{socket:<24}"), "[2a02:6b8:0:1::1%5]:53 ");
|
||||
assert_eq!(format!("{socket:>24}"), " [2a02:6b8:0:1::1%5]:53");
|
||||
assert_eq!(format!("{socket:^24}"), " [2a02:6b8:0:1::1%5]:53 ");
|
||||
assert_eq!(format!("{socket:.18}"), "[2a02:6b8:0:1::1%5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -595,10 +595,10 @@ impl TcpStream {
|
|||
/// // via platform-specific APIs such as epoll or IOCP
|
||||
/// wait_for_fd();
|
||||
/// }
|
||||
/// Err(e) => panic!("encountered IO error: {}", e),
|
||||
/// Err(e) => panic!("encountered IO error: {e}"),
|
||||
/// };
|
||||
/// };
|
||||
/// println!("bytes: {:?}", buf);
|
||||
/// println!("bytes: {buf:?}");
|
||||
/// ```
|
||||
#[stable(feature = "net2_mutators", since = "1.9.0")]
|
||||
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
|
@ -799,8 +799,8 @@ impl TcpListener {
|
|||
///
|
||||
/// let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
|
||||
/// match listener.accept() {
|
||||
/// Ok((_socket, addr)) => println!("new client: {:?}", addr),
|
||||
/// Err(e) => println!("couldn't get client: {:?}", e),
|
||||
/// Ok((_socket, addr)) => println!("new client: {addr:?}"),
|
||||
/// Err(e) => println!("couldn't get client: {e:?}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -991,7 +991,7 @@ impl TcpListener {
|
|||
/// wait_for_fd();
|
||||
/// continue;
|
||||
/// }
|
||||
/// Err(e) => panic!("encountered IO error: {}", e),
|
||||
/// Err(e) => panic!("encountered IO error: {e}"),
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -142,8 +142,7 @@ fn write_close() {
|
|||
e.kind() == ErrorKind::ConnectionReset
|
||||
|| e.kind() == ErrorKind::BrokenPipe
|
||||
|| e.kind() == ErrorKind::ConnectionAborted,
|
||||
"unknown error: {}",
|
||||
e
|
||||
"unknown error: {e}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +654,7 @@ fn debug() {
|
|||
inner_name,
|
||||
render_inner(&listener)
|
||||
);
|
||||
assert_eq!(format!("{:?}", listener), compare);
|
||||
assert_eq!(format!("{listener:?}"), compare);
|
||||
|
||||
let stream = t!(TcpStream::connect(&("localhost", socket_addr.port())));
|
||||
let compare = format!(
|
||||
|
@ -665,7 +664,7 @@ fn debug() {
|
|||
inner_name,
|
||||
render_inner(&stream)
|
||||
);
|
||||
assert_eq!(format!("{:?}", stream), compare);
|
||||
assert_eq!(format!("{stream:?}"), compare);
|
||||
}
|
||||
|
||||
// FIXME: re-enabled openbsd tests once their socket timeout code
|
||||
|
@ -832,7 +831,7 @@ fn set_nonblocking() {
|
|||
match stream.read(&mut buf) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -862,7 +861,7 @@ fn peek() {
|
|||
match c.peek(&mut b) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
}
|
||||
t!(txdone.send(()));
|
||||
})
|
||||
|
|
|
@ -605,9 +605,9 @@ impl UdpSocket {
|
|||
///
|
||||
/// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
|
||||
/// match socket.take_error() {
|
||||
/// Ok(Some(error)) => println!("UdpSocket error: {:?}", error),
|
||||
/// Ok(Some(error)) => println!("UdpSocket error: {error:?}"),
|
||||
/// Ok(None) => println!("No error"),
|
||||
/// Err(error) => println!("UdpSocket.take_error failed: {:?}", error),
|
||||
/// Err(error) => println!("UdpSocket.take_error failed: {error:?}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "net2_mutators", since = "1.9.0")]
|
||||
|
@ -686,8 +686,8 @@ impl UdpSocket {
|
|||
/// socket.connect("127.0.0.1:8080").expect("connect function failed");
|
||||
/// let mut buf = [0; 10];
|
||||
/// match socket.recv(&mut buf) {
|
||||
/// Ok(received) => println!("received {} bytes {:?}", received, &buf[..received]),
|
||||
/// Err(e) => println!("recv function failed: {:?}", e),
|
||||
/// Ok(received) => println!("received {received} bytes {:?}", &buf[..received]),
|
||||
/// Err(e) => println!("recv function failed: {e:?}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "net2_mutators", since = "1.9.0")]
|
||||
|
@ -726,8 +726,8 @@ impl UdpSocket {
|
|||
/// socket.connect("127.0.0.1:8080").expect("connect function failed");
|
||||
/// let mut buf = [0; 10];
|
||||
/// match socket.peek(&mut buf) {
|
||||
/// Ok(received) => println!("received {} bytes", received),
|
||||
/// Err(e) => println!("peek function failed: {:?}", e),
|
||||
/// Ok(received) => println!("received {received} bytes"),
|
||||
/// Err(e) => println!("peek function failed: {e:?}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "peek", since = "1.18.0")]
|
||||
|
@ -770,7 +770,7 @@ impl UdpSocket {
|
|||
/// // via platform-specific APIs such as epoll or IOCP
|
||||
/// wait_for_fd();
|
||||
/// }
|
||||
/// Err(e) => panic!("encountered IO error: {}", e),
|
||||
/// Err(e) => panic!("encountered IO error: {e}"),
|
||||
/// }
|
||||
/// };
|
||||
/// println!("bytes: {:?}", &buf[..num_bytes_read]);
|
||||
|
|
|
@ -173,8 +173,8 @@ fn debug() {
|
|||
|
||||
let udpsock = t!(UdpSocket::bind(&socket_addr));
|
||||
let udpsock_inner = udpsock.0.socket().as_raw();
|
||||
let compare = format!("UdpSocket {{ addr: {:?}, {}: {:?} }}", socket_addr, name, udpsock_inner);
|
||||
assert_eq!(format!("{:?}", udpsock), compare);
|
||||
let compare = format!("UdpSocket {{ addr: {socket_addr:?}, {name}: {udpsock_inner:?} }}");
|
||||
assert_eq!(format!("{udpsock:?}"), compare);
|
||||
}
|
||||
|
||||
// FIXME: re-enabled openbsd/netbsd tests once their socket timeout code
|
||||
|
@ -359,7 +359,7 @@ fn set_nonblocking() {
|
|||
match socket.recv(&mut buf) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub trait FileExt {
|
|||
///
|
||||
/// // We now read 8 bytes from the offset 10.
|
||||
/// let num_bytes_read = file.read_at(&mut buf, 10)?;
|
||||
/// println!("read {} bytes: {:?}", num_bytes_read, buf);
|
||||
/// println!("read {num_bytes_read} bytes: {buf:?}");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -861,7 +861,7 @@ pub trait DirEntryExt2: Sealed {
|
|||
/// entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));
|
||||
///
|
||||
/// for p in entries {
|
||||
/// println!("{:?}", p);
|
||||
/// println!("{p:?}");
|
||||
/// }
|
||||
///
|
||||
/// Ok(())
|
||||
|
|
|
@ -86,7 +86,7 @@ impl<'a> fmt::Display for AsciiEscaped<'a> {
|
|||
/// let socket = match UnixListener::bind("/tmp/sock") {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't bind: {:?}", e);
|
||||
/// println!("Couldn't bind: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -307,7 +307,7 @@ impl SocketAddr {
|
|||
/// let listener = match UnixListener::bind_addr(&addr) {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(err) => {
|
||||
/// println!("Couldn't bind: {:?}", err);
|
||||
/// println!("Couldn't bind: {err:?}");
|
||||
/// return Err(err);
|
||||
/// }
|
||||
/// };
|
||||
|
@ -346,7 +346,7 @@ impl fmt::Debug for SocketAddr {
|
|||
match self.address() {
|
||||
AddressKind::Unnamed => write!(fmt, "(unnamed)"),
|
||||
AddressKind::Abstract(name) => write!(fmt, "{} (abstract)", AsciiEscaped(name)),
|
||||
AddressKind::Pathname(path) => write!(fmt, "{:?} (pathname)", path),
|
||||
AddressKind::Pathname(path) => write!(fmt, "{path:?} (pathname)"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -396,7 +396,7 @@ impl<'a> Iterator for Messages<'a> {
|
|||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -568,7 +568,7 @@ impl<'a> SocketAncillary<'a> {
|
|||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -579,7 +579,7 @@ impl<'a> SocketAncillary<'a> {
|
|||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -95,7 +95,7 @@ impl UnixDatagram {
|
|||
/// let sock = match UnixDatagram::bind("/path/to/the/socket") {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't bind: {:?}", e);
|
||||
/// println!("Couldn't bind: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -127,7 +127,7 @@ impl UnixDatagram {
|
|||
/// let sock2 = match UnixDatagram::bind_addr(&addr) {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(err) => {
|
||||
/// println!("Couldn't bind: {:?}", err);
|
||||
/// println!("Couldn't bind: {err:?}");
|
||||
/// return Err(err);
|
||||
/// }
|
||||
/// };
|
||||
|
@ -157,7 +157,7 @@ impl UnixDatagram {
|
|||
/// let sock = match UnixDatagram::unbound() {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't unbound: {:?}", e);
|
||||
/// println!("Couldn't unbound: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -180,7 +180,7 @@ impl UnixDatagram {
|
|||
/// let (sock1, sock2) = match UnixDatagram::pair() {
|
||||
/// Ok((sock1, sock2)) => (sock1, sock2),
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't unbound: {:?}", e);
|
||||
/// println!("Couldn't unbound: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -210,7 +210,7 @@ impl UnixDatagram {
|
|||
/// match sock.connect("/path/to/the/socket") {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't connect: {:?}", e);
|
||||
/// println!("Couldn't connect: {e:?}");
|
||||
/// return Err(e)
|
||||
/// }
|
||||
/// };
|
||||
|
@ -243,7 +243,7 @@ impl UnixDatagram {
|
|||
/// match sock.connect_addr(&addr) {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't connect: {:?}", e);
|
||||
/// println!("Couldn't connect: {e:?}");
|
||||
/// return Err(e)
|
||||
/// }
|
||||
/// };
|
||||
|
@ -367,7 +367,7 @@ impl UnixDatagram {
|
|||
/// let sock = UnixDatagram::unbound()?;
|
||||
/// let mut buf = vec![0; 10];
|
||||
/// let (size, sender) = sock.recv_from(buf.as_mut_slice())?;
|
||||
/// println!("received {} bytes from {:?}", size, sender);
|
||||
/// println!("received {size} bytes from {sender:?}");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -422,11 +422,11 @@ impl UnixDatagram {
|
|||
/// let mut ancillary_buffer = [0; 128];
|
||||
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
|
||||
/// let (size, _truncated, sender) = sock.recv_vectored_with_ancillary_from(bufs, &mut ancillary)?;
|
||||
/// println!("received {}", size);
|
||||
/// println!("received {size}");
|
||||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -479,11 +479,11 @@ impl UnixDatagram {
|
|||
/// let mut ancillary_buffer = [0; 128];
|
||||
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
|
||||
/// let (size, _truncated) = sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
|
||||
/// println!("received {}", size);
|
||||
/// println!("received {size}");
|
||||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -893,7 +893,7 @@ impl UnixDatagram {
|
|||
/// fn main() -> std::io::Result<()> {
|
||||
/// let sock = UnixDatagram::unbound()?;
|
||||
/// if let Ok(Some(err)) = sock.take_error() {
|
||||
/// println!("Got error: {:?}", err);
|
||||
/// println!("Got error: {err:?}");
|
||||
/// }
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
|
|
@ -63,7 +63,7 @@ impl UnixListener {
|
|||
/// let listener = match UnixListener::bind("/path/to/the/socket") {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't connect: {:?}", e);
|
||||
/// println!("Couldn't connect: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -98,7 +98,7 @@ impl UnixListener {
|
|||
/// let listener2 = match UnixListener::bind_addr(&addr) {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(err) => {
|
||||
/// println!("Couldn't bind: {:?}", err);
|
||||
/// println!("Couldn't bind: {err:?}");
|
||||
/// return Err(err);
|
||||
/// }
|
||||
/// };
|
||||
|
@ -136,8 +136,8 @@ impl UnixListener {
|
|||
/// let listener = UnixListener::bind("/path/to/the/socket")?;
|
||||
///
|
||||
/// match listener.accept() {
|
||||
/// Ok((socket, addr)) => println!("Got a client: {:?}", addr),
|
||||
/// Err(e) => println!("accept function failed: {:?}", e),
|
||||
/// Ok((socket, addr)) => println!("Got a client: {addr:?}"),
|
||||
/// Err(e) => println!("accept function failed: {e:?}"),
|
||||
/// }
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -226,7 +226,7 @@ impl UnixListener {
|
|||
/// let listener = UnixListener::bind("/tmp/sock")?;
|
||||
///
|
||||
/// if let Ok(Some(err)) = listener.take_error() {
|
||||
/// println!("Got error: {:?}", err);
|
||||
/// println!("Got error: {err:?}");
|
||||
/// }
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
|
|
@ -57,7 +57,7 @@ pub use ucred::UCred;
|
|||
/// stream.write_all(b"hello world")?;
|
||||
/// let mut response = String::new();
|
||||
/// stream.read_to_string(&mut response)?;
|
||||
/// println!("{}", response);
|
||||
/// println!("{response}");
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -90,7 +90,7 @@ impl UnixStream {
|
|||
/// let socket = match UnixStream::connect("/tmp/sock") {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't connect: {:?}", e);
|
||||
/// println!("Couldn't connect: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -123,7 +123,7 @@ impl UnixStream {
|
|||
/// let sock = match UnixStream::connect_addr(&addr) {
|
||||
/// Ok(sock) => sock,
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't connect: {:?}", e);
|
||||
/// println!("Couldn't connect: {e:?}");
|
||||
/// return Err(e)
|
||||
/// }
|
||||
/// };
|
||||
|
@ -155,7 +155,7 @@ impl UnixStream {
|
|||
/// let (sock1, sock2) = match UnixStream::pair() {
|
||||
/// Ok((sock1, sock2)) => (sock1, sock2),
|
||||
/// Err(e) => {
|
||||
/// println!("Couldn't create a pair of sockets: {:?}", e);
|
||||
/// println!("Couldn't create a pair of sockets: {e:?}");
|
||||
/// return
|
||||
/// }
|
||||
/// };
|
||||
|
@ -443,7 +443,7 @@ impl UnixStream {
|
|||
/// fn main() -> std::io::Result<()> {
|
||||
/// let socket = UnixStream::connect("/tmp/sock")?;
|
||||
/// if let Ok(Some(err)) = socket.take_error() {
|
||||
/// println!("Got error: {:?}", err);
|
||||
/// println!("Got error: {err:?}");
|
||||
/// }
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -530,11 +530,11 @@ impl UnixStream {
|
|||
/// let mut ancillary_buffer = [0; 128];
|
||||
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
|
||||
/// let size = socket.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
|
||||
/// println!("received {}", size);
|
||||
/// println!("received {size}");
|
||||
/// for ancillary_result in ancillary.messages() {
|
||||
/// if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
|
||||
/// for fd in scm_rights {
|
||||
/// println!("receive file descriptor: {}", fd);
|
||||
/// println!("receive file descriptor: {fd}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -29,7 +29,7 @@ macro_rules! or_panic {
|
|||
($e:expr) => {
|
||||
match $e {
|
||||
Ok(e) => e,
|
||||
Err(e) => panic!("{}", e),
|
||||
Err(e) => panic!("{e}"),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -161,19 +161,19 @@ fn long_path() {
|
|||
);
|
||||
match UnixStream::connect(&socket_path) {
|
||||
Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
Ok(_) => panic!("unexpected success"),
|
||||
}
|
||||
|
||||
match UnixListener::bind(&socket_path) {
|
||||
Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
Ok(_) => panic!("unexpected success"),
|
||||
}
|
||||
|
||||
match UnixDatagram::bind(&socket_path) {
|
||||
Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
Ok(_) => panic!("unexpected success"),
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ fn test_abstract_namespace_too_long() {
|
|||
jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
|
||||
) {
|
||||
Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
|
||||
Err(e) => panic!("unexpected error {}", e),
|
||||
Err(e) => panic!("unexpected error {e}"),
|
||||
Ok(_) => panic!("unexpected success"),
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ fn test_unix_stream_peek() {
|
|||
match stream.peek(&mut buf) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
|
||||
Err(e) => panic!("unexpected error: {}", e),
|
||||
Err(e) => panic!("unexpected error: {e}"),
|
||||
}
|
||||
|
||||
or_panic!(txdone.send(()));
|
||||
|
|
|
@ -283,7 +283,7 @@ fn default_hook(info: &PanicInfo<'_>) {
|
|||
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
|
||||
|
||||
let write = |err: &mut dyn crate::io::Write| {
|
||||
let _ = writeln!(err, "thread '{}' panicked at '{}', {}", name, msg, location);
|
||||
let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}");
|
||||
|
||||
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
|
@ -677,7 +677,7 @@ fn rust_panic_with_hook(
|
|||
// Unfortunately, this does not print a backtrace, because creating
|
||||
// a `Backtrace` will allocate, which we must to avoid here.
|
||||
let panicinfo = PanicInfo::internal_constructor(message, location, can_unwind);
|
||||
rtprintpanic!("{}\npanicked after panic::always_abort(), aborting.\n", panicinfo);
|
||||
rtprintpanic!("{panicinfo}\npanicked after panic::always_abort(), aborting.\n");
|
||||
}
|
||||
crate::sys::abort_internal();
|
||||
}
|
||||
|
@ -745,5 +745,5 @@ fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
|
|||
let obj = &mut msg as *mut &mut dyn BoxMeUp;
|
||||
__rust_start_panic(obj)
|
||||
};
|
||||
rtabort!("failed to initiate panic, error {}", code)
|
||||
rtabort!("failed to initiate panic, error {code}")
|
||||
}
|
||||
|
|
|
@ -592,7 +592,7 @@ impl AsRef<Path> for Component<'_> {
|
|||
/// let path = Path::new("/tmp/foo/bar.txt");
|
||||
///
|
||||
/// for component in path.components() {
|
||||
/// println!("{:?}", component);
|
||||
/// println!("{component:?}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -1586,17 +1586,17 @@ fn test_components_debug() {
|
|||
let mut components = path.components();
|
||||
|
||||
let expected = "Components([RootDir, Normal(\"tmp\")])";
|
||||
let actual = format!("{:?}", components);
|
||||
let actual = format!("{components:?}");
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
let _ = components.next().unwrap();
|
||||
let expected = "Components([Normal(\"tmp\")])";
|
||||
let actual = format!("{:?}", components);
|
||||
let actual = format!("{components:?}");
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
let _ = components.next().unwrap();
|
||||
let expected = "Components([])";
|
||||
let actual = format!("{:?}", components);
|
||||
let actual = format!("{components:?}");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -1608,17 +1608,17 @@ fn test_iter_debug() {
|
|||
let mut iter = path.iter();
|
||||
|
||||
let expected = "Iter([\"/\", \"tmp\"])";
|
||||
let actual = format!("{:?}", iter);
|
||||
let actual = format!("{iter:?}");
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
let _ = iter.next().unwrap();
|
||||
let expected = "Iter([\"tmp\"])";
|
||||
let actual = format!("{:?}", iter);
|
||||
let actual = format!("{iter:?}");
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
let _ = iter.next().unwrap();
|
||||
let expected = "Iter([])";
|
||||
let actual = format!("{:?}", iter);
|
||||
let actual = format!("{iter:?}");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -1770,7 +1770,7 @@ fn test_windows_absolute() {
|
|||
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
||||
let prefix = "my/home";
|
||||
let mut paths: Vec<_> =
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {}.rs", num))).collect();
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||
|
||||
paths.sort();
|
||||
|
||||
|
@ -1783,7 +1783,7 @@ fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
|||
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {}.rs", num))).collect();
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||
|
||||
let mut set = BTreeSet::new();
|
||||
|
||||
|
@ -1801,7 +1801,7 @@ fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
|||
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
||||
let prefix = "my/home";
|
||||
let paths: Vec<_> =
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {}.rs", num))).collect();
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||
|
||||
let mut set = BTreeSet::new();
|
||||
|
||||
|
@ -1819,7 +1819,7 @@ fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
|||
fn bench_path_hashset(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {}.rs", num))).collect();
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||
|
||||
let mut set = HashSet::new();
|
||||
|
||||
|
@ -1837,7 +1837,7 @@ fn bench_path_hashset(b: &mut test::Bencher) {
|
|||
fn bench_path_hashset_miss(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {}.rs", num))).collect();
|
||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||
|
||||
let mut set = HashSet::new();
|
||||
|
||||
|
|
|
@ -607,7 +607,7 @@ mod prim_pointer {}
|
|||
///
|
||||
/// // This loop prints: 0 1 2
|
||||
/// for x in array {
|
||||
/// print!("{} ", x);
|
||||
/// print!("{x} ");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -646,19 +646,19 @@ mod prim_pointer {}
|
|||
/// // This creates a slice iterator, producing references to each value.
|
||||
/// for item in array.into_iter().enumerate() {
|
||||
/// let (i, x): (usize, &i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
///
|
||||
/// // The `array_into_iter` lint suggests this change for future compatibility:
|
||||
/// for item in array.iter().enumerate() {
|
||||
/// let (i, x): (usize, &i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
///
|
||||
/// // You can explicitly iterate an array by value using `IntoIterator::into_iter`
|
||||
/// for item in IntoIterator::into_iter(array).enumerate() {
|
||||
/// let (i, x): (usize, i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -673,13 +673,13 @@ mod prim_pointer {}
|
|||
/// // This iterates by reference:
|
||||
/// for item in array.iter().enumerate() {
|
||||
/// let (i, x): (usize, &i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
///
|
||||
/// // This iterates by value:
|
||||
/// for item in array.into_iter().enumerate() {
|
||||
/// let (i, x): (usize, i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -702,26 +702,26 @@ mod prim_pointer {}
|
|||
/// // This iterates by reference:
|
||||
/// for item in array.iter() {
|
||||
/// let x: &i32 = item;
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// // This iterates by value:
|
||||
/// for item in IntoIterator::into_iter(array) {
|
||||
/// let x: i32 = item;
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// // This iterates by value:
|
||||
/// for item in array {
|
||||
/// let x: i32 = item;
|
||||
/// println!("{}", x);
|
||||
/// println!("{x}");
|
||||
/// }
|
||||
///
|
||||
/// // IntoIter can also start a chain.
|
||||
/// // This iterates by value:
|
||||
/// for item in IntoIterator::into_iter(array).enumerate() {
|
||||
/// let (i, x): (usize, i32) = item;
|
||||
/// println!("array[{}] = {}", i, x);
|
||||
/// println!("array[{i}] = {x}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -915,7 +915,7 @@ impl Command {
|
|||
/// .status()
|
||||
/// .expect("failed to execute process");
|
||||
///
|
||||
/// println!("process finished with: {}", status);
|
||||
/// println!("process finished with: {status}");
|
||||
///
|
||||
/// assert!(status.success());
|
||||
/// ```
|
||||
|
@ -1434,7 +1434,7 @@ impl ExitStatus {
|
|||
/// .status()
|
||||
/// .expect("ls could not be executed");
|
||||
///
|
||||
/// println!("ls: {}", status);
|
||||
/// println!("ls: {status}");
|
||||
/// status.exit_ok().expect_err("/dev/nonexistent could be listed!");
|
||||
/// # } // cfg!(unix)
|
||||
/// ```
|
||||
|
@ -1459,7 +1459,7 @@ impl ExitStatus {
|
|||
/// if status.success() {
|
||||
/// println!("'projects/' directory created");
|
||||
/// } else {
|
||||
/// println!("failed to create 'projects/' directory: {}", status);
|
||||
/// println!("failed to create 'projects/' directory: {status}");
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
|
@ -1490,7 +1490,7 @@ impl ExitStatus {
|
|||
/// .expect("failed to execute mkdir");
|
||||
///
|
||||
/// match status.code() {
|
||||
/// Some(code) => println!("Exited with status code: {}", code),
|
||||
/// Some(code) => println!("Exited with status code: {code}"),
|
||||
/// None => println!("Process terminated by signal")
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -1806,13 +1806,13 @@ impl Child {
|
|||
/// let mut child = Command::new("ls").spawn().unwrap();
|
||||
///
|
||||
/// match child.try_wait() {
|
||||
/// Ok(Some(status)) => println!("exited with: {}", status),
|
||||
/// Ok(Some(status)) => println!("exited with: {status}"),
|
||||
/// Ok(None) => {
|
||||
/// println!("status not ready yet, let's really wait");
|
||||
/// let res = child.wait();
|
||||
/// println!("result: {:?}", res);
|
||||
/// println!("result: {res:?}");
|
||||
/// }
|
||||
/// Err(e) => println!("error attempting to wait: {}", e),
|
||||
/// Err(e) => println!("error attempting to wait: {e}"),
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "process_try_wait", since = "1.18.0")]
|
||||
|
@ -1912,7 +1912,7 @@ impl Child {
|
|||
/// std::process::exit(match run_app() {
|
||||
/// Ok(_) => 0,
|
||||
/// Err(err) => {
|
||||
/// eprintln!("error: {:?}", err);
|
||||
/// eprintln!("error: {err:?}");
|
||||
/// 1
|
||||
/// }
|
||||
/// });
|
||||
|
@ -2071,7 +2071,7 @@ impl Termination for ! {
|
|||
impl<E: fmt::Debug> Termination for Result<!, E> {
|
||||
fn report(self) -> ExitCode {
|
||||
let Err(err) = self;
|
||||
eprintln!("Error: {:?}", err);
|
||||
eprintln!("Error: {err:?}");
|
||||
ExitCode::FAILURE.report()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ fn signal_reported_right() {
|
|||
p.kill().unwrap();
|
||||
match p.wait().unwrap().signal() {
|
||||
Some(9) => {}
|
||||
result => panic!("not terminated by signal 9 (instead, {:?})", result),
|
||||
result => panic!("not terminated by signal 9 (instead, {result:?})"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,8 +252,7 @@ fn test_override_env() {
|
|||
|
||||
assert!(
|
||||
output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}",
|
||||
output
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{output}",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -265,8 +264,7 @@ fn test_add_to_env() {
|
|||
|
||||
assert!(
|
||||
output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}",
|
||||
output
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{output}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -288,13 +286,11 @@ fn test_capture_env_at_spawn() {
|
|||
|
||||
assert!(
|
||||
output.contains("RUN_TEST_NEW_ENV1=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{}",
|
||||
output
|
||||
"didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{output}"
|
||||
);
|
||||
assert!(
|
||||
output.contains("RUN_TEST_NEW_ENV2=456"),
|
||||
"didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{}",
|
||||
output
|
||||
"didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{output}"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
//! B = 4;
|
||||
//! A = A + B;
|
||||
//! C = B;
|
||||
//! println!("{} {} {}", A, B, C);
|
||||
//! println!("{A} {B} {C}");
|
||||
//! C = A;
|
||||
//! }
|
||||
//! }
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
//!
|
||||
//! // Unbounded receiver waiting for all senders to complete.
|
||||
//! while let Ok(msg) = rx.recv() {
|
||||
//! println!("{}", msg);
|
||||
//! println!("{msg}");
|
||||
//! }
|
||||
//!
|
||||
//! println!("completed");
|
||||
|
@ -376,7 +376,7 @@ impl<T> !Sync for Receiver<T> {}
|
|||
/// });
|
||||
///
|
||||
/// for x in recv.iter() {
|
||||
/// println!("Got: {}", x);
|
||||
/// println!("Got: {x}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -419,7 +419,7 @@ pub struct Iter<'a, T: 'a> {
|
|||
/// thread::sleep(Duration::from_secs(2)); // block for two seconds
|
||||
///
|
||||
/// for x in receiver.try_iter() {
|
||||
/// println!("Got: {}", x);
|
||||
/// println!("Got: {x}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "receiver_try_iter", since = "1.15.0")]
|
||||
|
@ -453,7 +453,7 @@ pub struct TryIter<'a, T: 'a> {
|
|||
/// });
|
||||
///
|
||||
/// for x in recv.into_iter() {
|
||||
/// println!("Got: {}", x);
|
||||
/// println!("Got: {x}");
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "receiver_into_iter", since = "1.1.0")]
|
||||
|
@ -544,16 +544,16 @@ impl<T> !Sync for Sender<T> {}
|
|||
/// let mut msg;
|
||||
///
|
||||
/// msg = receiver.recv().unwrap();
|
||||
/// println!("message {} received", msg);
|
||||
/// println!("message {msg} received");
|
||||
///
|
||||
/// // "Thread unblocked!" will be printed now
|
||||
///
|
||||
/// msg = receiver.recv().unwrap();
|
||||
/// println!("message {} received", msg);
|
||||
/// println!("message {msg} received");
|
||||
///
|
||||
/// msg = receiver.recv().unwrap();
|
||||
///
|
||||
/// println!("message {} received", msg);
|
||||
/// println!("message {msg} received");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct SyncSender<T> {
|
||||
|
@ -996,14 +996,14 @@ impl<T> SyncSender<T> {
|
|||
///
|
||||
/// let mut msg;
|
||||
/// msg = receiver.recv().unwrap();
|
||||
/// println!("message {} received", msg);
|
||||
/// println!("message {msg} received");
|
||||
///
|
||||
/// msg = receiver.recv().unwrap();
|
||||
/// println!("message {} received", msg);
|
||||
/// println!("message {msg} received");
|
||||
///
|
||||
/// // Third message may have never been sent
|
||||
/// match receiver.try_recv() {
|
||||
/// Ok(msg) => println!("message {} received", msg),
|
||||
/// Ok(msg) => println!("message {msg} received"),
|
||||
/// Err(_) => println!("the third message was never sent"),
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -369,7 +369,7 @@ impl<T> Packet<T> {
|
|||
match self.channels.fetch_sub(1, Ordering::SeqCst) {
|
||||
1 => {}
|
||||
n if n > 1 => return,
|
||||
n => panic!("bad number of channels left {}", n),
|
||||
n => panic!("bad number of channels left {n}"),
|
||||
}
|
||||
|
||||
match self.cnt.swap(DISCONNECTED, Ordering::SeqCst) {
|
||||
|
|
|
@ -94,7 +94,7 @@ fn test_into_inner_poison() {
|
|||
assert!(m.is_poisoned());
|
||||
match Arc::try_unwrap(m).unwrap().into_inner() {
|
||||
Err(e) => assert_eq!(e.into_inner(), NonCopy(10)),
|
||||
Ok(x) => panic!("into_inner of poisoned Mutex is Ok: {:?}", x),
|
||||
Ok(x) => panic!("into_inner of poisoned Mutex is Ok: {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ fn test_get_mut_poison() {
|
|||
assert!(m.is_poisoned());
|
||||
match Arc::try_unwrap(m).unwrap().get_mut() {
|
||||
Err(e) => assert_eq!(*e.into_inner(), NonCopy(10)),
|
||||
Ok(x) => panic!("get_mut of poisoned Mutex is Ok: {:?}", x),
|
||||
Ok(x) => panic!("get_mut of poisoned Mutex is Ok: {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ pub struct Guard {
|
|||
/// Ok(_) => unreachable!(),
|
||||
/// Err(p_err) => {
|
||||
/// let data = p_err.get_ref();
|
||||
/// println!("recovered: {}", data);
|
||||
/// println!("recovered: {data}");
|
||||
/// }
|
||||
/// };
|
||||
/// ```
|
||||
|
|
|
@ -218,7 +218,7 @@ fn test_into_inner_poison() {
|
|||
assert!(m.is_poisoned());
|
||||
match Arc::try_unwrap(m).unwrap().into_inner() {
|
||||
Err(e) => assert_eq!(e.into_inner(), NonCopy(10)),
|
||||
Ok(x) => panic!("into_inner of poisoned RwLock is Ok: {:?}", x),
|
||||
Ok(x) => panic!("into_inner of poisoned RwLock is Ok: {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,6 +242,6 @@ fn test_get_mut_poison() {
|
|||
assert!(m.is_poisoned());
|
||||
match Arc::try_unwrap(m).unwrap().get_mut() {
|
||||
Err(e) => assert_eq!(*e.into_inner(), NonCopy(10)),
|
||||
Ok(x) => panic!("get_mut of poisoned RwLock is Ok: {:?}", x),
|
||||
Ok(x) => panic!("get_mut of poisoned RwLock is Ok: {x:?}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64
|
|||
pub(super) fn exit_with_code(code: isize) -> ! {
|
||||
if code != 0 {
|
||||
if let Some(mut out) = panic::SgxPanicOutput::new() {
|
||||
let _ = write!(out, "Exited with status code {}", code);
|
||||
let _ = write!(out, "Exited with status code {code}");
|
||||
}
|
||||
}
|
||||
usercalls::exit(code != 0);
|
||||
|
|
|
@ -83,7 +83,7 @@ pub fn close(fd: Fd) {
|
|||
|
||||
fn string_from_bytebuffer(buf: &alloc::UserRef<ByteBuffer>, usercall: &str, arg: &str) -> String {
|
||||
String::from_utf8(buf.copy_user_buffer())
|
||||
.unwrap_or_else(|_| rtabort!("Usercall {}: expected {} to be valid UTF-8", usercall, arg))
|
||||
.unwrap_or_else(|_| rtabort!("Usercall {usercall}: expected {arg} to be valid UTF-8"))
|
||||
}
|
||||
|
||||
/// Usercall `bind_stream`. See the ABI documentation for more information.
|
||||
|
@ -287,7 +287,7 @@ fn check_os_error(err: Result) -> i32 {
|
|||
{
|
||||
err
|
||||
} else {
|
||||
rtabort!("Usercall: returned invalid error value {}", err)
|
||||
rtabort!("Usercall: returned invalid error value {err}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ impl<T: RegisterArgument> RegisterArgument for Option<NonNull<T>> {
|
|||
|
||||
impl ReturnValue for ! {
|
||||
fn from_registers(call: &'static str, _regs: (Register, Register)) -> Self {
|
||||
rtabort!("Usercall {}: did not expect to be re-entered", call);
|
||||
rtabort!("Usercall {call}: did not expect to be re-entered");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -501,7 +501,7 @@ impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
|
|||
type Error = io::Error;
|
||||
|
||||
fn try_from((host, port): (&'a str, u16)) -> io::Result<LookupHost> {
|
||||
LookupHost::new(format!("{}:{}", host, port))
|
||||
LookupHost::new(format!("{host}:{port}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn error_string(errno: i32) -> String {
|
|||
if errno == RESULT_SUCCESS {
|
||||
"operation successful".into()
|
||||
} else if ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&errno) {
|
||||
format!("user-specified error {:08x}", errno)
|
||||
format!("user-specified error {errno:08x}")
|
||||
} else {
|
||||
decode_error_kind(errno).as_str().into()
|
||||
}
|
||||
|
|
|
@ -83,6 +83,6 @@ pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
|
|||
}
|
||||
let buf = unsafe { slice::from_raw_parts(m as *const u8, s as _) };
|
||||
if let Ok(s) = str::from_utf8(&buf[..buf.iter().position(|&b| b == 0).unwrap_or(buf.len())]) {
|
||||
eprint!("{}", s);
|
||||
eprint!("{s}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
|
|||
unsafe {
|
||||
let mut out = crate::mem::MaybeUninit::<[u64; 2]>::uninit();
|
||||
let result = abi::SOLID_RNG_SampleRandomBytes(out.as_mut_ptr() as *mut u8, 16);
|
||||
assert_eq!(result, 0, "SOLID_RNG_SampleRandomBytes failed: {}", result);
|
||||
assert_eq!(result, 0, "SOLID_RNG_SampleRandomBytes failed: {result}");
|
||||
let [x1, x2] = out.assume_init();
|
||||
(x1, x2)
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
|
|||
};
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Uncategorized,
|
||||
&format!("failed to lookup address information: {}", msg)[..],
|
||||
&format!("failed to lookup address information: {msg}")[..],
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ pub fn errno() -> i32 {
|
|||
}
|
||||
|
||||
pub fn error_string(errno: i32) -> String {
|
||||
if let Some(name) = error::error_name(errno) { name.to_owned() } else { format!("{}", errno) }
|
||||
if let Some(name) = error::error_name(errno) { name.to_owned() } else { format!("{errno}") }
|
||||
}
|
||||
|
||||
pub fn getcwd() -> io::Result<PathBuf> {
|
||||
|
|
|
@ -54,7 +54,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
|
|||
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Uncategorized,
|
||||
&format!("failed to lookup address information: {}", detail)[..],
|
||||
&format!("failed to lookup address information: {detail}")[..],
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::*;
|
|||
fn slice_debug_output() {
|
||||
let input = Slice::from_u8_slice(b"\xF0hello,\tworld");
|
||||
let expected = r#""\xF0hello,\tworld""#;
|
||||
let output = format!("{:?}", input);
|
||||
let output = format!("{input:?}");
|
||||
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ impl Process {
|
|||
return Ok(None);
|
||||
}
|
||||
_ => {
|
||||
panic!("Failed to wait on process handle: {}", status);
|
||||
panic!("Failed to wait on process handle: {status}");
|
||||
}
|
||||
}
|
||||
zx_cvt(zx_object_get_info(
|
||||
|
|
|
@ -120,7 +120,7 @@ impl Command {
|
|||
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
||||
Err(e) => {
|
||||
assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
|
||||
panic!("the CLOEXEC pipe failed: {:?}", e)
|
||||
panic!("the CLOEXEC pipe failed: {e:?}")
|
||||
}
|
||||
Ok(..) => {
|
||||
// pipe I/O up to PIPE_BUF bytes should be atomic
|
||||
|
@ -682,15 +682,15 @@ 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 status: {}", code)
|
||||
write!(f, "exit status: {code}")
|
||||
} else if let Some(signal) = self.signal() {
|
||||
if self.core_dumped() {
|
||||
write!(f, "signal: {} (core dumped)", signal)
|
||||
write!(f, "signal: {signal} (core dumped)")
|
||||
} else {
|
||||
write!(f, "signal: {}", signal)
|
||||
write!(f, "signal: {signal}")
|
||||
}
|
||||
} else if let Some(signal) = self.stopped_signal() {
|
||||
write!(f, "stopped (not terminated) by signal: {}", signal)
|
||||
write!(f, "stopped (not terminated) by signal: {signal}")
|
||||
} else if self.continued() {
|
||||
write!(f, "continued (WIFCONTINUED)")
|
||||
} else {
|
||||
|
|
|
@ -239,10 +239,10 @@ 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 code: {code}")
|
||||
} else {
|
||||
let signal = self.signal().unwrap();
|
||||
write!(f, "signal: {}", signal)
|
||||
write!(f, "signal: {signal}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ mod imp {
|
|||
} else if err == libc::EAGAIN {
|
||||
return false;
|
||||
} else {
|
||||
panic!("unexpected getrandom error: {}", err);
|
||||
panic!("unexpected getrandom error: {err}");
|
||||
}
|
||||
} else {
|
||||
read += result as usize;
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn error_string(mut errnum: i32) -> String {
|
|||
if res == 0 {
|
||||
// Sometimes FormatMessageW can fail e.g., system doesn't like langId,
|
||||
let fm_err = errno();
|
||||
return format!("OS Error {} (FormatMessageW() returned error {})", errnum, fm_err);
|
||||
return format!("OS Error {errnum} (FormatMessageW() returned error {fm_err})");
|
||||
}
|
||||
|
||||
match String::from_utf16(&buf[..res]) {
|
||||
|
|
|
@ -121,9 +121,7 @@ fn windows_env_unicode_case() {
|
|||
assert_eq!(
|
||||
env::var(key).ok(),
|
||||
value.map(|s| s.to_string_lossy().into_owned()),
|
||||
"command environment mismatch: {} {}",
|
||||
a,
|
||||
b
|
||||
"command environment mismatch: {a} {b}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ fn keyed_event_handle() -> c::HANDLE {
|
|||
0,
|
||||
) {
|
||||
c::STATUS_SUCCESS => {}
|
||||
r => panic!("Unable to create keyed event handle: error {}", r),
|
||||
r => panic!("Unable to create keyed event handle: error {r}"),
|
||||
}
|
||||
}
|
||||
match HANDLE.compare_exchange(INVALID, handle as usize, Relaxed, Relaxed) {
|
||||
|
|
|
@ -174,7 +174,7 @@ pub fn output_filename(
|
|||
if let Some(cwd) = cwd {
|
||||
if let Ok(stripped) = file.strip_prefix(&cwd) {
|
||||
if let Some(s) = stripped.to_str() {
|
||||
return write!(fmt, ".{}{}", path::MAIN_SEPARATOR, s);
|
||||
return write!(fmt, ".{}{s}", path::MAIN_SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ fn no_lookup_host_duplicates() {
|
|||
let mut addrs = HashMap::new();
|
||||
let lh = match LookupHost::try_from(("localhost", 0)) {
|
||||
Ok(lh) => lh,
|
||||
Err(e) => panic!("couldn't resolve `localhost': {}", e),
|
||||
Err(e) => panic!("couldn't resolve `localhost': {e}"),
|
||||
};
|
||||
for sa in lh {
|
||||
*addrs.entry(sa).or_insert(0) += 1;
|
||||
|
|
|
@ -84,7 +84,7 @@ impl Parker {
|
|||
match self.state.swap(EMPTY, SeqCst) {
|
||||
NOTIFIED => {} // got a notification, hurray!
|
||||
PARKED => {} // no notification, alas
|
||||
n => panic!("inconsistent park_timeout state: {}", n),
|
||||
n => panic!("inconsistent park_timeout state: {n}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -830,7 +830,7 @@ pub unsafe fn slice_unchecked(s: &Wtf8, begin: usize, end: usize) -> &Wtf8 {
|
|||
#[inline(never)]
|
||||
pub fn slice_error_fail(s: &Wtf8, begin: usize, end: usize) -> ! {
|
||||
assert!(begin <= end);
|
||||
panic!("index {} and/or {} in `{:?}` do not lie on character boundary", begin, end, s);
|
||||
panic!("index {begin} and/or {end} in `{s:?}` do not lie on character boundary");
|
||||
}
|
||||
|
||||
/// Iterator for the code points of a WTF-8 string.
|
||||
|
|
|
@ -266,7 +266,7 @@ fn wtf8buf_extend() {
|
|||
fn wtf8buf_show() {
|
||||
let mut string = Wtf8Buf::from_str("a\té \u{7f}💩\r");
|
||||
string.push(CodePoint::from_u32(0xD800).unwrap());
|
||||
assert_eq!(format!("{:?}", string), "\"a\\té \\u{7f}\u{1f4a9}\\r\\u{d800}\"");
|
||||
assert_eq!(format!("{string:?}"), "\"a\\té \\u{7f}\u{1f4a9}\\r\\u{d800}\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -278,7 +278,7 @@ fn wtf8buf_as_slice() {
|
|||
fn wtf8buf_show_str() {
|
||||
let text = "a\té 💩\r";
|
||||
let string = Wtf8Buf::from_str(text);
|
||||
assert_eq!(format!("{:?}", text), format!("{:?}", string));
|
||||
assert_eq!(format!("{text:?}"), format!("{string:?}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -613,7 +613,7 @@ impl Builder {
|
|||
///
|
||||
/// let receiver = thread::spawn(move || {
|
||||
/// let value = rx.recv().expect("Unable to receive from channel");
|
||||
/// println!("{}", value);
|
||||
/// println!("{value}");
|
||||
/// });
|
||||
///
|
||||
/// sender.join().expect("The sender thread has panicked");
|
||||
|
@ -633,7 +633,7 @@ impl Builder {
|
|||
/// });
|
||||
///
|
||||
/// let result = computation.join().unwrap();
|
||||
/// println!("{}", result);
|
||||
/// println!("{result}");
|
||||
/// ```
|
||||
///
|
||||
/// [`channels`]: crate::sync::mpsc
|
||||
|
@ -979,7 +979,7 @@ pub fn park_timeout_ms(ms: u32) {
|
|||
/// if elapsed >= timeout {
|
||||
/// break;
|
||||
/// }
|
||||
/// println!("restarting park_timeout after {:?}", elapsed);
|
||||
/// println!("restarting park_timeout after {elapsed:?}");
|
||||
/// timeout_remaining = timeout - elapsed;
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -22,7 +22,7 @@ pub struct Scope<'scope, 'env: 'scope> {
|
|||
/// std::thread::scope(|s| {
|
||||
/// s.spawn(|| {
|
||||
/// let a = String::from("abcd");
|
||||
/// s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
|
||||
/// s.spawn(|| println!("{a:?}")); // might run after `a` is dropped
|
||||
/// });
|
||||
/// });
|
||||
/// ```
|
||||
|
|
|
@ -191,7 +191,7 @@ pub struct Instant(time::Instant);
|
|||
/// }
|
||||
/// Err(e) => {
|
||||
/// // an error occurred!
|
||||
/// println!("Error: {:?}", e);
|
||||
/// println!("Error: {e:?}");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -513,7 +513,7 @@ impl SystemTime {
|
|||
/// let new_sys_time = SystemTime::now();
|
||||
/// let difference = new_sys_time.duration_since(sys_time)
|
||||
/// .expect("Clock may have gone backwards");
|
||||
/// println!("{:?}", difference);
|
||||
/// println!("{difference:?}");
|
||||
/// ```
|
||||
#[stable(feature = "time2", since = "1.8.0")]
|
||||
pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
|
||||
|
|
|
@ -55,10 +55,10 @@ fn instant_elapsed() {
|
|||
fn instant_math() {
|
||||
let a = Instant::now();
|
||||
let b = Instant::now();
|
||||
println!("a: {:?}", a);
|
||||
println!("b: {:?}", b);
|
||||
println!("a: {a:?}");
|
||||
println!("b: {b:?}");
|
||||
let dur = b.duration_since(a);
|
||||
println!("dur: {:?}", dur);
|
||||
println!("dur: {dur:?}");
|
||||
assert_almost_eq!(b - dur, a);
|
||||
assert_almost_eq!(a + dur, b);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue