X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=Contributing.md;h=bbd736ec98f5aed7a0e672ad5c878473fb6b3386;hb=b8a133d432fc5af0eee5bb30d05b1e07875aea72;hp=9478bc89f3ba27b1906b20015b7ea238f31904a0;hpb=888abbb0ec5db10e5117de12077c9a4b2cd3c417;p=rust.git diff --git a/Contributing.md b/Contributing.md index 9478bc89f3b..bbd736ec98f 100644 --- a/Contributing.md +++ b/Contributing.md @@ -64,6 +64,9 @@ would need a configuration file named `test-indent.toml` in that directory. As a example, the `issue-1111.rs` test file is configured by the file `./tests/config/issue-1111.toml`. +## Debugging + +Some `rewrite_*` methods use the `debug!` macro for printing useful information. These messages can be printed by using the environment variable `RUST_LOG=rustfmt=DEBUG`. These traces can be helpful in understanding which part of the code was used and get a better grasp on the execution flow. ## Hack! @@ -153,6 +156,8 @@ which is how much we are currently indented from the lhs of the page. We also take a context which contains information used for parsing, the current block indent, and a configuration (see below). +##### Rewrite and Indent + To understand the indents, consider ``` @@ -195,6 +200,8 @@ checked subtraction: `available_space = budget.checked_sub(overhead)?`. `checked_sub` returns an `Option`, and if we would underflow `?` returns `None`, otherwise we proceed with the computed space. +##### Rewrite of list-like expressions + Much syntax in Rust is lists: lists of arguments, lists of fields, lists of array elements, etc. We have some generic code to handle lists, including how to space them in horizontal and vertical space, indentation, comments between @@ -203,6 +210,8 @@ code is a bit complex. Look in [src/lists.rs](src/lists.rs). `write_list` is the and `ListFormatting` the key structure for configuration. You'll need to make a `ListItems` for input, this is usually done using `itemize_list`. +##### Configuration + Rustfmt strives to be highly configurable. Often the first part of a patch is creating a configuration option for the feature you are implementing. All handling of configuration options is done in [src/config/mod.rs](src/config/mod.rs). Look for the