Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ADMIN_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This listing deliberately doesn't parse so rustfmt fails.
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this is very interesting... this seems good to be honest.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This listing deliberately doesn't parse so rustfmt fails.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 80
5 changes: 3 additions & 2 deletions tools/src/bin/release_listings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
//
// - `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<dyn Error>> {
Expand All @@ -84,8 +85,8 @@ fn copy_cleaned_listing_files(from: PathBuf, to: PathBuf) -> Result<(), Box<dyn
copy_cleaned_listing_files(item_path, output_item)?;
}
} else {
// Don't copy output files
if item_name != "output.txt" {
// Don't copy output files or files that tell update-rustc.sh not to format
if item_name != "output.txt" && item_name != "rustfmt-ignore" {
let item_extension = item_path.extension();
if item_extension.is_some() && item_extension.unwrap() == "rs" {
copy_cleaned_rust_file(item_name, &item_path, &output_item)?;
Expand Down
14 changes: 13 additions & 1 deletion tools/update-rustc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ set -eu
echo 'Building book into `tmp/book-before` before updating...'
mdbook build -d tmp/book-before

# TODO: Rustfmt all listings here
# Rustfmt all listings
echo 'Formatting all listings...'
find -s listings -name Cargo.toml -print0 | while IFS= read -r -d '' f; do
dir_to_fmt=$(dirname $f)

# There are a handful of listings we don't want to rustfmt and skipping doesn't work;
# those will have a file in their directory that explains why.
if [ ! -f "${dir_to_fmt}/rustfmt-ignore" ]; then
cd $dir_to_fmt
cargo fmt --all && true
cd - > /dev/null
fi
done

# Get listings without anchor comments in tmp by compiling a release listings artifact
echo 'Generate listings without anchor comments...'
Expand Down