Skip to content

Commit bfd479d

Browse files
Merge pull request #4920 from calebcartwright/subtree-sync
subtree sync
2 parents 7872306 + 277feac commit bfd479d

22 files changed

+153
-52
lines changed

Diff for: CHANGELOG.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ https://rust-lang.github.io/rustfmt/?version=v1.4.33&search=#imports_granularity
176176

177177
### Changed
178178

179-
- Original comment indentation for trailing comments within an `if` is now taken into account when determining the indentation level to use for the trailing comment in formatted code. This does not modify any existing code formatted with rustfmt; it simply gives the programmer discretion to specify whether the comment is associated to the `else` block, or if the trailing comment is just a member of the `if` block. ([#1575](https://github.com/rust-lang/rustfmt/issues/1575), [#4120](https://github.com/rust-lang/rustfmt/issues/4120), [#4506](https://github.com/rust-lang/rustfmt/issues/4506))
179+
- Original comment indentation for trailing comments within an `if` is now taken into account when determining the indentation level to use for the trailing comment in formatted code. This does not modify any existing code formatted with rustfmt; it simply gives the programmer discretion to specify whether the comment is associated to the `else` block, or if the trailing comment is just a member of the `if` block. ([#1575](https://github.com/rust-lang/rustfmt/issues/1575), [#4120](https://github.com/rust-lang/rustfmt/issues/4120), [#4506](https://github.com/rust-lang/rustfmt/issues/4506))
180180

181181
In this example the `// else comment` refers to the `else`:
182182
```rust
@@ -213,7 +213,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels"
213213

214214
### Fixed
215215
- Formatting of empty blocks with attributes which only contained comments is no longer butchered.([#4475](https://github.com/rust-lang/rustfmt/issues/4475), [#4467](https://github.com/rust-lang/rustfmt/issues/4467), [#4452](https://github.com/rust-lang/rustfmt/issues/4452#issuecomment-705886282), [#4522](https://github.com/rust-lang/rustfmt/issues/4522))
216-
- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872))
216+
- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872))
217217

218218
### Install/Download Options
219219
- **crates.io package** - *pending*
@@ -297,7 +297,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels"
297297
- Fix aligning comments of different group
298298
- Fix flattening imports with a single `self`.
299299
- Fix removing attributes on function parameters.
300-
- Fix removing `impl` keyword from opaque type.
300+
- Fix removing `impl` keyword from opaque type.
301301

302302
## [1.4.8] 2019-09-08
303303

@@ -329,7 +329,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels"
329329

330330
- Add `--message-format` command line option to `cargo-fmt`.
331331
- Add `-l,--files-with-diff` command line option to `rustfmt`.
332-
- Add `json` emit mode.
332+
- Add `json` emit mode.
333333

334334
### Fixed
335335

@@ -380,7 +380,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels"
380380

381381
### Added
382382

383-
- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt
383+
- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt
384384
from formatting an attribute #3665
385385

386386
### Changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ unicode-segmentation = "1.0.0"
4242
regex = "1.0"
4343
term = "0.6"
4444
diff = "0.1"
45-
log = "0.4"
45+
log = "0.4.14"
4646
env_logger = "0.6"
4747
getopts = "0.2"
4848
derive-new = "0.5"

Diff for: Configurations.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or
1717

1818
Below you find a detailed visual guide on all the supported configuration options of rustfmt:
1919

20-
## `array_width`
20+
## `array_width`
2121

2222
Maximum width of an array literal before falling back to vertical formatting.
2323

2424
- **Default value**: `60`
2525
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
2626
- **Stable**: Yes
2727

28-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `array_width` will take precedence.
28+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `array_width` will take precedence.
2929

3030
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
3131

32-
## `attr_fn_like_width`
32+
## `attr_fn_like_width`
3333

3434
Maximum width of the args of a function-like attributes before falling back to vertical formatting.
3535

3636
- **Default value**: `70`
3737
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
3838
- **Stable**: Yes
3939

40-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `attr_fn_like_width` will take precedence.
40+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `attr_fn_like_width` will take precedence.
4141

4242
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
4343

@@ -295,15 +295,15 @@ where
295295
}
296296
```
297297

298-
## `chain_width`
298+
## `chain_width`
299299

300300
Maximum width of a chain to fit on one line.
301301

302302
- **Default value**: `60`
303303
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
304304
- **Stable**: Yes
305305

306-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `chain_width` will take precedence.
306+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `chain_width` will take precedence.
307307

308308
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
309309

@@ -751,15 +751,15 @@ trait Lorem {
751751
}
752752
```
753753

754-
## `fn_call_width`
754+
## `fn_call_width`
755755

756756
Maximum width of the args of a function call before falling back to vertical formatting.
757757

758758
- **Default value**: `60`
759759
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
760760
- **Stable**: Yes
761761

762-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `fn_call_width` will take precedence.
762+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `fn_call_width` will take precedence.
763763

764764
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
765765

@@ -2124,15 +2124,15 @@ Don't reformat out of line modules
21242124
- **Possible values**: `true`, `false`
21252125
- **Stable**: No (tracking issue: #3389)
21262126

2127-
## `single_line_if_else_max_width`
2127+
## `single_line_if_else_max_width`
21282128

21292129
Maximum line length for single line if-else expressions. A value of `0` (zero) results in if-else expressions always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`.
21302130

21312131
- **Default value**: `50`
21322132
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
21332133
- **Stable**: Yes
21342134

2135-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence.
2135+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence.
21362136

21372137
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
21382138

@@ -2313,27 +2313,27 @@ fn main() {
23132313

23142314
See also: [`indent_style`](#indent_style).
23152315

2316-
## `struct_lit_width`
2316+
## `struct_lit_width`
23172317

23182318
Maximum width in the body of a struct literal before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`.
23192319

23202320
- **Default value**: `18`
23212321
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
23222322
- **Stable**: Yes
23232323

2324-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_lit_width` will take precedence.
2324+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_lit_width` will take precedence.
23252325

23262326
See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line)
23272327

2328-
## `struct_variant_width`
2328+
## `struct_variant_width`
23292329

23302330
Maximum width in the body of a struct variant before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`.
23312331

23322332
- **Default value**: `35`
23332333
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
23342334
- **Stable**: Yes
23352335

2336-
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_variant_width` will take precedence.
2336+
By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_variant_width` will take precedence.
23372337

23382338
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
23392339

@@ -2530,7 +2530,7 @@ fn main() {
25302530

25312531
This option can be used to simplify the management and bulk updates of the granular width configuration settings ([`fn_call_width`](#fn_call_width), [`attr_fn_like_width`](#attr_fn_like_width), [`struct_lit_width`](#struct_lit_width), [`struct_variant_width`](#struct_variant_width), [`array_width`](#array_width), [`chain_width`](#chain_width), [`single_line_if_else_max_width`](#single_line_if_else_max_width)), that respectively control when formatted constructs are multi-lined/vertical based on width.
25322532

2533-
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
2533+
Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`.
25342534

25352535
- **Default value**: `"Default"`
25362536
- **Possible values**: `"Default"`, `"Off"`, `"Max"`
@@ -2595,7 +2595,7 @@ fn main() {
25952595
```
25962596

25972597
#### `Off`:
2598-
When `use_small_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics.
2598+
When `use_small_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics.
25992599

26002600
```rust
26012601
enum Lorem {

Diff for: Contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ colourised diff will be printed so that the offending line(s) can quickly be
3838
identified.
3939

4040
Without explicit settings, the tests will be run using rustfmt's default
41-
configuration. It is possible to run a test using non-default settings in several
41+
configuration. It is possible to run a test using non-default settings in several
4242
ways. Firstly, you can include configuration parameters in comments at the top
4343
of the file. For example: to use 3 spaces per tab, start your test with
4444
`// rustfmt-tab_spaces: 3`. Just remember that the comment is part of the input,

Diff for: Design.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ for its configuration.
150150

151151
Our visitor keeps track of the desired current indent due to blocks (
152152
`block_indent`). Each `visit_*` method reformats code according to this indent,
153-
`config.comment_width()` and `config.max_width()`. Most reformatting that is done
154-
in the `visit_*` methods is a bit hacky and is meant to be temporary until it can
153+
`config.comment_width()` and `config.max_width()`. Most reformatting that is done
154+
in the `visit_*` methods is a bit hacky and is meant to be temporary until it can
155155
be done properly.
156156

157157
There are a bunch of methods called `rewrite_*`. They do the bulk of the

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`.
180180

181181
* For things you do not want rustfmt to mangle, use `#[rustfmt::skip]`
182182
* To prevent rustfmt from formatting a macro or an attribute,
183-
use `#[rustfmt::skip::macros(target_macro_name)]` or
183+
use `#[rustfmt::skip::macros(target_macro_name)]` or
184184
`#[rustfmt::skip::attributes(target_attribute_name)]`
185185

186186
Example:
187187

188188
```rust
189-
#![rustfmt::skip::attributes(custom_attribute)]
189+
#![rustfmt::skip::attributes(custom_attribute)]
190190
191191
#[custom_attribute(formatting , here , should , be , Skipped)]
192192
#[rustfmt::skip::macros(html)]

Diff for: ci/integration.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -ex
1515
# it again.
1616
#
1717
#which cargo-fmt || cargo install --force
18-
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force
18+
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force
1919

2020
echo "Integration tests for: ${INTEGRATION}"
2121
cargo fmt -- --version

Diff for: docs/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
outputHtml() {
8686
const ast = this.configurationDescriptions
8787
.filter(({ head, text, stable }) => {
88-
88+
8989
if (
9090
text.includes(this.searchCondition) === false &&
9191
head.includes(this.searchCondition) === false
@@ -105,7 +105,7 @@
105105
},
106106
created: async function() {
107107
const res = await axios.get(ConfigurationMdUrl);
108-
const {
108+
const {
109109
about,
110110
configurationAbout,
111111
configurationDescriptions
@@ -144,7 +144,7 @@
144144
const lastIndex = stack.length - 1;
145145
stack[lastIndex].push(next);
146146
return stack;
147-
},
147+
},
148148
[[]]);
149149
});
150150
}
@@ -179,7 +179,7 @@
179179
configurationAbout, ...configurationDescriptions
180180
] = configurations;
181181
configurationAbout.value.links = {};
182-
182+
183183
return {
184184
about,
185185
configurationAbout: configurationAbout.value,

Diff for: src/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ pub(crate) fn format_expr(
107107
}
108108
ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
109109
ast::ExprKind::Struct(ref struct_expr) => {
110-
let ast::StructExpr { fields, path, rest } = &**struct_expr;
110+
let ast::StructExpr {
111+
fields, path, rest, ..
112+
} = &**struct_expr;
111113
rewrite_struct_lit(context, path, fields, rest, &expr.attrs, expr.span, shape)
112114
}
113115
ast::ExprKind::Tup(ref items) => {

Diff for: src/formatting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'b, T: Write + 'b> Session<'b, T> {
3434
return Err(ErrorKind::VersionMismatch);
3535
}
3636

37-
rustc_span::with_session_globals(self.config.edition().into(), || {
37+
rustc_span::create_session_if_not_set_then(self.config.edition().into(), |_| {
3838
if self.config.disable_all_formatting() {
3939
// When the input is from stdin, echo back the input.
4040
if let Input::Text(ref buf) = input {

Diff for: src/items.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering};
66
use regex::Regex;
77
use rustc_ast::visit;
88
use rustc_ast::{ast, ptr};
9-
use rustc_span::{symbol, BytePos, Span, DUMMY_SP};
9+
use rustc_span::{symbol, BytePos, Span};
1010

1111
use crate::attr::filter_inline_attrs;
1212
use crate::comment::{
@@ -31,12 +31,7 @@ use crate::stmt::Stmt;
3131
use crate::utils::*;
3232
use crate::vertical::rewrite_with_alignment;
3333
use crate::visitor::FmtVisitor;
34-
35-
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
36-
kind: ast::VisibilityKind::Inherited,
37-
span: DUMMY_SP,
38-
tokens: None,
39-
};
34+
use crate::DEFAULT_VISIBILITY;
4035

4136
fn type_annotation_separator(config: &Config) -> &str {
4237
colon_spaces(config)
@@ -976,7 +971,7 @@ impl<'a> StructParts<'a> {
976971
format_header(context, self.prefix, self.ident, self.vis, offset)
977972
}
978973

979-
fn from_variant(variant: &'a ast::Variant) -> Self {
974+
pub(crate) fn from_variant(variant: &'a ast::Variant) -> Self {
980975
StructParts {
981976
prefix: "",
982977
ident: variant.ident,

Diff for: src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(rustc_private)]
22
#![deny(rust_2018_idioms)]
33
#![warn(unreachable_pub)]
4+
#![recursion_limit = "256"]
45

56
#[macro_use]
67
extern crate derive_new;
@@ -31,7 +32,7 @@ use std::rc::Rc;
3132

3233
use ignore;
3334
use rustc_ast::ast;
34-
use rustc_span::symbol;
35+
use rustc_span::{symbol, DUMMY_SP};
3536
use thiserror::Error;
3637

3738
use crate::comment::LineClasses;
@@ -95,6 +96,11 @@ mod types;
9596
mod vertical;
9697
pub(crate) mod visitor;
9798

99+
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
100+
kind: ast::VisibilityKind::Inherited,
101+
span: DUMMY_SP,
102+
tokens: None,
103+
};
98104
/// The various errors that can occur during formatting. Note that not all of
99105
/// these can currently be propagated to clients.
100106
#[derive(Error, Debug)]

Diff for: src/modules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
318318
self.directory = directory;
319319
}
320320
match (sub_mod.ast_mod_kind, sub_mod.items) {
321-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => {
321+
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
322322
self.visit_mod_from_ast(&items)
323323
}
324324
(Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items),

Diff for: src/patterns.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
4545
| ast::PatKind::Path(..)
4646
| ast::PatKind::Range(..) => false,
4747
ast::PatKind::Tuple(ref subpats) => subpats.len() <= 1,
48-
ast::PatKind::TupleStruct(ref path, ref subpats) => {
48+
ast::PatKind::TupleStruct(_, ref path, ref subpats) => {
4949
path.segments.len() <= 1 && subpats.len() <= 1
5050
}
5151
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
@@ -226,7 +226,7 @@ impl Rewrite for Pat {
226226
PatKind::Path(ref q_self, ref path) => {
227227
rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)
228228
}
229-
PatKind::TupleStruct(ref path, ref pat_vec) => {
229+
PatKind::TupleStruct(_, ref path, ref pat_vec) => {
230230
let path_str = rewrite_path(context, PathContext::Expr, None, path, shape)?;
231231
rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape)
232232
}
@@ -244,7 +244,7 @@ impl Rewrite for Pat {
244244
.collect();
245245
Some(format!("[{}]", rw.join(", ")))
246246
}
247-
PatKind::Struct(ref path, ref fields, ellipsis) => {
247+
PatKind::Struct(_, ref path, ref fields, ellipsis) => {
248248
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
249249
}
250250
PatKind::MacCall(ref mac) => {

Diff for: src/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::source_file;
1616
use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session};
1717

1818
mod configuration_snippet;
19+
mod mod_resolver;
1920
mod parser;
2021

2122
const DIFF_CONTEXT_SIZE: usize = 3;

0 commit comments

Comments
 (0)