From dec27eead05b38d5947754390505815cbbf537ca Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 24 Jan 2020 09:17:56 -0500 Subject: [PATCH] Add rustfmt to the update-rustc script With a mechanism to ignore particular listings for various reasons --- ADMIN_TASKS.md | 4 ++++ .../rustfmt-ignore | 1 + .../listing-04-01/rustfmt-ignore | 3 +++ .../listing-04-03/rustfmt-ignore | 3 +++ .../listing-04-04/rustfmt-ignore | 3 +++ .../no-listing-02-string-scope/rustfmt-ignore | 3 +++ .../rustfmt-ignore | 3 +++ .../rustfmt-ignore | 3 +++ .../listing-10-18/rustfmt-ignore | 3 +++ .../listing-10-19/rustfmt-ignore | 3 +++ .../output-only-01-adder-crate/add/rustfmt-ignore | 2 ++ .../listing-18-25/rustfmt-ignore | 1 + rustfmt.toml | 1 + tools/src/bin/release_listings.rs | 5 +++-- tools/update-rustc.sh | 14 +++++++++++++- 15 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/listing-04-01/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/listing-04-03/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/listing-04-04/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/no-listing-02-string-scope/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/rustfmt-ignore create mode 100644 listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/rustfmt-ignore create mode 100644 listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/rustfmt-ignore create mode 100644 listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/rustfmt-ignore create mode 100644 listings/ch14-more-about-cargo/output-only-01-adder-crate/add/rustfmt-ignore create mode 100644 listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore create mode 100644 rustfmt.toml diff --git a/ADMIN_TASKS.md b/ADMIN_TASKS.md index d12ccd61..ad02693a 100644 --- a/ADMIN_TASKS.md +++ b/ADMIN_TASKS.md @@ -68,6 +68,10 @@ listing beyond the most trivial should be extracted into a file. To do that: of user input or external events like making a web request), keep the output inline but make a comment that contains `manual-regeneration` and instructions for manually updating the inline output. +- If you don't want this example to even be attempted to be formatted by `rustfmt` (for example + because the example doesn't parse on purpose), add a `rustfmt-ignore` file in the listing's + directory and the reason it's not being formatted as the contents of that file (in case it's a + rustfmt bug that might get fixed someday). ## See the effect of some change on the rendered book diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/rustfmt-ignore b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/rustfmt-ignore new file mode 100644 index 00000000..06a976dd --- /dev/null +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/rustfmt-ignore @@ -0,0 +1 @@ +This listing deliberately doesn't parse so rustfmt fails. diff --git a/listings/ch04-understanding-ownership/listing-04-01/rustfmt-ignore b/listings/ch04-understanding-ownership/listing-04-01/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/listing-04-01/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch04-understanding-ownership/listing-04-03/rustfmt-ignore b/listings/ch04-understanding-ownership/listing-04-03/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/listing-04-03/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch04-understanding-ownership/listing-04-04/rustfmt-ignore b/listings/ch04-understanding-ownership/listing-04-04/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/listing-04-04/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch04-understanding-ownership/no-listing-02-string-scope/rustfmt-ignore b/listings/ch04-understanding-ownership/no-listing-02-string-scope/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-02-string-scope/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/rustfmt-ignore b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/rustfmt-ignore b/listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/rustfmt-ignore b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/rustfmt-ignore b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/rustfmt-ignore new file mode 100644 index 00000000..9a53c718 --- /dev/null +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/rustfmt-ignore @@ -0,0 +1,3 @@ +We have some weird comments pointing out borrowing scopes that we don't want to change; +unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to +manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028 diff --git a/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/rustfmt-ignore b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/rustfmt-ignore new file mode 100644 index 00000000..958e5683 --- /dev/null +++ b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/rustfmt-ignore @@ -0,0 +1,2 @@ +This listing is used for demonstrating how to set up a workspace, but the workspace isn't +completely set up yet, so rustfmt complains the crate mentioned in Cargo.toml doesn't exist yet. diff --git a/listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore b/listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore new file mode 100644 index 00000000..06a976dd --- /dev/null +++ b/listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore @@ -0,0 +1 @@ +This listing deliberately doesn't parse so rustfmt fails. diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..df99c691 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 80 diff --git a/tools/src/bin/release_listings.rs b/tools/src/bin/release_listings.rs index 3e5ea7c8..5b245ef6 100644 --- a/tools/src/bin/release_listings.rs +++ b/tools/src/bin/release_listings.rs @@ -67,6 +67,7 @@ fn main() -> Result<(), Box> { // // - `target` directories // - `output.txt` files used to display output in the book +// - `rustfmt-ignore` files used to signal to update-rustc.sh the listing shouldn't be formatted // - anchor comments or snip comments // - empty `main` functions in `lib.rs` files used to trick rustdoc fn copy_cleaned_listing_files(from: PathBuf, to: PathBuf) -> Result<(), Box> { @@ -84,8 +85,8 @@ fn copy_cleaned_listing_files(from: PathBuf, to: PathBuf) -> Result<(), Box /dev/null + fi +done # Get listings without anchor comments in tmp by compiling a release listings artifact echo 'Generate listings without anchor comments...'