From d67f1a48efbcdc689c69b6218ec55b541ebf8c7a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 May 2021 16:56:25 -0400 Subject: [PATCH 1/9] Update log to 0.4.14 This avoids the following warning: ``` warning: trailing semicolon in macro used in expression position --> /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.11/src/macros.rs:152:45 | 147 | / macro_rules! debug { 148 | | (target: $target:expr, $($arg:tt)+) => ( 149 | | log!(target: $target, $crate::Level::Debug, $($arg)+); 150 | | ); 151 | | ($($arg:tt)+) => ( 152 | | log!($crate::Level::Debug, $($arg)+); | | ^ 153 | | ) 154 | | } | |_- in this expansion of `debug!` | ::: src/tools/rustfmt/src/modules/visitor.rs:36:23 | 36 | Err(e) => debug!("{}", e), | --------------- in this macro invocation | = note: requested on the command line with `-W semicolon-in-expressions-from-macros` = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #79813 ``` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 24b3b79343b..3a04fb28f7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ unicode-segmentation = "1.0.0" regex = "1.0" term = "0.6" diff = "0.1" -log = "0.4" +log = "0.4.14" env_logger = "0.6" getopts = "0.2" derive-new = "0.5" From e243be6adad16ad65c3349e476d528d1f416ed59 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Sun, 16 May 2021 22:13:38 -0500 Subject: [PATCH 2/9] Allow formatting `Anonymous{Struct, Union}` declarations --- src/items.rs | 11 +++------- src/lib.rs | 7 ++++++- src/types.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/items.rs b/src/items.rs index ecbd0bd12ec..420484c0ba1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering}; use regex::Regex; use rustc_ast::visit; use rustc_ast::{ast, ptr}; -use rustc_span::{symbol, BytePos, Span, DUMMY_SP}; +use rustc_span::{symbol, BytePos, Span}; use crate::attr::filter_inline_attrs; use crate::comment::{ @@ -31,12 +31,7 @@ use crate::stmt::Stmt; use crate::utils::*; use crate::vertical::rewrite_with_alignment; use crate::visitor::FmtVisitor; - -const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility { - kind: ast::VisibilityKind::Inherited, - span: DUMMY_SP, - tokens: None, -}; +use crate::DEFAULT_VISIBILITY; fn type_annotation_separator(config: &Config) -> &str { colon_spaces(config) @@ -976,7 +971,7 @@ impl<'a> StructParts<'a> { format_header(context, self.prefix, self.ident, self.vis, offset) } - fn from_variant(variant: &'a ast::Variant) -> Self { + pub(crate) fn from_variant(variant: &'a ast::Variant) -> Self { StructParts { prefix: "", ident: variant.ident, diff --git a/src/lib.rs b/src/lib.rs index 8a798777e0e..cde5d390cf2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ use std::rc::Rc; use ignore; use rustc_ast::ast; -use rustc_span::symbol; +use rustc_span::{symbol, DUMMY_SP}; use thiserror::Error; use crate::comment::LineClasses; @@ -95,6 +95,11 @@ mod types; mod vertical; pub(crate) mod visitor; +const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility { + kind: ast::VisibilityKind::Inherited, + span: DUMMY_SP, + tokens: None, +}; /// The various errors that can occur during formatting. Note that not all of /// these can currently be propagated to clients. #[derive(Error, Debug)] diff --git a/src/types.rs b/src/types.rs index cda17e13eeb..5597af9ee32 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,14 +2,14 @@ use std::iter::ExactSizeIterator; use std::ops::Deref; use rustc_ast::ast::{self, FnRetTy, Mutability}; -use rustc_span::{symbol::kw, BytePos, Pos, Span}; +use rustc_span::{symbol::kw, symbol::Ident, BytePos, Pos, Span}; -use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; use crate::config::{IndentStyle, TypeDensity, Version}; use crate::expr::{ format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType, }; +use crate::items::StructParts; use crate::lists::{ definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator, }; @@ -24,6 +24,11 @@ use crate::utils::{ colon_spaces, extra_offset, first_line_width, format_extern, format_mutability, last_line_extendable, last_line_width, mk_sp, rewrite_ident, }; +use crate::DEFAULT_VISIBILITY; +use crate::{ + comment::{combine_strs_with_missing_comments, contains_comment}, + items::format_struct_struct, +}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(crate) enum PathContext { @@ -764,6 +769,54 @@ impl Rewrite for ast::Ty { ast::TyKind::Tup(ref items) => { rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1) } + ast::TyKind::AnonymousStruct(ref fields, recovered) => { + let ident = Ident::new( + kw::Struct, + mk_sp(self.span.lo(), self.span.lo() + BytePos(6)), + ); + let data = ast::VariantData::Struct(fields.clone(), recovered); + let variant = ast::Variant { + attrs: vec![], + id: self.id, + span: self.span, + vis: DEFAULT_VISIBILITY, + ident, + data, + disr_expr: None, + is_placeholder: false, + }; + format_struct_struct( + &context, + &StructParts::from_variant(&variant), + fields, + shape.indent, + None, + ) + } + ast::TyKind::AnonymousUnion(ref fields, recovered) => { + let ident = Ident::new( + kw::Union, + mk_sp(self.span.lo(), self.span.lo() + BytePos(5)), + ); + let data = ast::VariantData::Struct(fields.clone(), recovered); + let variant = ast::Variant { + attrs: vec![], + id: self.id, + span: self.span, + vis: DEFAULT_VISIBILITY, + ident, + data, + disr_expr: None, + is_placeholder: false, + }; + format_struct_struct( + &context, + &StructParts::from_variant(&variant), + fields, + shape.indent, + None, + ) + } ast::TyKind::Path(ref q_self, ref path) => { rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape) } From 58c63cf8dec2b7d97667932c17248f774dd6e1ab Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Thu, 10 Dec 2020 13:20:07 +0100 Subject: [PATCH 3/9] Add support for using qualified paths with structs in expression and pattern position. --- src/expr.rs | 4 +++- src/patterns.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index ced382c4915..bca9f77f959 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -107,7 +107,9 @@ pub(crate) fn format_expr( } ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape), ast::ExprKind::Struct(ref struct_expr) => { - let ast::StructExpr { fields, path, rest } = &**struct_expr; + let ast::StructExpr { + fields, path, rest, .. + } = &**struct_expr; rewrite_struct_lit(context, path, fields, rest, &expr.attrs, expr.span, shape) } ast::ExprKind::Tup(ref items) => { diff --git a/src/patterns.rs b/src/patterns.rs index 6824fc661ba..fa0ef260991 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -45,7 +45,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool { | ast::PatKind::Path(..) | ast::PatKind::Range(..) => false, ast::PatKind::Tuple(ref subpats) => subpats.len() <= 1, - ast::PatKind::TupleStruct(ref path, ref subpats) => { + ast::PatKind::TupleStruct(_, ref path, ref subpats) => { path.segments.len() <= 1 && subpats.len() <= 1 } ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => { @@ -226,7 +226,7 @@ impl Rewrite for Pat { PatKind::Path(ref q_self, ref path) => { rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape) } - PatKind::TupleStruct(ref path, ref pat_vec) => { + PatKind::TupleStruct(_, ref path, ref pat_vec) => { let path_str = rewrite_path(context, PathContext::Expr, None, path, shape)?; rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape) } @@ -244,7 +244,7 @@ impl Rewrite for Pat { .collect(); Some(format!("[{}]", rw.join(", "))) } - PatKind::Struct(ref path, ref fields, ellipsis) => { + PatKind::Struct(_, ref path, ref fields, ellipsis) => { rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape) } PatKind::MacCall(ref mac) => { From 1e2258ffa949bf4d273259e78d326857c0b2bb3d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 17 Jun 2021 07:11:13 +0900 Subject: [PATCH 4/9] Use `AttrVec` for `Arm`, `FieldDef`, and `Variant` --- src/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index 5597af9ee32..974c0c5990c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,7 @@ use std::iter::ExactSizeIterator; use std::ops::Deref; -use rustc_ast::ast::{self, FnRetTy, Mutability}; +use rustc_ast::ast::{self, AttrVec, FnRetTy, Mutability}; use rustc_span::{symbol::kw, symbol::Ident, BytePos, Pos, Span}; use crate::config::lists::*; @@ -776,7 +776,7 @@ impl Rewrite for ast::Ty { ); let data = ast::VariantData::Struct(fields.clone(), recovered); let variant = ast::Variant { - attrs: vec![], + attrs: AttrVec::new(), id: self.id, span: self.span, vis: DEFAULT_VISIBILITY, @@ -800,7 +800,7 @@ impl Rewrite for ast::Ty { ); let data = ast::VariantData::Struct(fields.clone(), recovered); let variant = ast::Variant { - attrs: vec![], + attrs: AttrVec::new(), id: self.id, span: self.span, vis: DEFAULT_VISIBILITY, From 2608f2c63bbc565cffd02514c997511ac31f74aa Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Thu, 17 Jun 2021 22:35:19 -0500 Subject: [PATCH 5/9] fix(rustfmt): load nested out-of-line mods correctly --- src/modules.rs | 2 +- src/test/mod.rs | 1 + src/test/mod_resolver.rs | 25 ++++++++++++++++++++++++ tests/mod-resolver/issue-4874/bar/baz.rs | 5 +++++ tests/mod-resolver/issue-4874/foo.rs | 1 + tests/mod-resolver/issue-4874/foo/qux.rs | 5 +++++ tests/mod-resolver/issue-4874/main.rs | 8 ++++++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/test/mod_resolver.rs create mode 100644 tests/mod-resolver/issue-4874/bar/baz.rs create mode 100644 tests/mod-resolver/issue-4874/foo.rs create mode 100644 tests/mod-resolver/issue-4874/foo/qux.rs create mode 100644 tests/mod-resolver/issue-4874/main.rs diff --git a/src/modules.rs b/src/modules.rs index c3f44068601..5de0575b5cd 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { self.directory = directory; } match (sub_mod.ast_mod_kind, sub_mod.items) { - (Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => { + (Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => { self.visit_mod_from_ast(&items) } (Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items), diff --git a/src/test/mod.rs b/src/test/mod.rs index ce56a223f2b..cb52346a13a 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -16,6 +16,7 @@ use crate::source_file; use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session}; mod configuration_snippet; +mod mod_resolver; mod parser; const DIFF_CONTEXT_SIZE: usize = 3; diff --git a/src/test/mod_resolver.rs b/src/test/mod_resolver.rs new file mode 100644 index 00000000000..e0b55e3efb2 --- /dev/null +++ b/src/test/mod_resolver.rs @@ -0,0 +1,25 @@ +use std::io; +use std::path::PathBuf; + +use super::read_config; + +use crate::{FileName, Input, Session}; + +#[test] +fn nested_out_of_line_mods_loaded() { + // See also https://github.com/rust-lang/rustfmt/issues/4874 + let filename = "tests/mod-resolver/issue-4874/main.rs"; + let input_file = PathBuf::from(filename); + let config = read_config(&input_file); + let mut session = Session::::new(config, None); + let report = session + .format(Input::File(filename.into())) + .expect("Should not have had any execution errors"); + let errors_by_file = &report.internal.borrow().0; + assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from( + "tests/mod-resolver/issue-4874/bar/baz.rs", + )))); + assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from( + "tests/mod-resolver/issue-4874/foo/qux.rs", + )))); +} diff --git a/tests/mod-resolver/issue-4874/bar/baz.rs b/tests/mod-resolver/issue-4874/bar/baz.rs new file mode 100644 index 00000000000..d31b675ea26 --- /dev/null +++ b/tests/mod-resolver/issue-4874/bar/baz.rs @@ -0,0 +1,5 @@ +fn + fail_fmt_check + ( + + ) {} \ No newline at end of file diff --git a/tests/mod-resolver/issue-4874/foo.rs b/tests/mod-resolver/issue-4874/foo.rs new file mode 100644 index 00000000000..246d847869a --- /dev/null +++ b/tests/mod-resolver/issue-4874/foo.rs @@ -0,0 +1 @@ +mod qux; \ No newline at end of file diff --git a/tests/mod-resolver/issue-4874/foo/qux.rs b/tests/mod-resolver/issue-4874/foo/qux.rs new file mode 100644 index 00000000000..d8bb610a64d --- /dev/null +++ b/tests/mod-resolver/issue-4874/foo/qux.rs @@ -0,0 +1,5 @@ + fn + badly_formatted + ( + + ) {} \ No newline at end of file diff --git a/tests/mod-resolver/issue-4874/main.rs b/tests/mod-resolver/issue-4874/main.rs new file mode 100644 index 00000000000..3609415b146 --- /dev/null +++ b/tests/mod-resolver/issue-4874/main.rs @@ -0,0 +1,8 @@ +fn main() { + println!("Hello, world!"); +} + +mod foo; +mod bar { + mod baz; +} \ No newline at end of file From 71f01d197411fc7a9b3509cbf566720eabdf8d92 Mon Sep 17 00:00:00 2001 From: Alexander Melentyev Date: Mon, 21 Jun 2021 12:11:37 +0300 Subject: [PATCH 6/9] Delete spaces --- CHANGELOG.md | 10 +++++----- Configurations.md | 32 ++++++++++++++++---------------- Contributing.md | 2 +- Design.md | 4 ++-- README.md | 4 ++-- ci/integration.sh | 2 +- docs/index.html | 8 ++++---- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f23663d6c2..68354b6ceaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -176,7 +176,7 @@ https://rust-lang.github.io/rustfmt/?version=v1.4.33&search=#imports_granularity ### Changed -- 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)) +- 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)) In this example the `// else comment` refers to the `else`: ```rust @@ -213,7 +213,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" ### Fixed - 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)) -- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872)) +- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872)) ### Install/Download Options - **crates.io package** - *pending* @@ -297,7 +297,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" - Fix aligning comments of different group - Fix flattening imports with a single `self`. - Fix removing attributes on function parameters. -- Fix removing `impl` keyword from opaque type. +- Fix removing `impl` keyword from opaque type. ## [1.4.8] 2019-09-08 @@ -329,7 +329,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" - Add `--message-format` command line option to `cargo-fmt`. - Add `-l,--files-with-diff` command line option to `rustfmt`. -- Add `json` emit mode. +- Add `json` emit mode. ### Fixed @@ -380,7 +380,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" ### Added -- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt +- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt from formatting an attribute #3665 ### Changed diff --git a/Configurations.md b/Configurations.md index 37cb7474130..9daa7065379 100644 --- a/Configurations.md +++ b/Configurations.md @@ -17,7 +17,7 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or Below you find a detailed visual guide on all the supported configuration options of rustfmt: -## `array_width` +## `array_width` Maximum width of an array literal before falling back to vertical formatting. @@ -25,11 +25,11 @@ Maximum width of an array literal before falling back to vertical formatting. - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) -## `attr_fn_like_width` +## `attr_fn_like_width` Maximum width of the args of a function-like attributes before falling back to vertical formatting. @@ -37,7 +37,7 @@ Maximum width of the args of a function-like attributes before falling back to v - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -295,7 +295,7 @@ where } ``` -## `chain_width` +## `chain_width` Maximum width of a chain to fit on one line. @@ -303,7 +303,7 @@ Maximum width of a chain to fit on one line. - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -751,7 +751,7 @@ trait Lorem { } ``` -## `fn_call_width` +## `fn_call_width` Maximum width of the args of a function call before falling back to vertical formatting. @@ -759,7 +759,7 @@ Maximum width of the args of a function call before falling back to vertical for - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2124,7 +2124,7 @@ Don't reformat out of line modules - **Possible values**: `true`, `false` - **Stable**: No (tracking issue: #3389) -## `single_line_if_else_max_width` +## `single_line_if_else_max_width` 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`. @@ -2132,7 +2132,7 @@ Maximum line length for single line if-else expressions. A value of `0` (zero) r - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2313,7 +2313,7 @@ fn main() { See also: [`indent_style`](#indent_style). -## `struct_lit_width` +## `struct_lit_width` 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`. @@ -2321,11 +2321,11 @@ Maximum width in the body of a struct literal before falling back to vertical fo - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line) -## `struct_variant_width` +## `struct_variant_width` 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`. @@ -2333,7 +2333,7 @@ Maximum width in the body of a struct variant before falling back to vertical fo - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -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. +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. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2530,7 +2530,7 @@ fn main() { 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. -Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`. +Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`. - **Default value**: `"Default"` - **Possible values**: `"Default"`, `"Off"`, `"Max"` @@ -2595,7 +2595,7 @@ fn main() { ``` #### `Off`: -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. +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. ```rust enum Lorem { diff --git a/Contributing.md b/Contributing.md index 131f38dd06a..1b77dad11f0 100644 --- a/Contributing.md +++ b/Contributing.md @@ -38,7 +38,7 @@ colourised diff will be printed so that the offending line(s) can quickly be identified. Without explicit settings, the tests will be run using rustfmt's default -configuration. It is possible to run a test using non-default settings in several +configuration. It is possible to run a test using non-default settings in several ways. Firstly, you can include configuration parameters in comments at the top of the file. For example: to use 3 spaces per tab, start your test with `// rustfmt-tab_spaces: 3`. Just remember that the comment is part of the input, diff --git a/Design.md b/Design.md index 00a7652aee0..7a4dcf8773b 100644 --- a/Design.md +++ b/Design.md @@ -150,8 +150,8 @@ for its configuration. Our visitor keeps track of the desired current indent due to blocks ( `block_indent`). Each `visit_*` method reformats code according to this indent, -`config.comment_width()` and `config.max_width()`. Most reformatting that is done -in the `visit_*` methods is a bit hacky and is meant to be temporary until it can +`config.comment_width()` and `config.max_width()`. Most reformatting that is done +in the `visit_*` methods is a bit hacky and is meant to be temporary until it can be done properly. There are a bunch of methods called `rewrite_*`. They do the bulk of the diff --git a/README.md b/README.md index 7a97d31bab9..500a9f9a37c 100644 --- a/README.md +++ b/README.md @@ -180,13 +180,13 @@ needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`. * For things you do not want rustfmt to mangle, use `#[rustfmt::skip]` * To prevent rustfmt from formatting a macro or an attribute, - use `#[rustfmt::skip::macros(target_macro_name)]` or + use `#[rustfmt::skip::macros(target_macro_name)]` or `#[rustfmt::skip::attributes(target_attribute_name)]` Example: ```rust - #![rustfmt::skip::attributes(custom_attribute)] + #![rustfmt::skip::attributes(custom_attribute)] #[custom_attribute(formatting , here , should , be , Skipped)] #[rustfmt::skip::macros(html)] diff --git a/ci/integration.sh b/ci/integration.sh index 13a3ecaa196..0269e3ee4af 100755 --- a/ci/integration.sh +++ b/ci/integration.sh @@ -15,7 +15,7 @@ set -ex # it again. # #which cargo-fmt || cargo install --force -CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force +CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force echo "Integration tests for: ${INTEGRATION}" cargo fmt -- --version diff --git a/docs/index.html b/docs/index.html index 2a12da3881f..56d1917e2b6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -85,7 +85,7 @@ outputHtml() { const ast = this.configurationDescriptions .filter(({ head, text, stable }) => { - + if ( text.includes(this.searchCondition) === false && head.includes(this.searchCondition) === false @@ -105,7 +105,7 @@ }, created: async function() { const res = await axios.get(ConfigurationMdUrl); - const { + const { about, configurationAbout, configurationDescriptions @@ -144,7 +144,7 @@ const lastIndex = stack.length - 1; stack[lastIndex].push(next); return stack; - }, + }, [[]]); }); } @@ -179,7 +179,7 @@ configurationAbout, ...configurationDescriptions ] = configurations; configurationAbout.value.links = {}; - + return { about, configurationAbout: configurationAbout.value, From 33acc960f78cfde092a4e720c01896fbff86cdc8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Jun 2021 00:13:34 -0400 Subject: [PATCH 7/9] Document rustfmt on nightly-rustc The recursion_limit attribute avoids the following error: ``` error[E0275]: overflow evaluating the requirement `std::ptr::Unique: std::marker::Send` | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`rustfmt_nightly`) ``` --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index cde5d390cf2..ce8a45eea65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![feature(rustc_private)] #![deny(rust_2018_idioms)] #![warn(unreachable_pub)] +#![recursion_limit = "256"] #[macro_use] extern crate derive_new; From abf449ffa657ab10c274595c1d3ec7a69bf801c3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 May 2021 21:31:25 +0200 Subject: [PATCH 8/9] Rework SESSION_GLOBALS API to prevent overwriting it --- src/formatting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatting.rs b/src/formatting.rs index b69ecdc5cb8..e0403574eeb 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -34,7 +34,7 @@ impl<'b, T: Write + 'b> Session<'b, T> { return Err(ErrorKind::VersionMismatch); } - rustc_span::with_session_globals(self.config.edition().into(), || { + rustc_span::create_session_if_not_set_then(self.config.edition().into(), |_| { if self.config.disable_all_formatting() { // When the input is from stdin, echo back the input. if let Input::Text(ref buf) = input { From 277feac1f97324dffea0bfc3816ef8d3f73026f3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 25 Jun 2021 20:43:04 +0200 Subject: [PATCH 9/9] Use LocalExpnId where possible. --- src/utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index d3c349fb701..614cda5f911 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::{ }; use rustc_ast::ptr; use rustc_ast_pretty::pprust; -use rustc_span::{sym, symbol, BytePos, ExpnId, Span, Symbol, SyntaxContext}; +use rustc_span::{sym, symbol, BytePos, LocalExpnId, Span, Symbol, SyntaxContext}; use unicode_width::UnicodeWidthStr; use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; @@ -675,7 +675,7 @@ pub(crate) trait NodeIdExt { impl NodeIdExt for NodeId { fn root() -> NodeId { - NodeId::placeholder_from_expn_id(ExpnId::root()) + NodeId::placeholder_from_expn_id(LocalExpnId::ROOT) } }