X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=Contributing.md;h=bbd736ec98f5aed7a0e672ad5c878473fb6b3386;hb=613dfcc521e07088dbd72a8dcf484f002139f453;hp=ac3659c5cc749e239e91641f02eb471daf4f5e44;hpb=7dba56f97b1add226c01759c381616f0b6a75a85;p=rust.git diff --git a/Contributing.md b/Contributing.md index ac3659c5cc7..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! @@ -108,7 +111,7 @@ format. There are different nodes for every kind of item and expression in Rust. For more details see the source code in the compiler - [ast.rs](https://dxr.mozilla.org/rust/source/src/libsyntax/ast.rs) - and/or the -[docs](http://manishearth.github.io/rust-internals-docs/syntax/ast/index.html). +[docs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/index.html). Many nodes in the AST (but not all, annoyingly) have a `Span`. A `Span` is a range in the source code, it can easily be converted to a snippet of source @@ -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,9 +210,11 @@ 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.rs](src/config.rs). Look for the +handling of configuration options is done in [src/config/mod.rs](src/config/mod.rs). Look for the `create_config!` macro at the end of the file for all the options. The rest of the file defines a bunch of enums used for options, and the machinery to produce the config struct and parse a config file, etc. Checking an option is done by