diff options
| author | T-O-R-U-S <bageliq@protonmail.com> | 2022-02-12 23:16:17 +0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2022-03-10 10:23:40 -0500 |
| commit | 72a25d05bf1a4b155d74139ef700ff93af6d8e22 (patch) | |
| tree | 3f143b29a3a51b68e9b29d93e47fb0b0968ad3df /library/core/src | |
| parent | ba14a836c7038da21f5e102aacc7e6d5964f79a6 (diff) | |
| download | rust-72a25d05bf1a4b155d74139ef700ff93af6d8e22.tar.gz rust-72a25d05bf1a4b155d74139ef700ff93af6d8e22.zip | |
Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new 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).
Diffstat (limited to 'library/core/src')
32 files changed, 149 insertions, 149 deletions
diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 72528185707..3b15ab1e689 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -62,7 +62,7 @@ //! println!("String ({}): {}", as_string.len(), as_string); //! } //! None => { -//! println!("{:?}", value); +//! println!("{value:?}"); //! } //! } //! } diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index aef7ad77568..9dbb5eecd46 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -85,7 +85,7 @@ //! // of scope then the subsequent borrow would cause a dynamic thread panic. //! // This is the major hazard of using `RefCell`. //! let total: i32 = shared_map.borrow().values().sum(); -//! println!("{}", total); +//! println!("{total}"); //! } //! ``` //! diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index c4c0a5a6c78..66de94d1b92 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -370,7 +370,7 @@ impl char { /// /// ``` /// for c in 'โค'.escape_unicode() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -448,7 +448,7 @@ impl char { /// /// ``` /// for c in '\n'.escape_debug() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -504,7 +504,7 @@ impl char { /// /// ``` /// for c in '"'.escape_default() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -949,7 +949,7 @@ impl char { /// /// ``` /// for c in 'ฤฐ'.to_lowercase() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -1016,7 +1016,7 @@ impl char { /// /// ``` /// for c in 'ร'.to_uppercase() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 90c5719f486..84cf1753f86 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -64,7 +64,7 @@ pub mod rt { /// /// let pythagorean_triple = Triangle { a: 3.0, b: 4.0, c: 5.0 }; /// -/// assert_eq!(format!("{}", pythagorean_triple), "(3, 4, 5)"); +/// assert_eq!(format!("{pythagorean_triple}"), "(3, 4, 5)"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub type Result = result::Result<(), Error>; @@ -174,7 +174,7 @@ pub trait Write { /// use std::fmt::{Error, Write}; /// /// fn writer<W: Write>(f: &mut W, s: &str) -> Result<(), Error> { - /// f.write_fmt(format_args!("{}", s)) + /// f.write_fmt(format_args!("{s}")) /// } /// /// let mut buf = String::new(); @@ -562,7 +562,7 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); +/// assert_eq!(format!("The origin is: {origin:?}"), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// /// Manually implementing: @@ -586,7 +586,7 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); +/// assert_eq!(format!("The origin is: {origin:?}"), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// /// There are a number of helper methods on the [`Formatter`] struct to help you with manual @@ -627,7 +627,7 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// assert_eq!(format!("The origin is: {:#?}", origin), +/// assert_eq!(format!("The origin is: {origin:#?}"), /// "The origin is: Point { /// x: 0, /// y: 0, @@ -670,9 +670,9 @@ pub trait Debug { /// } /// /// let position = Position { longitude: 1.987, latitude: 2.983 }; - /// assert_eq!(format!("{:?}", position), "(1.987, 2.983)"); + /// assert_eq!(format!("{position:?}"), "(1.987, 2.983)"); /// - /// assert_eq!(format!("{:#?}", position), "( + /// assert_eq!(format!("{position:#?}"), "( /// 1.987, /// 2.983, /// )"); @@ -724,7 +724,7 @@ pub use macros::Debug; /// /// let origin = Point { x: 0, y: 0 }; /// -/// assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)"); +/// assert_eq!(format!("The origin is: {origin}"), "The origin is: (0, 0)"); /// ``` #[rustc_on_unimplemented( on( @@ -786,8 +786,8 @@ pub trait Display { /// ``` /// let x = 42; // 42 is '52' in octal /// -/// assert_eq!(format!("{:o}", x), "52"); -/// assert_eq!(format!("{:#o}", x), "0o52"); +/// assert_eq!(format!("{x:o}"), "52"); +/// assert_eq!(format!("{x:#o}"), "0o52"); /// /// assert_eq!(format!("{:o}", -16), "37777777760"); /// ``` @@ -809,9 +809,9 @@ pub trait Display { /// /// let l = Length(9); /// -/// assert_eq!(format!("l as octal is: {:o}", l), "l as octal is: 11"); +/// assert_eq!(format!("l as octal is: {l:o}"), "l as octal is: 11"); /// -/// assert_eq!(format!("l as octal is: {:#06o}", l), "l as octal is: 0o0011"); +/// assert_eq!(format!("l as octal is: {l:#06o}"), "l as octal is: 0o0011"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Octal { @@ -840,8 +840,8 @@ pub trait Octal { /// ``` /// let x = 42; // 42 is '101010' in binary /// -/// assert_eq!(format!("{:b}", x), "101010"); -/// assert_eq!(format!("{:#b}", x), "0b101010"); +/// assert_eq!(format!("{x:b}"), "101010"); +/// assert_eq!(format!("{x:#b}"), "0b101010"); /// /// assert_eq!(format!("{:b}", -16), "11111111111111111111111111110000"); /// ``` @@ -863,10 +863,10 @@ pub trait Octal { /// /// let l = Length(107); /// -/// assert_eq!(format!("l as binary is: {:b}", l), "l as binary is: 1101011"); +/// assert_eq!(format!("l as binary is: {l:b}"), "l as binary is: 1101011"); /// /// assert_eq!( -/// format!("l as binary is: {:#032b}", l), +/// format!("l as binary is: {l:#032b}"), /// "l as binary is: 0b000000000000000000000001101011" /// ); /// ``` @@ -898,8 +898,8 @@ pub trait Binary { /// ``` /// let x = 42; // 42 is '2a' in hex /// -/// assert_eq!(format!("{:x}", x), "2a"); -/// assert_eq!(format!("{:#x}", x), "0x2a"); +/// assert_eq!(format!("{x:x}"), "2a"); +/// assert_eq!(format!("{x:#x}"), "0x2a"); /// /// assert_eq!(format!("{:x}", -16), "fffffff0"); /// ``` @@ -921,9 +921,9 @@ pub trait Binary { /// /// let l = Length(9); /// -/// assert_eq!(format!("l as hex is: {:x}", l), "l as hex is: 9"); +/// assert_eq!(format!("l as hex is: {l:x}"), "l as hex is: 9"); /// -/// assert_eq!(format!("l as hex is: {:#010x}", l), "l as hex is: 0x00000009"); +/// assert_eq!(format!("l as hex is: {l:#010x}"), "l as hex is: 0x00000009"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerHex { @@ -953,8 +953,8 @@ pub trait LowerHex { /// ``` /// let x = 42; // 42 is '2A' in hex /// -/// assert_eq!(format!("{:X}", x), "2A"); -/// assert_eq!(format!("{:#X}", x), "0x2A"); +/// assert_eq!(format!("{x:X}"), "2A"); +/// assert_eq!(format!("{x:#X}"), "0x2A"); /// /// assert_eq!(format!("{:X}", -16), "FFFFFFF0"); /// ``` @@ -976,9 +976,9 @@ pub trait LowerHex { /// /// let l = Length(i32::MAX); /// -/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF"); +/// assert_eq!(format!("l as hex is: {l:X}"), "l as hex is: 7FFFFFFF"); /// -/// assert_eq!(format!("l as hex is: {:#010X}", l), "l as hex is: 0x7FFFFFFF"); +/// assert_eq!(format!("l as hex is: {l:#010X}"), "l as hex is: 0x7FFFFFFF"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperHex { @@ -1003,7 +1003,7 @@ pub trait UpperHex { /// ``` /// let x = &42; /// -/// let address = format!("{:p}", x); // this produces something like '0x7f06092ac6d0' +/// let address = format!("{x:p}"); // this produces something like '0x7f06092ac6d0' /// ``` /// /// Implementing `Pointer` on a type: @@ -1024,9 +1024,9 @@ pub trait UpperHex { /// /// let l = Length(42); /// -/// println!("l is in memory here: {:p}", l); +/// println!("l is in memory here: {l:p}"); /// -/// let l_ptr = format!("{:018p}", l); +/// let l_ptr = format!("{l:018p}"); /// assert_eq!(l_ptr.len(), 18); /// assert_eq!(&l_ptr[..2], "0x"); /// ``` @@ -1054,7 +1054,7 @@ pub trait Pointer { /// ``` /// let x = 42.0; // 42.0 is '4.2e1' in scientific notation /// -/// assert_eq!(format!("{:e}", x), "4.2e1"); +/// assert_eq!(format!("{x:e}"), "4.2e1"); /// ``` /// /// Implementing `LowerExp` on a type: @@ -1074,12 +1074,12 @@ pub trait Pointer { /// let l = Length(100); /// /// assert_eq!( -/// format!("l in scientific notation is: {:e}", l), +/// format!("l in scientific notation is: {l:e}"), /// "l in scientific notation is: 1e2" /// ); /// /// assert_eq!( -/// format!("l in scientific notation is: {:05e}", l), +/// format!("l in scientific notation is: {l:05e}"), /// "l in scientific notation is: 001e2" /// ); /// ``` @@ -1105,7 +1105,7 @@ pub trait LowerExp { /// ``` /// let x = 42.0; // 42.0 is '4.2E1' in scientific notation /// -/// assert_eq!(format!("{:E}", x), "4.2E1"); +/// assert_eq!(format!("{x:E}"), "4.2E1"); /// ``` /// /// Implementing `UpperExp` on a type: @@ -1125,12 +1125,12 @@ pub trait LowerExp { /// let l = Length(100); /// /// assert_eq!( -/// format!("l in scientific notation is: {:E}", l), +/// format!("l in scientific notation is: {l:E}"), /// "l in scientific notation is: 1E2" /// ); /// /// assert_eq!( -/// format!("l in scientific notation is: {:05E}", l), +/// format!("l in scientific notation is: {l:05E}"), /// "l in scientific notation is: 001E2" /// ); /// ``` @@ -1429,8 +1429,8 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// assert_eq!(&format!("{:<4}", Foo), "Foo "); - /// assert_eq!(&format!("{:0>4}", Foo), "0Foo"); + /// assert_eq!(&format!("{Foo:<4}"), "Foo "); + /// assert_eq!(&format!("{Foo:0>4}"), "0Foo"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn pad(&mut self, s: &str) -> Result { @@ -1613,8 +1613,8 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// assert_eq!(&format!("{}", Foo), "Foo"); - /// assert_eq!(&format!("{:0>8}", Foo), "Foo"); + /// assert_eq!(&format!("{Foo}"), "Foo"); + /// assert_eq!(&format!("{Foo:0>8}"), "Foo"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn write_str(&mut self, data: &str) -> Result { @@ -1670,18 +1670,18 @@ impl<'a> Formatter<'a> { /// let c = formatter.fill(); /// if let Some(width) = formatter.width() { /// for _ in 0..width { - /// write!(formatter, "{}", c)?; + /// write!(formatter, "{c}")?; /// } /// Ok(()) /// } else { - /// write!(formatter, "{}", c) + /// write!(formatter, "{c}") /// } /// } /// } /// /// // We set alignment to the right with ">". - /// assert_eq!(&format!("{:G>3}", Foo), "GGG"); - /// assert_eq!(&format!("{:t>6}", Foo), "tttttt"); + /// assert_eq!(&format!("{Foo:G>3}"), "GGG"); + /// assert_eq!(&format!("{Foo:t>6}"), "tttttt"); /// ``` #[must_use] #[stable(feature = "fmt_flags", since = "1.5.0")] @@ -1711,14 +1711,14 @@ impl<'a> Formatter<'a> { /// } else { /// "into the void" /// }; - /// write!(formatter, "{}", s) + /// write!(formatter, "{s}") /// } /// } /// - /// assert_eq!(&format!("{:<}", Foo), "left"); - /// assert_eq!(&format!("{:>}", Foo), "right"); - /// assert_eq!(&format!("{:^}", Foo), "center"); - /// assert_eq!(&format!("{}", Foo), "into the void"); + /// assert_eq!(&format!("{Foo:<}"), "left"); + /// assert_eq!(&format!("{Foo:>}"), "right"); + /// assert_eq!(&format!("{Foo:^}"), "center"); + /// assert_eq!(&format!("{Foo}"), "into the void"); /// ``` #[must_use] #[stable(feature = "fmt_flags_align", since = "1.28.0")] diff --git a/library/core/src/iter/adapters/map.rs b/library/core/src/iter/adapters/map.rs index d2077a63e15..4b03449972c 100644 --- a/library/core/src/iter/adapters/map.rs +++ b/library/core/src/iter/adapters/map.rs @@ -34,7 +34,7 @@ use crate::ops::Try; /// /// for pair in ['a', 'b', 'c'].into_iter() /// .map(|letter| { c += 1; (letter, c) }) { -/// println!("{:?}", pair); +/// println!("{pair:?}"); /// } /// ``` /// @@ -52,7 +52,7 @@ use crate::ops::Try; /// for pair in ['a', 'b', 'c'].into_iter() /// .map(|letter| { c += 1; (letter, c) }) /// .rev() { -/// println!("{:?}", pair); +/// println!("{pair:?}"); /// } /// ``` #[must_use = "iterators are lazy and do nothing unless consumed"] diff --git a/library/core/src/iter/mod.rs b/library/core/src/iter/mod.rs index 65f56f64dbf..5a987733134 100644 --- a/library/core/src/iter/mod.rs +++ b/library/core/src/iter/mod.rs @@ -144,7 +144,7 @@ //! let values = vec![1, 2, 3, 4, 5]; //! //! for x in values { -//! println!("{}", x); +//! println!("{x}"); //! } //! ``` //! @@ -164,7 +164,7 @@ //! let values = vec![1, 2, 3, 4, 5]; //! //! for x in values { -//! println!("{}", x); +//! println!("{x}"); //! } //! ``` //! @@ -181,7 +181,7 @@ //! None => break, //! }; //! let x = next; -//! let () = { println!("{}", x); }; +//! let () = { println!("{x}"); }; //! }, //! }; //! result @@ -280,7 +280,7 @@ //! ``` //! # #![allow(unused_must_use)] //! let v = vec![1, 2, 3, 4, 5]; -//! v.iter().map(|x| println!("{}", x)); +//! v.iter().map(|x| println!("{x}")); //! ``` //! //! This will not print any values, as we only created an iterator, rather than @@ -297,10 +297,10 @@ //! ``` //! let v = vec![1, 2, 3, 4, 5]; //! -//! v.iter().for_each(|x| println!("{}", x)); +//! v.iter().for_each(|x| println!("{x}")); //! // or //! for x in &v { -//! println!("{}", x); +//! println!("{x}"); //! } //! ``` //! @@ -329,7 +329,7 @@ //! let five_numbers = numbers.take(5); //! //! for number in five_numbers { -//! println!("{}", number); +//! println!("{number}"); //! } //! ``` //! @@ -345,7 +345,7 @@ //! let ones = std::iter::repeat(1); //! let least = ones.min().unwrap(); // Oh no! An infinite loop! //! // `ones.min()` causes an infinite loop, so we won't reach this point! -//! println!("The smallest number one is {}.", least); +//! println!("The smallest number one is {least}."); //! ``` //! //! [`take`]: Iterator::take diff --git a/library/core/src/iter/sources/once.rs b/library/core/src/iter/sources/once.rs index 27bc3dcfd79..6e9ed0d3c52 100644 --- a/library/core/src/iter/sources/once.rs +++ b/library/core/src/iter/sources/once.rs @@ -48,7 +48,7 @@ use crate::iter::{FusedIterator, TrustedLen}; /// /// // this will give us all of the files in .foo as well as .foorc /// for f in files { -/// println!("{:?}", f); +/// println!("{f:?}"); /// } /// ``` #[stable(feature = "iter_once", since = "1.2.0")] diff --git a/library/core/src/iter/sources/once_with.rs b/library/core/src/iter/sources/once_with.rs index cf6a3c11524..d79f85c2559 100644 --- a/library/core/src/iter/sources/once_with.rs +++ b/library/core/src/iter/sources/once_with.rs @@ -52,7 +52,7 @@ use crate::iter::{FusedIterator, TrustedLen}; /// /// // this will give us all of the files in .foo as well as .foorc /// for f in files { -/// println!("{:?}", f); +/// println!("{f:?}"); /// } /// ``` #[inline] diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 637d7bc4488..31ce4a895e1 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -214,7 +214,7 @@ pub trait FromIterator<A>: Sized { /// { /// collection /// .into_iter() -/// .map(|item| format!("{:?}", item)) +/// .map(|item| format!("{item:?}")) /// .collect() /// } /// ``` @@ -332,7 +332,7 @@ impl<I: Iterator> IntoIterator for I { /// c.extend(vec![1, 2, 3]); /// /// // we've added these elements onto the end -/// assert_eq!("MyCollection([5, 6, 7, 1, 2, 3])", format!("{:?}", c)); +/// assert_eq!("MyCollection([5, 6, 7, 1, 2, 3])", format!("{c:?}")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend<A> { diff --git a/library/core/src/iter/traits/double_ended.rs b/library/core/src/iter/traits/double_ended.rs index a6aed6d210b..bdf94c792c2 100644 --- a/library/core/src/iter/traits/double_ended.rs +++ b/library/core/src/iter/traits/double_ended.rs @@ -281,7 +281,7 @@ pub trait DoubleEndedIterator: Iterator { /// let zero = "0".to_string(); /// /// let result = numbers.iter().rfold(zero, |acc, &x| { - /// format!("({} + {})", x, acc) + /// format!("({x} + {acc})") /// }); /// /// assert_eq!(result, "(1 + (2 + (3 + (4 + (5 + 0)))))"); diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index c35d0784dd5..d980f593081 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -709,13 +709,13 @@ pub trait Iterator { /// ``` /// # #![allow(unused_must_use)] /// // don't do this: - /// (0..5).map(|x| println!("{}", x)); + /// (0..5).map(|x| println!("{x}")); /// /// // it won't even execute, as it is lazy. Rust will warn you about this. /// /// // Instead, use for: /// for x in 0..5 { - /// println!("{}", x); + /// println!("{x}"); /// } /// ``` #[inline] @@ -761,7 +761,7 @@ pub trait Iterator { /// (0..5).flat_map(|x| x * 100 .. x * 110) /// .enumerate() /// .filter(|&(i, x)| (i + x) % 3 == 0) - /// .for_each(|(i, x)| println!("{}:{}", i, x)); + /// .for_each(|(i, x)| println!("{i}:{x}")); /// ``` #[inline] #[stable(feature = "iterator_for_each", since = "1.21.0")] @@ -1575,17 +1575,17 @@ pub trait Iterator { /// .filter(|x| x % 2 == 0) /// .fold(0, |sum, i| sum + i); /// - /// println!("{}", sum); + /// println!("{sum}"); /// /// // let's add some inspect() calls to investigate what's happening /// let sum = a.iter() /// .cloned() - /// .inspect(|x| println!("about to filter: {}", x)) + /// .inspect(|x| println!("about to filter: {x}")) /// .filter(|x| x % 2 == 0) - /// .inspect(|x| println!("made it through filter: {}", x)) + /// .inspect(|x| println!("made it through filter: {x}")) /// .fold(0, |sum, i| sum + i); /// - /// println!("{}", sum); + /// println!("{sum}"); /// ``` /// /// This will print: @@ -1611,13 +1611,13 @@ pub trait Iterator { /// .map(|line| line.parse::<i32>()) /// .inspect(|num| { /// if let Err(ref e) = *num { - /// println!("Parsing error: {}", e); + /// println!("Parsing error: {e}"); /// } /// }) /// .filter_map(Result::ok) /// .sum(); /// - /// println!("Sum: {}", sum); + /// println!("Sum: {sum}"); /// ``` /// /// This will print: @@ -2205,7 +2205,7 @@ pub trait Iterator { /// /// let data = ["no_tea.txt", "stale_bread.json", "torrential_rain.png"]; /// - /// let res = data.iter().try_for_each(|x| writeln!(stdout(), "{}", x)); + /// let res = data.iter().try_for_each(|x| writeln!(stdout(), "{x}")); /// assert!(res.is_ok()); /// /// let mut it = data.iter().cloned(); @@ -2319,7 +2319,7 @@ pub trait Iterator { /// let zero = "0".to_string(); /// /// let result = numbers.iter().fold(zero, |acc, &x| { - /// format!("({} + {})", acc, x) + /// format!("({acc} + {x})") /// }); /// /// assert_eq!(result, "(((((0 + 1) + 2) + 3) + 4) + 5)"); diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 65a2c3ff6ed..ba7ae55ec6f 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -895,7 +895,7 @@ pub(crate) mod builtin { /// /// ``` /// let path: &'static str = env!("PATH"); - /// println!("the $PATH variable at the time of compiling was: {}", path); + /// println!("the $PATH variable at the time of compiling was: {path}"); /// ``` /// /// You can customize the error message by passing a string as the second @@ -935,7 +935,7 @@ pub(crate) mod builtin { /// /// ``` /// let key: Option<&'static str> = option_env!("SECRET_KEY"); - /// println!("the secret key might be: {:?}", key); + /// println!("the secret key might be: {key:?}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_builtin_macro] @@ -1046,7 +1046,7 @@ pub(crate) mod builtin { /// /// ``` /// let current_line = line!(); - /// println!("defined on line: {}", current_line); + /// println!("defined on line: {current_line}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_builtin_macro] @@ -1074,7 +1074,7 @@ pub(crate) mod builtin { /// /// ``` /// let current_col = column!(); - /// println!("defined on column: {}", current_col); + /// println!("defined on column: {current_col}"); /// ``` /// /// `column!` counts Unicode code points, not bytes or graphemes. As a result, the first two @@ -1112,7 +1112,7 @@ pub(crate) mod builtin { /// /// ``` /// let this_file = file!(); - /// println!("defined in file: {}", this_file); + /// println!("defined in file: {this_file}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_builtin_macro] @@ -1176,7 +1176,7 @@ pub(crate) mod builtin { /// fn main() { /// let my_str = include_str!("spanish.in"); /// assert_eq!(my_str, "adiรณs\n"); - /// print!("{}", my_str); + /// print!("{my_str}"); /// } /// ``` /// @@ -1325,7 +1325,7 @@ pub(crate) mod builtin { /// fn main() { /// let my_string = include!("monkeys.in"); /// assert_eq!("๐๐๐๐๐๐", my_string); - /// println!("{}", my_string); + /// println!("{my_string}"); /// } /// ``` /// diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 71eea43aa54..82bac2640b4 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -219,7 +219,7 @@ pub trait StructuralEq { /// /// // `x` has moved into `y`, and so cannot be used /// -/// // println!("{:?}", x); // error: use of moved value +/// // println!("{x:?}"); // error: use of moved value /// ``` /// /// However, if a type implements `Copy`, it instead has 'copy semantics': @@ -236,7 +236,7 @@ pub trait StructuralEq { /// /// // `y` is a copy of `x` /// -/// println!("{:?}", x); // A-OK! +/// println!("{x:?}"); // A-OK! /// ``` /// /// It's important to note that in these two examples, the only difference is whether you diff --git a/library/core/src/num/dec2flt/mod.rs b/library/core/src/num/dec2flt/mod.rs index 2b280773e4c..d45ba595f1b 100644 --- a/library/core/src/num/dec2flt/mod.rs +++ b/library/core/src/num/dec2flt/mod.rs @@ -163,7 +163,7 @@ from_str_float_impl!(f64); /// use std::str::FromStr; /// /// if let Err(e) = f64::from_str("a.12") { -/// println!("Failed conversion to f64: {}", e); +/// println!("Failed conversion to f64: {e}"); /// } /// ``` #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 8a9ecbe98df..1a223016dae 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -61,7 +61,7 @@ impl const From<!> for TryFromIntError { /// /// ``` /// if let Err(e) = i32::from_str_radix("a12", 10) { -/// println!("Failed conversion to i32: {}", e); +/// println!("Failed conversion to i32: {e}"); /// } /// ``` #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 964378cc9c3..e2e569cb7ea 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -106,7 +106,7 @@ pub trait Index<Idx: ?Sized> { /// type Output = Weight; /// /// fn index(&self, index: Side) -> &Self::Output { -/// println!("Accessing {:?}-side of balance immutably", index); +/// println!("Accessing {index:?}-side of balance immutably"); /// match index { /// Side::Left => &self.left, /// Side::Right => &self.right, @@ -116,7 +116,7 @@ pub trait Index<Idx: ?Sized> { /// /// impl IndexMut<Side> for Balance { /// fn index_mut(&mut self, index: Side) -> &mut Self::Output { -/// println!("Accessing {:?}-side of balance mutably", index); +/// println!("Accessing {index:?}-side of balance mutably"); /// match index { /// Side::Left => &mut self.left, /// Side::Right => &mut self.right, diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 5029e0560b8..a3b14847342 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -653,7 +653,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> { /// map.insert(8, "c"); /// /// for (key, value) in map.range((Excluded(3), Included(8))) { -/// println!("{}: {}", key, value); +/// println!("{key}: {value}"); /// } /// /// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next()); diff --git a/library/core/src/option.rs b/library/core/src/option.rs index a6286f8d8d1..7d0c375cd4f 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -34,7 +34,7 @@ //! // Pattern match to retrieve the value //! match result { //! // The division was valid -//! Some(x) => println!("Result: {}", x), +//! Some(x) => println!("Result: {x}"), //! // The division was invalid //! None => println!("Cannot divide by 0"), //! } @@ -66,7 +66,7 @@ //! //! fn check_optional(optional: Option<Box<i32>>) { //! match optional { -//! Some(p) => println!("has value {}", p), +//! Some(p) => println!("has value {p}"), //! None => println!("has no value"), //! } //! } @@ -493,7 +493,7 @@ //! } //! //! match name_of_biggest_animal { -//! Some(name) => println!("the biggest animal is {}", name), +//! Some(name) => println!("the biggest animal is {name}"), //! None => println!("there are no animals :("), //! } //! ``` @@ -615,7 +615,7 @@ impl<T> Option<T> { /// // First, cast `Option<String>` to `Option<&String>` with `as_ref`, /// // then consume *that* with `map`, leaving `text` on the stack. /// let text_length: Option<usize> = text.as_ref().map(|s| s.len()); - /// println!("still can print text: {:?}", text); + /// println!("still can print text: {text:?}"); /// ``` #[inline] #[rustc_const_stable(feature = "const_option", since = "1.48.0")] @@ -918,10 +918,10 @@ impl<T> Option<T> { /// let v = vec![1, 2, 3, 4, 5]; /// /// // prints "got: 4" - /// let x: Option<&usize> = v.get(3).inspect(|x| println!("got: {}", x)); + /// let x: Option<&usize> = v.get(3).inspect(|x| println!("got: {x}")); /// /// // prints nothing - /// let x: Option<&usize> = v.get(5).inspect(|x| println!("got: {}", x)); + /// let x: Option<&usize> = v.get(5).inspect(|x| println!("got: {x}")); /// ``` #[inline] #[unstable(feature = "result_option_inspect", issue = "91345")] @@ -1976,7 +1976,7 @@ impl<'a, T> const From<&'a Option<T>> for Option<&'a T> { /// let s: Option<String> = Some(String::from("Hello, Rustaceans!")); /// let o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len()); /// - /// println!("Can still print s: {:?}", s); + /// println!("Can still print s: {s:?}"); /// /// assert_eq!(o, Some(18)); /// ``` diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index be8598fae09..1923155ebc1 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -16,7 +16,7 @@ use crate::panic::Location; /// /// panic::set_hook(Box::new(|panic_info| { /// if let Some(s) = panic_info.payload().downcast_ref::<&str>() { -/// println!("panic occurred: {:?}", s); +/// println!("panic occurred: {s:?}"); /// } else { /// println!("panic occurred"); /// } @@ -75,7 +75,7 @@ impl<'a> PanicInfo<'a> { /// /// panic::set_hook(Box::new(|panic_info| { /// if let Some(s) = panic_info.payload().downcast_ref::<&str>() { - /// println!("panic occurred: {:?}", s); + /// println!("panic occurred: {s:?}"); /// } else { /// println!("panic occurred"); /// } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 89cebaa653f..a908b1f3ba4 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -39,7 +39,7 @@ use crate::panic::{Location, PanicInfo}; #[rustc_const_unstable(feature = "core_panic", issue = "none")] #[lang = "panic"] // needed by codegen for panic on overflow and other `Assert` MIR terminators pub const fn panic(expr: &'static str) -> ! { - // Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially + // Use Arguments::new_v1 instead of format_args!("{expr}") to potentially // reduce size overhead. The format_args! macro uses str's Display trait to // write expr, which calls Formatter::pad, which must accommodate string // truncation and padding (even though none is used here). Using @@ -81,7 +81,7 @@ fn panic_bounds_check(index: usize, len: usize) -> ! { super::intrinsics::abort() } - panic!("index out of bounds: the len is {} but the index is {}", len, index) + panic!("index out of bounds: the len is {len} but the index is {index}") } // This function is called directly by the codegen backend, and must not have diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index ebb1d8971b9..225a679efd2 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -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}"); /// } /// ``` /// diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index ee544b4842e..75322066983 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -153,7 +153,7 @@ impl<T: ?Sized> *const T { /// /// unsafe { /// if let Some(val_back) = ptr.as_ref() { - /// println!("We got back the value: {}!", val_back); + /// println!("We got back the value: {val_back}!"); /// } /// } /// ``` @@ -169,7 +169,7 @@ impl<T: ?Sized> *const T { /// /// unsafe { /// let val_back = &*ptr; - /// println!("We got back the value: {}!", val_back); + /// println!("We got back the value: {val_back}!"); /// } /// ``` #[stable(feature = "ptr_as_ref", since = "1.9.0")] diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 3374b48c88c..861412703d3 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -160,7 +160,7 @@ impl<T: ?Sized> *mut T { /// /// unsafe { /// if let Some(val_back) = ptr.as_ref() { - /// println!("We got back the value: {}!", val_back); + /// println!("We got back the value: {val_back}!"); /// } /// } /// ``` @@ -176,7 +176,7 @@ impl<T: ?Sized> *mut T { /// /// unsafe { /// let val_back = &*ptr; - /// println!("We got back the value: {}!", val_back); + /// println!("We got back the value: {val_back}!"); /// } /// ``` #[stable(feature = "ptr_as_ref", since = "1.9.0")] @@ -409,7 +409,7 @@ impl<T: ?Sized> *mut T { /// let first_value = unsafe { ptr.as_mut().unwrap() }; /// *first_value = 4; /// # assert_eq!(s, [4, 2, 3]); - /// println!("{:?}", s); // It'll print: "[4, 2, 3]". + /// println!("{s:?}"); // It'll print: "[4, 2, 3]". /// ``` /// /// # Null-unchecked version @@ -424,7 +424,7 @@ impl<T: ?Sized> *mut T { /// let first_value = unsafe { &mut *ptr }; /// *first_value = 4; /// # assert_eq!(s, [4, 2, 3]); - /// println!("{:?}", s); // It'll print: "[4, 2, 3]". + /// println!("{s:?}"); // It'll print: "[4, 2, 3]". /// ``` #[stable(feature = "ptr_as_ref", since = "1.9.0")] #[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")] diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index c744ad5dd2d..a698aec51ca 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -314,7 +314,7 @@ impl<T: ?Sized> NonNull<T> { /// let ptr = NonNull::new(&mut x as *mut _).expect("ptr is null!"); /// /// let ref_x = unsafe { ptr.as_ref() }; - /// println!("{}", ref_x); + /// println!("{ref_x}"); /// ``` /// /// [the module documentation]: crate::ptr#safety diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 5a189f2b098..2d739bf295b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -35,8 +35,8 @@ //! //! let version = parse_version(&[1, 2, 3, 4]); //! match version { -//! Ok(v) => println!("working with version: {:?}", v), -//! Err(e) => println!("error parsing header: {:?}", e), +//! Ok(v) => println!("working with version: {v:?}"), +//! Err(e) => println!("error parsing header: {e:?}"), //! } //! ``` //! @@ -447,9 +447,9 @@ //! .collect(); //! assert_eq!(errs.len(), 3); //! assert_eq!(nums, [17, 99]); -//! println!("results {:?}", results); -//! println!("errs {:?}", errs); -//! println!("nums {:?}", nums); +//! println!("results {results:?}"); +//! println!("errs {errs:?}"); +//! println!("nums {nums:?}"); //! ``` //! //! ## Collecting into `Result` @@ -756,7 +756,7 @@ impl<T, E> Result<T, E> { /// /// for num in line.lines() { /// match num.parse::<i32>().map(|i| i * 2) { - /// Ok(n) => println!("{}", n), + /// Ok(n) => println!("{n}"), /// Err(..) => {} /// } /// } @@ -838,7 +838,7 @@ impl<T, E> Result<T, E> { /// Basic usage: /// /// ``` - /// fn stringify(x: u32) -> String { format!("error code: {}", x) } + /// fn stringify(x: u32) -> String { format!("error code: {x}") } /// /// let x: Result<u32, u32> = Ok(2); /// assert_eq!(x.map_err(stringify), Ok(2)); @@ -864,7 +864,7 @@ impl<T, E> Result<T, E> { /// /// let x: u8 = "4" /// .parse::<u8>() - /// .inspect(|x| println!("original: {}", x)) + /// .inspect(|x| println!("original: {x}")) /// .map(|x| x.pow(3)) /// .expect("failed to parse number"); /// ``` @@ -889,7 +889,7 @@ impl<T, E> Result<T, E> { /// /// fn read() -> io::Result<String> { /// fs::read_to_string("address.txt") - /// .inspect_err(|e| eprintln!("failed to read file: {}", e)) + /// .inspect_err(|e| eprintln!("failed to read file: {e}")) /// } /// ``` #[inline] @@ -1198,7 +1198,7 @@ impl<T, E> Result<T, E> { /// } /// /// let s: String = only_good_news().into_ok(); - /// println!("{}", s); + /// println!("{s}"); /// ``` #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] @@ -1235,7 +1235,7 @@ impl<T, E> Result<T, E> { /// } /// /// let error: String = only_bad_news().into_err(); - /// println!("{}", error); + /// println!("{error}"); /// ``` #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] @@ -1781,7 +1781,7 @@ impl<T> Result<T, T> { #[cold] #[track_caller] fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! { - panic!("{}: {:?}", msg, error) + panic!("{msg}: {error:?}") } // This is a separate function to avoid constructing a `dyn Debug` diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 7e6fbbe3538..3353c239866 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -48,7 +48,7 @@ const fn slice_start_index_len_fail(index: usize, len: usize) -> ! { // FIXME const-hack fn slice_start_index_len_fail_rt(index: usize, len: usize) -> ! { - panic!("range start index {} out of range for slice of length {}", index, len); + panic!("range start index {index} out of range for slice of length {len}"); } const fn slice_start_index_len_fail_ct(_: usize, _: usize) -> ! { @@ -69,7 +69,7 @@ const fn slice_end_index_len_fail(index: usize, len: usize) -> ! { // FIXME const-hack fn slice_end_index_len_fail_rt(index: usize, len: usize) -> ! { - panic!("range end index {} out of range for slice of length {}", index, len); + panic!("range end index {index} out of range for slice of length {len}"); } const fn slice_end_index_len_fail_ct(_: usize, _: usize) -> ! { @@ -88,7 +88,7 @@ const fn slice_index_order_fail(index: usize, end: usize) -> ! { // FIXME const-hack fn slice_index_order_fail_rt(index: usize, end: usize) -> ! { - panic!("slice index starts at {} but ends at {}", index, end); + panic!("slice index starts at {index} but ends at {end}"); } const fn slice_index_order_fail_ct(_: usize, _: usize) -> ! { diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index d260cc69469..82bd7dbcf6c 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -55,7 +55,7 @@ fn size_from_ptr<T>(_: *const T) -> usize { /// /// // Then, we iterate over it: /// for element in slice.iter() { -/// println!("{}", element); +/// println!("{element}"); /// } /// ``` /// @@ -176,7 +176,7 @@ impl<T> AsRef<[T]> for Iter<'_, T> { /// } /// /// // We now have "[2, 3, 4]": -/// println!("{:?}", slice); +/// println!("{slice:?}"); /// ``` /// /// [`iter_mut`]: slice::iter_mut @@ -266,7 +266,7 @@ impl<'a, T> IterMut<'a, T> { /// *iter.next().unwrap() += 1; /// } /// // Now slice is "[2, 2, 3]": - /// println!("{:?}", slice); + /// println!("{slice:?}"); /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "iter_to_slice", since = "1.4.0")] diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 7311fe40e04..166b3434372 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2012,7 +2012,7 @@ impl<T> [T] { /// let v = [10, 40, 30, 20, 60, 50]; /// /// for group in v.splitn(2, |num| *num % 3 == 0) { - /// println!("{:?}", group); + /// println!("{group:?}"); /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -2067,7 +2067,7 @@ impl<T> [T] { /// let v = [10, 40, 30, 20, 60, 50]; /// /// for group in v.rsplitn(2, |num| *num % 3 == 0) { - /// println!("{:?}", group); + /// println!("{group:?}"); /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index f66bab999a9..b1d36f27107 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -104,7 +104,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! { // 1. out of bounds if begin > s.len() || end > s.len() { let oob_index = if begin > s.len() { begin } else { end }; - panic!("byte index {} is out of bounds of `{}`{}", oob_index, s_trunc, ellipsis); + panic!("byte index {oob_index} is out of bounds of `{s_trunc}`{ellipsis}"); } // 2. begin <= end @@ -2446,7 +2446,7 @@ impl str { /// /// ``` /// for c in "โค\n!".escape_debug() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -2492,7 +2492,7 @@ impl str { /// /// ``` /// for c in "โค\n!".escape_default() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` @@ -2530,7 +2530,7 @@ impl str { /// /// ``` /// for c in "โค\n!".escape_unicode() { - /// print!("{}", c); + /// print!("{c}"); /// } /// println!(); /// ``` diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 2da04ab2cea..62103f5b075 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -94,7 +94,7 @@ //! } //! //! if let Err(panic) = thread.join() { -//! println!("Thread had an error: {:?}", panic); +//! println!("Thread had an error: {panic:?}"); //! } //! } //! ``` @@ -1345,7 +1345,7 @@ impl const From<bool> for AtomicBool { /// ``` /// use std::sync::atomic::AtomicBool; /// let atomic_bool = AtomicBool::from(true); - /// assert_eq!(format!("{:?}", atomic_bool), "true") + /// assert_eq!(format!("{atomic_bool:?}"), "true") /// ``` #[inline] fn from(b: bool) -> Self { diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 243c044b5d9..bd72d82b71c 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -1214,7 +1214,7 @@ impl fmt::Debug for Duration { /// use std::time::Duration; /// /// if let Err(e) = Duration::try_from_secs_f32(-1.0) { -/// println!("Failed conversion to Duration: {}", e); +/// println!("Failed conversion to Duration: {e}"); /// } /// ``` #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/library/core/src/unit.rs b/library/core/src/unit.rs index f41f4a5e94a..6656dd5c40b 100644 --- a/library/core/src/unit.rs +++ b/library/core/src/unit.rs @@ -9,7 +9,7 @@ use crate::iter::FromIterator; /// use std::io::*; /// let data = vec![1, 2, 3, 4, 5]; /// let res: Result<()> = data.iter() -/// .map(|x| writeln!(stdout(), "{}", x)) +/// .map(|x| writeln!(stdout(), "{x}")) /// .collect(); /// assert!(res.is_ok()); /// ``` |
