Skip to content

Commit 72a25d0

Browse files
mahmoud-moursyMark-Simulacrum
authored andcommitted
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).
1 parent ba14a83 commit 72a25d0

File tree

177 files changed

+724
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+724
-734
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,12 @@ impl HandlerInner {
10871087
let warnings = match self.deduplicated_warn_count {
10881088
0 => String::new(),
10891089
1 => "1 warning emitted".to_string(),
1090-
count => format!("{} warnings emitted", count),
1090+
count => format!("{count} warnings emitted"),
10911091
};
10921092
let errors = match self.deduplicated_err_count {
10931093
0 => String::new(),
10941094
1 => "aborting due to previous error".to_string(),
1095-
count => format!("aborting due to {} previous errors", count),
1095+
count => format!("aborting due to {count} previous errors"),
10961096
};
10971097
if self.treat_err_as_bug() {
10981098
return;

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3399,7 +3399,7 @@ declare_lint! {
33993399
/// // ^^^^^^^^
34003400
/// // This call to try_into matches both Foo:try_into and TryInto::try_into as
34013401
/// // `TryInto` has been added to the Rust prelude in 2021 edition.
3402-
/// println!("{}", x);
3402+
/// println!("{x}");
34033403
/// }
34043404
/// ```
34053405
///

compiler/rustc_middle/src/ty/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub struct CaptureInfo {
281281
/// let mut t = (0,1);
282282
///
283283
/// let c = || {
284-
/// println!("{}",t); // L1
284+
/// println!("{t}"); // L1
285285
/// t.1 = 4; // L2
286286
/// };
287287
/// ```

compiler/rustc_typeck/src/check/upvar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
458458
/// let s: String; // hir_id_s
459459
/// let mut p: Point; // his_id_p
460460
/// let c = || {
461-
/// println!("{}", s); // L1
461+
/// println!("{s}"); // L1
462462
/// p.x += 10; // L2
463-
/// println!("{}" , p.y) // L3
464-
/// println!("{}", p) // L4
463+
/// println!("{}" , p.y); // L3
464+
/// println!("{p}"); // L4
465465
/// drop(s); // L5
466466
/// };
467467
/// ```

library/alloc/src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub mod __alloc_error_handler {
397397
// if there is no `#[alloc_error_handler]`
398398
#[rustc_std_internal_symbol]
399399
pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! {
400-
panic!("memory allocation of {} bytes failed", size)
400+
panic!("memory allocation of {size} bytes failed")
401401
}
402402

403403
// if there is an `#[alloc_error_handler]`

library/alloc/src/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ where
161161
/// let readonly = [1, 2];
162162
/// let borrowed = Items::new((&readonly[..]).into());
163163
/// match borrowed {
164-
/// Items { values: Cow::Borrowed(b) } => println!("borrowed {:?}", b),
164+
/// Items { values: Cow::Borrowed(b) } => println!("borrowed {b:?}"),
165165
/// _ => panic!("expect borrowed value"),
166166
/// }
167167
///

library/alloc/src/boxed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//! }
3232
//!
3333
//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil))));
34-
//! println!("{:?}", list);
34+
//! println!("{list:?}");
3535
//! ```
3636
//!
3737
//! This will print `Cons(1, Cons(2, Nil))`.
@@ -1408,7 +1408,7 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
14081408
/// let slice: &[u8] = &[104, 101, 108, 108, 111];
14091409
/// let boxed_slice: Box<[u8]> = Box::from(slice);
14101410
///
1411-
/// println!("{:?}", boxed_slice);
1411+
/// println!("{boxed_slice:?}");
14121412
/// ```
14131413
fn from(slice: &[T]) -> Box<[T]> {
14141414
let len = slice.len();
@@ -1450,7 +1450,7 @@ impl From<&str> for Box<str> {
14501450
///
14511451
/// ```rust
14521452
/// let boxed: Box<str> = Box::from("hello");
1453-
/// println!("{}", boxed);
1453+
/// println!("{boxed}");
14541454
/// ```
14551455
#[inline]
14561456
fn from(s: &str) -> Box<str> {
@@ -1475,14 +1475,14 @@ impl From<Cow<'_, str>> for Box<str> {
14751475
///
14761476
/// let unboxed = Cow::Borrowed("hello");
14771477
/// let boxed: Box<str> = Box::from(unboxed);
1478-
/// println!("{}", boxed);
1478+
/// println!("{boxed}");
14791479
/// ```
14801480
///
14811481
/// ```rust
14821482
/// # use std::borrow::Cow;
14831483
/// let unboxed = Cow::Owned("hello".to_string());
14841484
/// let boxed: Box<str> = Box::from(unboxed);
1485-
/// println!("{}", boxed);
1485+
/// println!("{boxed}");
14861486
/// ```
14871487
#[inline]
14881488
fn from(cow: Cow<'_, str>) -> Box<str> {
@@ -1529,7 +1529,7 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
15291529
///
15301530
/// ```rust
15311531
/// let boxed: Box<[u8]> = Box::from([4, 2]);
1532-
/// println!("{:?}", boxed);
1532+
/// println!("{boxed:?}");
15331533
/// ```
15341534
fn from(array: [T; N]) -> Box<[T]> {
15351535
box array

library/alloc/src/collections/binary_heap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ use super::SpecExtend;
194194
/// // We can iterate over the items in the heap, although they are returned in
195195
/// // a random order.
196196
/// for x in &heap {
197-
/// println!("{}", x);
197+
/// println!("{x}");
198198
/// }
199199
///
200200
/// // If we instead pop these scores, they should come back in order.
@@ -830,7 +830,7 @@ impl<T> BinaryHeap<T> {
830830
///
831831
/// // Print 1, 2, 3, 4 in arbitrary order
832832
/// for x in heap.iter() {
833-
/// println!("{}", x);
833+
/// println!("{x}");
834834
/// }
835835
/// ```
836836
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1110,7 +1110,7 @@ impl<T> BinaryHeap<T> {
11101110
///
11111111
/// // Will print in some order
11121112
/// for x in vec {
1113-
/// println!("{}", x);
1113+
/// println!("{x}");
11141114
/// }
11151115
/// ```
11161116
#[must_use = "`self` will be dropped if the result is not used"]
@@ -1179,7 +1179,7 @@ impl<T> BinaryHeap<T> {
11791179
/// assert!(!heap.is_empty());
11801180
///
11811181
/// for x in heap.drain() {
1182-
/// println!("{}", x);
1182+
/// println!("{x}");
11831183
/// }
11841184
///
11851185
/// assert!(heap.is_empty());
@@ -1624,7 +1624,7 @@ impl<T> IntoIterator for BinaryHeap<T> {
16241624
/// // Print 1, 2, 3, 4 in arbitrary order
16251625
/// for x in heap.into_iter() {
16261626
/// // x has type i32, not &i32
1627-
/// println!("{}", x);
1627+
/// println!("{x}");
16281628
/// }
16291629
/// ```
16301630
fn into_iter(self) -> IntoIter<T> {

library/alloc/src/collections/btree/map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
104104
/// let to_find = ["Up!", "Office Space"];
105105
/// for movie in &to_find {
106106
/// match movie_reviews.get(movie) {
107-
/// Some(review) => println!("{}: {}", movie, review),
108-
/// None => println!("{} is unreviewed.", movie)
107+
/// Some(review) => println!("{movie}: {review}"),
108+
/// None => println!("{movie} is unreviewed.")
109109
/// }
110110
/// }
111111
///
@@ -114,7 +114,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
114114
///
115115
/// // iterate over everything.
116116
/// for (movie, review) in &movie_reviews {
117-
/// println!("{}: \"{}\"", movie, review);
117+
/// println!("{movie}: \"{review}\"");
118118
/// }
119119
/// ```
120120
///
@@ -1061,7 +1061,7 @@ impl<K, V> BTreeMap<K, V> {
10611061
/// map.insert(5, "b");
10621062
/// map.insert(8, "c");
10631063
/// for (&key, &value) in map.range((Included(&4), Included(&8))) {
1064-
/// println!("{}: {}", key, value);
1064+
/// println!("{key}: {value}");
10651065
/// }
10661066
/// assert_eq!(Some((&5, &"b")), map.range(4..).next());
10671067
/// ```
@@ -1104,7 +1104,7 @@ impl<K, V> BTreeMap<K, V> {
11041104
/// *balance += 100;
11051105
/// }
11061106
/// for (name, balance) in &map {
1107-
/// println!("{} => {}", name, balance);
1107+
/// println!("{name} => {balance}");
11081108
/// }
11091109
/// ```
11101110
#[stable(feature = "btree_range", since = "1.17.0")]
@@ -2088,7 +2088,7 @@ impl<K, V> BTreeMap<K, V> {
20882088
/// map.insert(1, "a");
20892089
///
20902090
/// for (key, value) in map.iter() {
2091-
/// println!("{}: {}", key, value);
2091+
/// println!("{key}: {value}");
20922092
/// }
20932093
///
20942094
/// let (first_key, first_value) = map.iter().next().unwrap();

library/alloc/src/collections/btree/map/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ fn test_ord_absence() {
17581758
}
17591759

17601760
fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
1761-
format!("{:?}", map);
1761+
format!("{map:?}");
17621762
format!("{:?}", map.iter());
17631763
format!("{:?}", map.iter_mut());
17641764
format!("{:?}", map.keys());

0 commit comments

Comments
 (0)