Skip to content

Commit

Permalink
Merge pull request #3385 from nyurik/inlinefmt2
Browse files Browse the repository at this point in the history
Inline all format arguments
  • Loading branch information
chriskrycho authored Apr 19, 2024
2 parents 9622474 + 6196a0a commit 162d540
Show file tree
Hide file tree
Showing 88 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rust-book"
version = "0.0.1"
description = "The Rust Book"
edition = "2018"
edition = "2021"

[[bin]]
name = "concat_chapters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ fn main() {
// do stuff with s
} // this scope is now over, and s is no longer valid
// ANCHOR_END: here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fn main() {
// special happens.

fn takes_ownership(some_string: String) { // some_string comes into scope
println!("{}", some_string);
println!("{some_string}");
} // Here, some_string goes out of scope and `drop` is called. The backing
// memory is freed.

fn makes_copy(some_integer: i32) { // some_integer comes into scope
println!("{}", some_integer);
println!("{some_integer}");
} // Here, some_integer goes out of scope. Nothing special happens.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn main() {

s.push_str(", world!"); // push_str() appends a literal to a String

println!("{}", s); // This will print `hello, world!`
// ANCHOR_END: here
println!("{s}"); // This will print `hello, world!`
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ fn main() {
let s1 = String::from("hello");
let s2 = s1;

println!("{}, world!", s1);
println!("{s1}, world!");
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ fn main() {

let r1 = &s; // no problem
let r2 = &s; // no problem
println!("{} and {}", r1, r2);
println!("{r1} and {r2}");
// variables r1 and r2 will not be used after this point

let r3 = &mut s; // no problem
println!("{}", r3);
println!("{r3}");
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn main() {

s.clear(); // error!

println!("the first word is: {}", word);
println!("the first word is: {word}");
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ fn main() {
height: 50,
};

println!("rect1 is {:?}", rect1);
println!("rect1 is {rect1:?}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ fn main() {
height: 50,
};

println!("rect1 is {:#?}", rect1);
println!("rect1 is {rect1:#?}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
// ANCHOR: here
let config_max = Some(3u8);
match config_max {
Some(max) => println!("The maximum is configured to be {}", max),
Some(max) => println!("The maximum is configured to be {max}"),
_ => (),
}
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
// ANCHOR: here
let config_max = Some(3u8);
if let Some(max) = config_max {
println!("The maximum is configured to be {}", max);
println!("The maximum is configured to be {max}");
}
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pub mod garden;

fn main() {
let plant = Asparagus {};
println!("I'm growing {:?}!", plant);
println!("I'm growing {plant:?}!");
}
2 changes: 1 addition & 1 deletion listings/ch08-common-collections/listing-08-23/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main() {
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Blue"), 25);

println!("{:?}", scores);
println!("{scores:?}");
// ANCHOR_END: here
}
2 changes: 1 addition & 1 deletion listings/ch08-common-collections/listing-08-24/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ fn main() {
scores.entry(String::from("Yellow")).or_insert(50);
scores.entry(String::from("Blue")).or_insert(50);

println!("{:?}", scores);
println!("{scores:?}");
// ANCHOR_END: here
}
2 changes: 1 addition & 1 deletion listings/ch08-common-collections/listing-08-25/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
*count += 1;
}

println!("{:?}", map);
println!("{map:?}");
// ANCHOR_END: here
}
2 changes: 1 addition & 1 deletion listings/ch09-error-handling/listing-09-04/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ fn main() {

let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {:?}", error),
Err(error) => panic!("Problem opening the file: {error:?}"),
};
}
4 changes: 2 additions & 2 deletions listings/ch09-error-handling/listing-09-05/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ fn main() {
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
Ok(fc) => fc,
Err(e) => panic!("Problem creating the file: {:?}", e),
Err(e) => panic!("Problem creating the file: {e:?}"),
},
other_error => {
panic!("Problem opening the file: {:?}", other_error);
panic!("Problem opening the file: {other_error:?}");
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
}
}

println!("The largest number is {}", largest);
println!("The largest number is {largest}");
// ANCHOR_END: here
assert_eq!(*largest, 100);
// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
}
}

println!("The largest number is {}", largest);
println!("The largest number is {largest}");

let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];

Expand All @@ -21,5 +21,5 @@ fn main() {
}
}

println!("The largest number is {}", largest);
println!("The largest number is {largest}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];

let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 100);
// ANCHOR: here

let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];

let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 6000);
// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];

let result = largest_i32(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 100);
// ANCHOR: here

let char_list = vec!['y', 'm', 'a', 'q'];

let result = largest_char(&char_list);
println!("The largest char is {}", result);
println!("The largest char is {result}");
// ANCHOR_END: here
assert_eq!(*result, 'y');
// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];

let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");

let char_list = vec!['y', 'm', 'a', 'q'];

let result = largest(&char_list);
println!("The largest char is {}", result);
println!("The largest char is {result}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ fn main() {
r = &x;
}

println!("r: {}", r);
println!("r: {r}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ fn main() {
r = &x; // | |
} // -+ |
// |
println!("r: {}", r); // |
println!("r: {r}"); // |
} // ---------+
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ fn main() {
// |
let r = &x; // --+-- 'a |
// | |
println!("r: {}", r); // | |
println!("r: {r}"); // | |
// --+ |
} // ----------+
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn main() {
let string2 = "xyz";

let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";

let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";

let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
{
let string2 = String::from("xyz");
let result = longest(string1.as_str(), string2.as_str());
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
}
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ error[E0597]: `string2` does not live long enough
| ^^^^^^^ borrowed value does not live long enough
7 | }
| - `string2` dropped here while still borrowed
8 | println!("The longest string is {}", result);
| ------ borrow later used here
8 | println!("The longest string is {result}");
| ------ borrow later used here

For more information about this error, try `rustc --explain E0597`.
error: could not compile `chapter10` (bin "chapter10") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
}
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR_END: here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {
let string2 = "efghijklmnopqrstuvwxyz";

let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";

let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

// ANCHOR: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl<'a> ImportantExcerpt<'a> {
// ANCHOR: 3rd
impl<'a> ImportantExcerpt<'a> {
fn announce_and_return_part(&self, announcement: &str) -> &str {
println!("Attention please: {}", announcement);
println!("Attention please: {announcement}");
self.part
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
string2,
"Today is someone's birthday!",
);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

// ANCHOR: here
Expand All @@ -21,7 +21,7 @@ fn longest_with_an_announcement<'a, T>(
where
T: Display,
{
println!("Announcement! {}", ann);
println!("Announcement! {ann}");
if x.len() > y.len() {
x
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn prints_and_returns_10(a: i32) -> i32 {
println!("I got the value {}", a);
println!("I got the value {a}");
10
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn prints_and_returns_10(a: i32) -> i32 {
println!("I got the value {}", a);
println!("I got the value {a}");
10
}

Expand Down
4 changes: 2 additions & 2 deletions listings/ch12-an-io-project/listing-12-02/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() {
let query = &args[1];
let file_path = &args[2];

println!("Searching for {}", query);
println!("In file {}", file_path);
println!("Searching for {query}");
println!("In file {file_path}");
}
4 changes: 2 additions & 2 deletions listings/ch12-an-io-project/listing-12-03/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() {
let query = &args[1];
let file_path = &args[2];

println!("Searching for {}", query);
println!("In file {}", file_path);
println!("Searching for {query}");
println!("In file {file_path}");
}
4 changes: 2 additions & 2 deletions listings/ch12-an-io-project/listing-12-04/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fn main() {
let query = &args[1];
let file_path = &args[2];

println!("Searching for {}", query);
println!("Searching for {query}");
// ANCHOR: here
println!("In file {}", file_path);
println!("In file {file_path}");

let contents = fs::read_to_string(file_path)
.expect("Should have been able to read the file");
Expand Down
Loading

0 comments on commit 162d540

Please sign in to comment.