diff --git a/Cargo.lock b/Cargo.lock index 8fcefa97489..ee396cce26a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,9 +343,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] diff --git a/Cargo.toml b/Cargo.toml index 00e0ed37a84..032b9b54810 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ diff = "0.1" dirs = "4.0" getopts = "0.2" ignore = "0.4" -itertools = "0.10" +itertools = "0.11" lazy_static = "1.4" regex = "1.7" serde = { version = "1.0.160", features = ["derive"] } diff --git a/Configurations.md b/Configurations.md index c4680a3023f..51a06ffc09f 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1111,7 +1111,7 @@ See also [`format_macro_bodies`](#format_macro_bodies). ## `format_macro_bodies` -Format the bodies of macros. +Format the bodies of declarative macro definitions. - **Default value**: `true` - **Possible values**: `true`, `false` @@ -1261,12 +1261,20 @@ Control the case of the letters in hexadecimal literal values ## `hide_parse_errors` -Do not show parse errors if the parser failed to parse files. +This option is deprecated and has been renamed to `show_parse_errors` to avoid confusion around the double negative default of `hide_parse_errors=false`. - **Default value**: `false` - **Possible values**: `true`, `false` - **Stable**: No (tracking issue: [#3390](https://github.com/rust-lang/rustfmt/issues/3390)) +## `show_parse_errors` + +Show parse errors if the parser failed to parse files. + +- **Default value**: `true` +- **Possible values**: `true`, `false` +- **Stable**: No (tracking issue: [#5977](https://github.com/rust-lang/rustfmt/issues/5977)) + ## `ignore` Skip formatting files and directories that match the specified pattern. diff --git a/rust-toolchain b/rust-toolchain index 0057e2f370a..aa35a7f12d5 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-10-22" +channel = "nightly-2023-12-28" components = ["llvm-tools", "rustc-dev"] diff --git a/src/closures.rs b/src/closures.rs index a09146e9592..5bf29441b54 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure( binder: &ast::ClosureBinder, constness: ast::Const, capture: ast::CaptureBy, - is_async: &ast::Async, + coroutine_kind: &Option, movability: ast::Movability, fn_decl: &ast::FnDecl, body: &ast::Expr, @@ -40,7 +40,16 @@ pub(crate) fn rewrite_closure( debug!("rewrite_closure {:?}", body); let (prefix, extra_offset) = rewrite_closure_fn_decl( - binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape, + binder, + constness, + capture, + coroutine_kind, + movability, + fn_decl, + body, + span, + context, + shape, )?; // 1 = space between `|...|` and body. let body_shape = shape.offset_left(extra_offset)?; @@ -188,7 +197,7 @@ fn rewrite_closure_expr( fn allow_multi_line(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::Match(..) - | ast::ExprKind::Async(..) + | ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::TryBlock(..) | ast::ExprKind::Loop(..) @@ -233,7 +242,7 @@ fn rewrite_closure_fn_decl( binder: &ast::ClosureBinder, constness: ast::Const, capture: ast::CaptureBy, - asyncness: &ast::Async, + coroutine_kind: &Option, movability: ast::Movability, fn_decl: &ast::FnDecl, body: &ast::Expr, @@ -263,8 +272,13 @@ fn rewrite_closure_fn_decl( } else { "" }; - let is_async = if asyncness.is_async() { "async " } else { "" }; - let mover = if capture == ast::CaptureBy::Value { + let coro = match coroutine_kind { + Some(ast::CoroutineKind::Async { .. }) => "async ", + Some(ast::CoroutineKind::Gen { .. }) => "gen ", + Some(ast::CoroutineKind::AsyncGen { .. }) => "async gen ", + None => "", + }; + let mover = if matches!(capture, ast::CaptureBy::Value { .. }) { "move " } else { "" @@ -272,7 +286,7 @@ fn rewrite_closure_fn_decl( // 4 = "|| {".len(), which is overconservative when the closure consists of // a single expression. let nested_shape = shape - .shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())? + .shrink_left(binder.len() + const_.len() + immovable.len() + coro.len() + mover.len())? .sub_width(4)?; // 1 = | @@ -310,7 +324,7 @@ fn rewrite_closure_fn_decl( .tactic(tactic) .preserve_newline(true); let list_str = write_list(&item_vec, &fmt)?; - let mut prefix = format!("{binder}{const_}{immovable}{is_async}{mover}|{list_str}|"); + let mut prefix = format!("{binder}{const_}{immovable}{coro}{mover}|{list_str}|"); if !ret_str.is_empty() { if prefix.contains('\n') { @@ -339,7 +353,7 @@ pub(crate) fn rewrite_last_closure( ref binder, constness, capture_clause, - ref asyncness, + ref coroutine_kind, movability, ref fn_decl, ref body, @@ -360,7 +374,7 @@ pub(crate) fn rewrite_last_closure( binder, constness, capture_clause, - asyncness, + coroutine_kind, movability, fn_decl, body, @@ -434,7 +448,7 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool { match expr.kind { - ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true, + ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop { .. } => true, ast::ExprKind::Loop(..) if version == Version::Two => true, ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Try(ref expr) @@ -459,7 +473,7 @@ fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { | ast::ExprKind::Block(..) | ast::ExprKind::While(..) | ast::ExprKind::Loop(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::TryBlock(..) => false, _ => true, } diff --git a/src/comment.rs b/src/comment.rs index 7da0f79bd09..44b3eb80aef 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -1,6 +1,6 @@ // Formatting and tools for comments. -use std::{self, borrow::Cow, iter}; +use std::{borrow::Cow, iter}; use itertools::{multipeek, MultiPeek}; use lazy_static::lazy_static; @@ -173,10 +173,7 @@ pub(crate) fn combine_strs_with_missing_comments( ) -> Option { trace!( "combine_strs_with_missing_comments `{}` `{}` {:?} {:?}", - prev_str, - next_str, - span, - shape + prev_str, next_str, span, shape ); let mut result = @@ -1847,7 +1844,6 @@ fn remove_comment_header(comment: &str) -> &str { #[cfg(test)] mod test { use super::*; - use crate::shape::{Indent, Shape}; #[test] fn char_classes() { diff --git a/src/config/config_type.rs b/src/config/config_type.rs index feb452d7235..7551241fc00 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -129,6 +129,7 @@ macro_rules! create_config { | "chain_width" => self.0.set_heuristics(), "merge_imports" => self.0.set_merge_imports(), "fn_args_layout" => self.0.set_fn_args_layout(), + "hide_parse_errors" => self.0.set_hide_parse_errors(), &_ => (), } } @@ -184,6 +185,7 @@ macro_rules! create_config { self.set_ignore(dir); self.set_merge_imports(); self.set_fn_args_layout(); + self.set_hide_parse_errors(); self } @@ -278,19 +280,21 @@ macro_rules! create_config { | "chain_width" => self.set_heuristics(), "merge_imports" => self.set_merge_imports(), "fn_args_layout" => self.set_fn_args_layout(), + "hide_parse_errors" => self.set_hide_parse_errors(), &_ => (), } } #[allow(unreachable_pub)] pub fn is_hidden_option(name: &str) -> bool { - const HIDE_OPTIONS: [&str; 6] = [ + const HIDE_OPTIONS: [&str; 7] = [ "verbose", "verbose_diff", "file_lines", "width_heuristics", "merge_imports", - "fn_args_layout" + "fn_args_layout", + "hide_parse_errors" ]; HIDE_OPTIONS.contains(&name) } @@ -461,6 +465,18 @@ macro_rules! create_config { } } + fn set_hide_parse_errors(&mut self) { + if self.was_set().hide_parse_errors() { + eprintln!( + "Warning: the `hide_parse_errors` option is deprecated. \ + Use `show_parse_errors` instead" + ); + if !self.was_set().show_parse_errors() { + self.show_parse_errors.2 = self.hide_parse_errors(); + } + } + } + #[allow(unreachable_pub)] /// Returns `true` if the config key was explicitly set and is the default value. pub fn is_default(&self, key: &str) -> bool { diff --git a/src/config/file_lines.rs b/src/config/file_lines.rs index e33fe9bb283..224864393d3 100644 --- a/src/config/file_lines.rs +++ b/src/config/file_lines.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use std::{cmp, fmt, iter, str}; use rustc_data_structures::sync::Lrc; -use rustc_span::{self, SourceFile}; +use rustc_span::SourceFile; use serde::{ser, Deserialize, Deserializer, Serialize, Serializer}; use serde_json as json; use thiserror::Error; diff --git a/src/config/mod.rs b/src/config/mod.rs index 23f09e4d028..1139289880c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,5 +1,4 @@ use std::cell::Cell; -use std::default::Default; use std::fs::File; use std::io::{Error, ErrorKind, Read}; use std::path::{Path, PathBuf}; @@ -27,6 +26,7 @@ pub(crate) mod file_lines; #[allow(unreachable_pub)] pub(crate) mod lists; pub(crate) mod macro_names; +pub(crate) mod style_edition; // This macro defines configuration options used in rustfmt. Each option // is defined as follows: @@ -74,7 +74,7 @@ create_config! { format_strings: bool, false, false, "Format string literals where necessary"; format_macro_matchers: bool, false, false, "Format the metavariable matching patterns in macros"; - format_macro_bodies: bool, true, false, "Format the bodies of macros"; + format_macro_bodies: bool, true, false, "Format the bodies of declarative macro definitions"; skip_macro_invocations: MacroSelectors, MacroSelectors::default(), false, "Skip formatting the bodies of macros invoked with the following names."; hex_literal_case: HexLiteralCase, HexLiteralCase::Preserve, false, @@ -172,7 +172,8 @@ create_config! { "Enables unstable features. Only available on nightly channel"; disable_all_formatting: bool, false, true, "Don't reformat anything"; skip_children: bool, false, false, "Don't reformat out of line modules"; - hide_parse_errors: bool, false, false, "Hide errors from the parser"; + hide_parse_errors: bool, false, false, "(deprecated: use show_parse_errors instead)"; + show_parse_errors: bool, true, false, "Show errors from the parser (unstable)"; error_on_line_overflow: bool, false, false, "Error if unable to get all lines within max_width"; error_on_unformatted: bool, false, false, "Error if unable to get comments or string literals within max_width, \ @@ -207,6 +208,7 @@ impl PartialConfig { cloned.print_misformatted_file_names = None; cloned.merge_imports = None; cloned.fn_args_layout = None; + cloned.hide_parse_errors = None; ::toml::to_string(&cloned).map_err(ToTomlError) } @@ -459,6 +461,13 @@ mod test { fn_params_layout: Density, Density::Tall, true, "Control the layout of parameters in a function signatures."; + // hide_parse_errors renamed to show_parse_errors + hide_parse_errors: bool, false, false, + "(deprecated: use show_parse_errors instead)"; + show_parse_errors: bool, true, false, + "Show errors from the parser (unstable)"; + + // Width Heuristics use_small_heuristics: Heuristics, Heuristics::Default, true, "Whether to use different formatting for items and \ @@ -685,7 +694,7 @@ required_version = "{}" unstable_features = false disable_all_formatting = false skip_children = false -hide_parse_errors = false +show_parse_errors = true error_on_line_overflow = false error_on_unformatted = false ignore = [] @@ -1021,7 +1030,6 @@ make_backup = false #[cfg(test)] mod partially_unstable_option { use super::mock::{Config, PartiallyUnstableOption}; - use super::*; /// From the command line, we can override with a stable variant. #[test] diff --git a/src/config/options.rs b/src/config/options.rs index e37f4027e4a..e7fd2cfbd31 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -1,3 +1,5 @@ +#![allow(unused_imports)] + use std::collections::{hash_set, HashSet}; use std::fmt; use std::path::{Path, PathBuf}; @@ -468,3 +470,27 @@ pub enum MatchArmLeadingPipe { /// Preserve any existing leading pipes Preserve, } + +/// Defines the default values for each config according to [the style guide]. +/// rustfmt output may differ between style editions. +/// +/// [the style guide]: https://doc.rust-lang.org/nightly/style-guide/ +#[config_type] +pub enum StyleEdition { + #[value = "2015"] + #[doc_hint = "2015"] + /// [Edition 2015]() + Edition2015, + #[value = "2018"] + #[doc_hint = "2018"] + /// [Edition 2018]() + Edition2018, + #[value = "2021"] + #[doc_hint = "2021"] + /// [Edition 2021]() + Edition2021, + #[value = "2024"] + #[doc_hint = "2024"] + /// [Edition 2024](). + Edition2024, +} diff --git a/src/config/style_edition.rs b/src/config/style_edition.rs new file mode 100644 index 00000000000..4dd5f0164fa --- /dev/null +++ b/src/config/style_edition.rs @@ -0,0 +1,69 @@ +use crate::config::StyleEdition; + +/// Defines the default value for the given style edition +pub(crate) trait StyleEditionDefault { + type ConfigType; + fn style_edition_default(style_edition: StyleEdition) -> Self::ConfigType; +} + +/// macro to help implement `StyleEditionDefault` for config options +#[macro_export] +macro_rules! style_edition_default { + ($ty:ident, $config_ty:ty, _ => $default:expr) => { + impl $crate::config::style_edition::StyleEditionDefault for $ty { + type ConfigType = $config_ty; + + fn style_edition_default(_: $crate::config::StyleEdition) -> Self::ConfigType { + $default + } + } + }; + ($ty:ident, $config_ty:ty, Edition2024 => $default_2024:expr, _ => $default_2015:expr) => { + impl $crate::config::style_edition::StyleEditionDefault for $ty { + type ConfigType = $config_ty; + + fn style_edition_default( + style_edition: $crate::config::StyleEdition, + ) -> Self::ConfigType { + match style_edition { + $crate::config::StyleEdition::Edition2015 + | $crate::config::StyleEdition::Edition2018 + | $crate::config::StyleEdition::Edition2021 => $default_2015, + $crate::config::StyleEdition::Edition2024 => $default_2024, + } + } + } + }; +} + +#[cfg(test)] +mod test { + use super::*; + use crate::config::StyleEdition; + + #[test] + fn test_impl_default_style_edition_struct_for_all_editions() { + struct Unit; + style_edition_default!(Unit, usize, _ => 100); + + // regardless of the style edition used the value will always return 100 + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100); + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2018), 100); + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2021), 100); + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2024), 100); + } + + #[test] + fn test_impl_default_style_edition_for_old_and_new_editions() { + struct Unit; + style_edition_default!(Unit, usize, Edition2024 => 50, _ => 100); + + // style edition 2015-2021 are all the same + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100); + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2018), 100); + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2021), 100); + + // style edition 2024 + assert_eq!(Unit::style_edition_default(StyleEdition::Edition2024), 50); + } +} diff --git a/src/emitter/checkstyle.rs b/src/emitter/checkstyle.rs index 56d6a0ed681..2a4a9dfce8e 100644 --- a/src/emitter/checkstyle.rs +++ b/src/emitter/checkstyle.rs @@ -1,7 +1,6 @@ use self::xml::XmlEscaped; use super::*; use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch}; -use std::io::{self, Write}; mod xml; diff --git a/src/emitter/diff.rs b/src/emitter/diff.rs index 764cd136e01..0af19a7d0b2 100644 --- a/src/emitter/diff.rs +++ b/src/emitter/diff.rs @@ -51,8 +51,6 @@ impl Emitter for DiffEmitter { #[cfg(test)] mod tests { use super::*; - use crate::config::Config; - use crate::FileName; use std::path::PathBuf; #[test] diff --git a/src/emitter/json.rs b/src/emitter/json.rs index 5594196bed9..f47c3260a02 100644 --- a/src/emitter/json.rs +++ b/src/emitter/json.rs @@ -2,7 +2,6 @@ use super::*; use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch}; use serde::Serialize; use serde_json::to_string as to_json_string; -use std::io::{self, Write}; #[derive(Debug, Default)] pub(crate) struct JsonEmitter { @@ -106,7 +105,6 @@ impl JsonEmitter { #[cfg(test)] mod tests { use super::*; - use crate::FileName; use std::path::PathBuf; #[test] diff --git a/src/emitter/modified_lines.rs b/src/emitter/modified_lines.rs index 94ff570a8a9..81f0a31b974 100644 --- a/src/emitter/modified_lines.rs +++ b/src/emitter/modified_lines.rs @@ -1,6 +1,5 @@ use super::*; use crate::rustfmt_diff::{make_diff, ModifiedLines}; -use std::io::Write; #[derive(Debug, Default)] pub(crate) struct ModifiedLinesEmitter; diff --git a/src/emitter/stdout.rs b/src/emitter/stdout.rs index 0bbc7332dfe..0b635a28bf2 100644 --- a/src/emitter/stdout.rs +++ b/src/emitter/stdout.rs @@ -1,6 +1,5 @@ use super::*; use crate::config::Verbosity; -use std::io::Write; #[derive(Debug)] pub(crate) struct StdoutEmitter { diff --git a/src/expr.rs b/src/expr.rs index 7e537ad4fbd..3445733f1d3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -3,7 +3,7 @@ use std::cmp::min; use itertools::Itertools; use rustc_ast::token::{Delimiter, Lit, LitKind}; -use rustc_ast::{ast, ptr, token}; +use rustc_ast::{ast, ptr, token, ForLoopKind}; use rustc_span::{BytePos, Span}; use crate::chains::rewrite_chain; @@ -134,7 +134,7 @@ pub(crate) fn format_expr( } ast::ExprKind::Let(ref pat, ref expr, _span, _) => rewrite_let(context, shape, pat, expr), ast::ExprKind::If(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::Loop(..) | ast::ExprKind::While(..) => to_control_flow(expr, expr_type) .and_then(|control_flow| control_flow.rewrite(context, shape)), @@ -212,7 +212,7 @@ pub(crate) fn format_expr( &cl.binder, cl.constness, cl.capture_clause, - &cl.asyncness, + &cl.coroutine_kind, cl.movability, &cl.fn_decl, &cl.body, @@ -367,15 +367,15 @@ pub(crate) fn format_expr( )) } } - ast::ExprKind::Async(capture_by, ref block) => { - let mover = if capture_by == ast::CaptureBy::Value { + ast::ExprKind::Gen(capture_by, ref block, ref kind) => { + let mover = if matches!(capture_by, ast::CaptureBy::Value { .. }) { "move " } else { "" }; if let rw @ Some(_) = rewrite_single_line_block( context, - format!("async {mover}").as_str(), + format!("{kind} {mover}").as_str(), block, Some(&expr.attrs), None, @@ -386,7 +386,7 @@ pub(crate) fn format_expr( // 6 = `async ` let budget = shape.width.saturating_sub(6); Some(format!( - "async {mover}{}", + "{kind} {mover}{}", rewrite_block( block, Some(&expr.attrs), @@ -682,9 +682,15 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option { - Some(ControlFlow::new_for(pat, cond, block, label, expr.span)) - } + ast::ExprKind::ForLoop { + ref pat, + ref iter, + ref body, + label, + kind, + } => Some(ControlFlow::new_for( + pat, iter, body, label, expr.span, kind, + )), ast::ExprKind::Loop(ref block, label, _) => { Some(ControlFlow::new_loop(block, label, expr.span)) } @@ -771,6 +777,7 @@ impl<'a> ControlFlow<'a> { block: &'a ast::Block, label: Option, span: Span, + kind: ForLoopKind, ) -> ControlFlow<'a> { ControlFlow { cond: Some(cond), @@ -778,7 +785,10 @@ impl<'a> ControlFlow<'a> { else_block: None, label, pat: Some(pat), - keyword: "for", + keyword: match kind { + ForLoopKind::For => "for", + ForLoopKind::ForAwait => "for await", + }, matcher: "", connector: " in", allow_single_line: false, @@ -1421,14 +1431,14 @@ pub(crate) fn can_be_overflowed_expr( || context.config.overflow_delimited_expr() } ast::ExprKind::If(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::Loop(..) | ast::ExprKind::While(..) => { context.config.combine_control_expr() && context.use_block_indent() && args_len == 1 } // Handle always block-like expressions - ast::ExprKind::Async(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true, + ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true, // Handle `[]` and `{}`-like expressions ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => { @@ -1990,7 +2000,7 @@ fn rewrite_unary_op( shape: Shape, ) -> Option { // For some reason, an UnOp is not spanned like BinOp! - rewrite_unary_prefix(context, ast::UnOp::to_string(op), expr, shape) + rewrite_unary_prefix(context, op.as_str(), expr, shape) } pub(crate) enum RhsAssignKind<'ast> { diff --git a/src/ignore_path.rs b/src/ignore_path.rs index d955949496a..7b5697bec3e 100644 --- a/src/ignore_path.rs +++ b/src/ignore_path.rs @@ -1,4 +1,4 @@ -use ignore::{self, gitignore}; +use ignore::gitignore; use crate::config::{FileName, IgnoreList}; diff --git a/src/imports.rs b/src/imports.rs index f8e7fa62890..09f6e752338 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -1102,7 +1102,6 @@ enum SharedPrefix { #[cfg(test)] mod test { use super::*; - use rustc_span::DUMMY_SP; // Parse the path part of an import. This parser is not robust and is only // suitable for use in a test harness. diff --git a/src/items.rs b/src/items.rs index 386fdcf9698..a6295384b99 100644 --- a/src/items.rs +++ b/src/items.rs @@ -287,7 +287,7 @@ pub(crate) struct FnSig<'a> { decl: &'a ast::FnDecl, generics: &'a ast::Generics, ext: ast::Extern, - is_async: Cow<'a, ast::Async>, + coroutine_kind: Cow<'a, Option>, constness: ast::Const, defaultness: ast::Defaultness, unsafety: ast::Unsafe, @@ -302,7 +302,7 @@ impl<'a> FnSig<'a> { ) -> FnSig<'a> { FnSig { unsafety: method_sig.header.unsafety, - is_async: Cow::Borrowed(&method_sig.header.asyncness), + coroutine_kind: Cow::Borrowed(&method_sig.header.coroutine_kind), constness: method_sig.header.constness, defaultness: ast::Defaultness::Final, ext: method_sig.header.ext, @@ -328,7 +328,7 @@ impl<'a> FnSig<'a> { generics, ext: fn_sig.header.ext, constness: fn_sig.header.constness, - is_async: Cow::Borrowed(&fn_sig.header.asyncness), + coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind), defaultness, unsafety: fn_sig.header.unsafety, visibility: vis, @@ -343,7 +343,8 @@ impl<'a> FnSig<'a> { result.push_str(&*format_visibility(context, self.visibility)); result.push_str(format_defaultness(self.defaultness)); result.push_str(format_constness(self.constness)); - result.push_str(format_async(&self.is_async)); + self.coroutine_kind + .map(|coroutine_kind| result.push_str(format_coro(&coroutine_kind))); result.push_str(format_unsafety(self.unsafety)); result.push_str(&format_extern( self.ext, @@ -665,7 +666,7 @@ impl<'a> FmtVisitor<'a> { let span = mk_sp(lo, field.span.lo()); let variant_body = match field.data { - ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => format_struct( + ast::VariantData::Tuple(..) | ast::VariantData::Struct { .. } => format_struct( &context, &StructParts::from_variant(field, &context), self.block_indent, @@ -1093,7 +1094,7 @@ fn enum_variant_span(variant: &ast::Variant, context: &RewriteContext<'_>) -> Sp if let Some(ref anon_const) = variant.disr_expr { let span_before_consts = variant.span.until(anon_const.value.span); let hi = match &variant.data { - Struct(..) => context + Struct { .. } => context .snippet_provider .span_after_last(span_before_consts, "}"), Tuple(..) => context @@ -1113,12 +1114,12 @@ fn format_struct( offset: Indent, one_line_width: Option, ) -> Option { - match *struct_parts.def { + match struct_parts.def { ast::VariantData::Unit(..) => format_unit_struct(context, struct_parts, offset), - ast::VariantData::Tuple(ref fields, _) => { + ast::VariantData::Tuple(fields, _) => { format_tuple_struct(context, struct_parts, fields, offset) } - ast::VariantData::Struct(ref fields, _) => { + ast::VariantData::Struct { fields, .. } => { format_struct_struct(context, struct_parts, fields, offset, one_line_width) } } diff --git a/src/lib.rs b/src/lib.rs index 8800e200fa4..400d3fe6dce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,7 +304,7 @@ fn format_snippet(snippet: &str, config: &Config, is_macro_def: bool) -> Option< let mut out: Vec = Vec::with_capacity(snippet.len() * 2); config.set().emit_mode(config::EmitMode::Stdout); config.set().verbose(Verbosity::Quiet); - config.set().hide_parse_errors(true); + config.set().show_parse_errors(false); if is_macro_def { config.set().error_on_unformatted(true); } diff --git a/src/macros.rs b/src/macros.rs index 76553466e48..86694089fd6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -708,7 +708,7 @@ struct MacroArgParser { fn last_tok(tt: &TokenTree) -> Token { match *tt { TokenTree::Token(ref t, _) => t.clone(), - TokenTree::Delimited(delim_span, delim, _) => Token { + TokenTree::Delimited(delim_span, _, delim, _) => Token { kind: TokenKind::CloseDelim(delim), span: delim_span.close, }, @@ -925,7 +925,7 @@ impl MacroArgParser { self.add_meta_variable(&mut iter)?; } TokenTree::Token(ref t, _) => self.update_buffer(t), - &TokenTree::Delimited(_delimited_span, delimited, ref tts) => { + &TokenTree::Delimited(_dspan, _spacing, delimited, ref tts) => { if !self.buf.is_empty() { if next_space(&self.last_tok.kind) == SpaceState::Always { self.add_separator(); @@ -1167,7 +1167,7 @@ impl<'a> MacroParser<'a> { let tok = self.toks.next()?; let (lo, args_paren_kind) = match tok { TokenTree::Token(..) => return None, - &TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d), + &TokenTree::Delimited(delimited_span, _, d, _) => (delimited_span.open.lo(), d), }; let args = TokenStream::new(vec![tok.clone()]); match self.toks.next()? { @@ -1269,7 +1269,7 @@ impl MacroBranch { let has_block_body = old_body.starts_with('{'); let mut config = context.config.clone(); - config.set().hide_parse_errors(true); + config.set().show_parse_errors(false); result += " {"; diff --git a/src/matches.rs b/src/matches.rs index 45f8bd90206..72386f0a097 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -223,7 +223,7 @@ fn rewrite_match_arm( ) -> Option { let (missing_span, attrs_str) = if !arm.attrs.is_empty() { if contains_skip(&arm.attrs) { - let (_, body) = flatten_arm_body(context, &arm.body, None); + let (_, body) = flatten_arm_body(context, arm.body.as_deref()?, None); // `arm.span()` does not include trailing comma, add it manually. return Some(format!( "{}{}", @@ -246,7 +246,7 @@ fn rewrite_match_arm( }; // Patterns - let pat_shape = match &arm.body.kind { + let pat_shape = match &arm.body.as_ref()?.kind { ast::ExprKind::Block(_, Some(label)) => { // Some block with a label ` => 'label: {` // 7 = ` => : {` @@ -280,10 +280,10 @@ fn rewrite_match_arm( false, )?; - let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.span().lo()); + let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.as_ref()?.span().lo()); rewrite_match_body( context, - &arm.body, + arm.body.as_ref()?, &lhs_str, shape, guard_str.contains('\n'), @@ -591,7 +591,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool { ast::ExprKind::If(..) => false, // We do not allow collapsing a block around expression with condition // to avoid it being cluttered with match arm. - ast::ExprKind::ForLoop(..) | ast::ExprKind::While(..) => false, + ast::ExprKind::ForLoop { .. } | ast::ExprKind::While(..) => false, ast::ExprKind::Loop(..) | ast::ExprKind::Match(..) | ast::ExprKind::Block(..) diff --git a/src/overflow.rs b/src/overflow.rs index d81bf24dbd1..2f9705ec943 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -8,8 +8,8 @@ use rustc_ast::{ast, ptr}; use rustc_span::Span; use crate::closures; -use crate::config::lists::*; use crate::config::Version; +use crate::config::{lists::*, Config}; use crate::expr::{ can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr, rewrite_cond, @@ -60,6 +60,13 @@ const SPECIAL_CASE_MACROS: &[(&str, usize)] = &[ ("debug_assert_ne!", 2), ]; +/// Additional special case macros for version 2; these are separated to avoid breaking changes in +/// version 1. +const SPECIAL_CASE_MACROS_V2: &[(&str, usize)] = &[ + // From the `log` crate. + ("trace!", 0), +]; + const SPECIAL_CASE_ATTR: &[(&str, usize)] = &[ // From the `failure` crate. ("fail", 0), @@ -182,12 +189,17 @@ impl<'a> OverflowableItem<'a> { } } - fn special_cases(&self) -> &'static [(&'static str, usize)] { - match self { + fn special_cases(&self, config: &Config) -> impl Iterator { + let base_cases = match self { OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS, OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR, _ => &[], - } + }; + let additional_cases = match (self, config.version()) { + (OverflowableItem::MacroArg(..), Version::Two) => SPECIAL_CASE_MACROS_V2, + _ => &[], + }; + base_cases.iter().chain(additional_cases) } } @@ -409,7 +421,7 @@ impl<'a> Context<'a> { // When overflowing the expressions which consists of a control flow // expression, avoid condition to use multi line. ast::ExprKind::If(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::Loop(..) | ast::ExprKind::While(..) | ast::ExprKind::Match(..) => { @@ -551,7 +563,7 @@ impl<'a> Context<'a> { if tactic == DefinitiveListTactic::Vertical { if let Some((all_simple, num_args_before)) = - maybe_get_args_offset(self.ident, &self.items) + maybe_get_args_offset(self.ident, &self.items, &self.context.config) { let one_line = all_simple && definitive_tactic( @@ -771,11 +783,11 @@ fn no_long_items(list: &[ListItem], short_array_element_width_threshold: usize) pub(crate) fn maybe_get_args_offset( callee_str: &str, args: &[OverflowableItem<'_>], + config: &Config, ) -> Option<(bool, usize)> { if let Some(&(_, num_args_before)) = args .get(0)? - .special_cases() - .iter() + .special_cases(config) .find(|&&(s, _)| s == callee_str) { let all_simple = args.len() > num_args_before diff --git a/src/pairs.rs b/src/pairs.rs index 07c05193739..bfc2ffed383 100644 --- a/src/pairs.rs +++ b/src/pairs.rs @@ -339,7 +339,7 @@ impl FlattenPair for ast::Expr { if let Some(pop) = stack.pop() { match pop.kind { ast::ExprKind::Binary(op, _, ref rhs) => { - separators.push(op.node.to_string()); + separators.push(op.node.as_str()); node = rhs; } _ => unreachable!(), diff --git a/src/parse/macros/cfg_if.rs b/src/parse/macros/cfg_if.rs index cbc4c90b8f9..bafef7b0f46 100644 --- a/src/parse/macros/cfg_if.rs +++ b/src/parse/macros/cfg_if.rs @@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>( Ok(None) => continue, Err(err) => { err.cancel(); - parser.sess.span_diagnostic.reset_err_count(); + parser.sess.dcx.reset_err_count(); return Err( "Expected item inside cfg_if block, but failed to parse it as an item", ); diff --git a/src/parse/macros/lazy_static.rs b/src/parse/macros/lazy_static.rs index a8c2feec453..8b1dc6694d6 100644 --- a/src/parse/macros/lazy_static.rs +++ b/src/parse/macros/lazy_static.rs @@ -16,8 +16,8 @@ pub(crate) fn parse_lazy_static( ($method:ident $(,)* $($arg:expr),* $(,)*) => { match parser.$method($($arg,)*) { Ok(val) => { - if parser.sess.span_diagnostic.has_errors().is_some() { - parser.sess.span_diagnostic.reset_err_count(); + if parser.sess.dcx.has_errors().is_some() { + parser.sess.dcx.reset_err_count(); return None; } else { val @@ -25,7 +25,7 @@ pub(crate) fn parse_lazy_static( } Err(err) => { err.cancel(); - parser.sess.span_diagnostic.reset_err_count(); + parser.sess.dcx.reset_err_count(); return None; } } diff --git a/src/parse/macros/mod.rs b/src/parse/macros/mod.rs index 7a802f7a88e..2dd2622174f 100644 --- a/src/parse/macros/mod.rs +++ b/src/parse/macros/mod.rs @@ -28,8 +28,8 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { let mut cloned_parser = (*parser).clone(); match $parser(&mut cloned_parser) { Ok(x) => { - if parser.sess.span_diagnostic.has_errors().is_some() { - parser.sess.span_diagnostic.reset_err_count(); + if parser.sess.dcx.has_errors().is_some() { + parser.sess.dcx.reset_err_count(); } else { // Parsing succeeded. *parser = cloned_parser; @@ -38,7 +38,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { } Err(e) => { e.cancel(); - parser.sess.span_diagnostic.reset_err_count(); + parser.sess.dcx.reset_err_count(); } } }; diff --git a/src/parse/session.rs b/src/parse/session.rs index 0573df9de2f..646d2d132a8 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter}; use rustc_errors::translation::Translate; -use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel}; +use rustc_errors::{ColorConfig, DiagCtxt, Diagnostic, Level as DiagnosticLevel}; use rustc_session::parse::ParseSess as RawParseSess; use rustc_span::{ source_map::{FilePathMapping, SourceMap}, @@ -118,13 +118,13 @@ impl From for ColorConfig { } } -fn default_handler( +fn default_dcx( source_map: Lrc, ignore_path_set: Lrc, can_reset: Lrc, - hide_parse_errors: bool, + show_parse_errors: bool, color: Color, -) -> Handler { +) -> DiagCtxt { let supports_color = term::stderr().map_or(false, |term| term.supports_color()); let emit_color = if supports_color { ColorConfig::from(color) @@ -132,7 +132,7 @@ fn default_handler( ColorConfig::Never }; - let emitter = if hide_parse_errors { + let emitter = if !show_parse_errors { silent_emitter() } else { let fallback_bundle = rustc_errors::fallback_fluent_bundle( @@ -141,7 +141,7 @@ fn default_handler( ); Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone()))) }; - Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter { + DiagCtxt::with_emitter(Box::new(SilentOnIgnoredFilesEmitter { has_non_ignorable_parser_errors: false, source_map, emitter, @@ -159,14 +159,14 @@ impl ParseSess { let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); let can_reset_errors = Lrc::new(AtomicBool::new(false)); - let handler = default_handler( + let dcx = default_dcx( Lrc::clone(&source_map), Lrc::clone(&ignore_path_set), Lrc::clone(&can_reset_errors), - config.hide_parse_errors(), + config.show_parse_errors(), config.color(), ); - let parse_sess = RawParseSess::with_span_handler(handler, source_map); + let parse_sess = RawParseSess::with_dcx(dcx, source_map); Ok(ParseSess { parse_sess, @@ -218,7 +218,7 @@ impl ParseSess { } pub(crate) fn set_silent_emitter(&mut self) { - self.parse_sess.span_diagnostic = Handler::with_emitter(silent_emitter()); + self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter()); } pub(crate) fn span_to_filename(&self, span: Span) -> FileName { @@ -284,10 +284,8 @@ impl ParseSess { // Methods that should be restricted within the parse module. impl ParseSess { pub(super) fn emit_diagnostics(&self, diagnostics: Vec) { - for mut diagnostic in diagnostics { - self.parse_sess - .span_diagnostic - .emit_diagnostic(&mut diagnostic); + for diagnostic in diagnostics { + self.parse_sess.dcx.emit_diagnostic(diagnostic); } } @@ -296,11 +294,11 @@ impl ParseSess { } pub(super) fn has_errors(&self) -> bool { - self.parse_sess.span_diagnostic.has_errors().is_some() + self.parse_sess.dcx.has_errors().is_some() } pub(super) fn reset_errors(&self) { - self.parse_sess.span_diagnostic.reset_err_count(); + self.parse_sess.dcx.reset_err_count(); } } @@ -372,7 +370,7 @@ mod tests { fn build_diagnostic(level: DiagnosticLevel, span: Option) -> Diagnostic { let mut diag = Diagnostic::new(level, ""); - diag.message.clear(); + diag.messages.clear(); if let Some(span) = span { diag.span = span; } diff --git a/src/patterns.rs b/src/patterns.rs index 33f3b4b8a21..0fa6edaa5d7 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -40,7 +40,9 @@ pub(crate) fn is_short_pattern(pat: &ast::Pat, pat_str: &str) -> bool { fn is_short_pattern_inner(pat: &ast::Pat) -> bool { match pat.kind { - ast::PatKind::Rest | ast::PatKind::Wild | ast::PatKind::Lit(_) => true, + ast::PatKind::Rest | ast::PatKind::Never | ast::PatKind::Wild | ast::PatKind::Lit(_) => { + true + } ast::PatKind::Ident(_, _, ref pat) => pat.is_none(), ast::PatKind::Struct(..) | ast::PatKind::MacCall(..) @@ -193,6 +195,7 @@ impl Rewrite for Pat { None } } + PatKind::Never => None, PatKind::Range(ref lhs, ref rhs, ref end_kind) => { let infix = match end_kind.node { RangeEnd::Included(RangeSyntax::DotDotDot) => "...", @@ -256,9 +259,15 @@ impl Rewrite for Pat { None, None, ), - PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => { - rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape) - } + PatKind::Struct(ref qself, ref path, ref fields, rest) => rewrite_struct_pat( + qself, + path, + fields, + rest == ast::PatFieldsRest::Rest, + self.span, + context, + shape, + ), PatKind::MacCall(ref mac) => { rewrite_macro(mac, None, context, shape, MacroPosition::Pat) } diff --git a/src/reorder.rs b/src/reorder.rs index 3bddf4c1b6a..3e14f9f1272 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -6,7 +6,7 @@ // FIXME(#2455): Reorder trait items. -use std::cmp::{Ord, Ordering}; +use std::cmp::Ordering; use rustc_ast::{ast, attr}; use rustc_span::{symbol::sym, Span}; diff --git a/src/spanned.rs b/src/spanned.rs index 2136cfeae1a..5960b144499 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -97,7 +97,12 @@ impl Spanned for ast::Arm { } else { self.attrs[0].span.lo() }; - span_with_attrs_lo_hi!(self, lo, self.body.span.hi()) + let hi = if let Some(body) = &self.body { + body.span.hi() + } else { + self.pat.span.hi() + }; + span_with_attrs_lo_hi!(self, lo, hi) } } diff --git a/src/types.rs b/src/types.rs index 127aff913e3..cd2582e66be 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,3 @@ -use std::iter::ExactSizeIterator; use std::ops::Deref; use rustc_ast::ast::{self, FnRetTy, Mutability, Term}; @@ -538,28 +537,19 @@ impl Rewrite for ast::Lifetime { impl Rewrite for ast::GenericBound { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { - ast::GenericBound::Trait(ref poly_trait_ref, trait_bound_modifier) => { + ast::GenericBound::Trait(ref poly_trait_ref, modifiers) => { let snippet = context.snippet(self.span()); let has_paren = snippet.starts_with('(') && snippet.ends_with(')'); - let rewrite = match trait_bound_modifier { - ast::TraitBoundModifier::None => poly_trait_ref.rewrite(context, shape), - ast::TraitBoundModifier::Maybe => poly_trait_ref - .rewrite(context, shape.offset_left(1)?) - .map(|s| format!("?{}", s)), - ast::TraitBoundModifier::MaybeConst => poly_trait_ref - .rewrite(context, shape.offset_left(7)?) - .map(|s| format!("~const {}", s)), - ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref - .rewrite(context, shape.offset_left(8)?) - .map(|s| format!("~const ?{}", s)), - ast::TraitBoundModifier::Negative => poly_trait_ref - .rewrite(context, shape.offset_left(1)?) - .map(|s| format!("!{}", s)), - ast::TraitBoundModifier::MaybeConstNegative => poly_trait_ref - .rewrite(context, shape.offset_left(8)?) - .map(|s| format!("~const !{}", s)), - }; - rewrite.map(|s| if has_paren { format!("({})", s) } else { s }) + let mut constness = modifiers.constness.as_str().to_string(); + if !constness.is_empty() { + constness.push(' '); + } + let polarity = modifiers.polarity.as_str(); + let shape = shape.offset_left(constness.len() + polarity.len())?; + poly_trait_ref + .rewrite(context, shape) + .map(|s| format!("{constness}{polarity}{s}")) + .map(|s| if has_paren { format!("({})", s) } else { s }) } ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape), } diff --git a/src/utils.rs b/src/utils.rs index 79a759d68ce..642b6603b1e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -75,10 +75,11 @@ pub(crate) fn format_visibility( } #[inline] -pub(crate) fn format_async(is_async: &ast::Async) -> &'static str { - match is_async { - ast::Async::Yes { .. } => "async ", - ast::Async::No => "", +pub(crate) fn format_coro(coroutine_kind: &ast::CoroutineKind) -> &'static str { + match coroutine_kind { + ast::CoroutineKind::Async { .. } => "async ", + ast::CoroutineKind::Gen { .. } => "gen ", + ast::CoroutineKind::AsyncGen { .. } => "async gen ", } } @@ -294,7 +295,7 @@ pub(crate) fn semicolon_for_stmt( ) -> bool { match stmt.kind { ast::StmtKind::Semi(ref expr) => match expr.kind { - ast::ExprKind::While(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) => { + ast::ExprKind::While(..) | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop { .. } => { false } ast::ExprKind::Break(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Ret(..) => { @@ -473,9 +474,9 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::If(..) | ast::ExprKind::Block(..) | ast::ExprKind::ConstBlock(..) - | ast::ExprKind::Async(..) + | ast::ExprKind::Gen(..) | ast::ExprKind::Loop(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::TryBlock(..) | ast::ExprKind::Match(..) => repr.contains('\n'), ast::ExprKind::Paren(ref expr) diff --git a/tests/source/issue-2927-2.rs b/tests/source/issue-2927-2.rs index d87761fdc9c..07afef38cf5 100644 --- a/tests/source/issue-2927-2.rs +++ b/tests/source/issue-2927-2.rs @@ -1,5 +1,5 @@ // rustfmt-edition: 2015 -#![feature(rust_2018_preview, uniform_paths)] +#![feature(uniform_paths)] use futures::prelude::*; use http_03::cli::Cli; use hyper::{service::service_fn_ok, Body, Response, Server}; diff --git a/tests/source/issue-2927.rs b/tests/source/issue-2927.rs index a7df32084f3..c7ec7bb0855 100644 --- a/tests/source/issue-2927.rs +++ b/tests/source/issue-2927.rs @@ -1,5 +1,5 @@ // rustfmt-edition: 2018 -#![feature(rust_2018_preview, uniform_paths)] +#![feature(uniform_paths)] use futures::prelude::*; use http_03::cli::Cli; use hyper::{service::service_fn_ok, Body, Response, Server}; diff --git a/tests/source/issue-5987/two.rs b/tests/source/issue-5987/two.rs new file mode 100644 index 00000000000..e20026b5565 --- /dev/null +++ b/tests/source/issue-5987/two.rs @@ -0,0 +1,13 @@ +// rustfmt-version: Two + +fn main() { + trace!( + "get some longer length in here yes yes {} {}", + "hello", + "world" + ); + debug!( + "get some longer length in here yes yes {} {}", + "hello", "world" + ); +} diff --git a/tests/target/issue-2927-2.rs b/tests/target/issue-2927-2.rs index e895783ba8b..46e0bf0e989 100644 --- a/tests/target/issue-2927-2.rs +++ b/tests/target/issue-2927-2.rs @@ -1,5 +1,5 @@ // rustfmt-edition: 2015 -#![feature(rust_2018_preview, uniform_paths)] +#![feature(uniform_paths)] use futures::prelude::*; use http_03::cli::Cli; use hyper::{service::service_fn_ok, Body, Response, Server}; diff --git a/tests/target/issue-2927.rs b/tests/target/issue-2927.rs index 3267be28d7b..56afc2d3e40 100644 --- a/tests/target/issue-2927.rs +++ b/tests/target/issue-2927.rs @@ -1,5 +1,5 @@ // rustfmt-edition: 2018 -#![feature(rust_2018_preview, uniform_paths)] +#![feature(uniform_paths)] use ::log::{error, info, log}; use futures::prelude::*; use http_03::cli::Cli; diff --git a/tests/target/issue-5987/one.rs b/tests/target/issue-5987/one.rs new file mode 100644 index 00000000000..3c995ed28ba --- /dev/null +++ b/tests/target/issue-5987/one.rs @@ -0,0 +1,13 @@ +// rustfmt-version: One + +fn main() { + trace!( + "get some longer length in here yes yes {} {}", + "hello", + "world" + ); + debug!( + "get some longer length in here yes yes {} {}", + "hello", "world" + ); +} diff --git a/tests/target/issue-5987/two.rs b/tests/target/issue-5987/two.rs new file mode 100644 index 00000000000..8fd92fc179e --- /dev/null +++ b/tests/target/issue-5987/two.rs @@ -0,0 +1,12 @@ +// rustfmt-version: Two + +fn main() { + trace!( + "get some longer length in here yes yes {} {}", + "hello", "world" + ); + debug!( + "get some longer length in here yes yes {} {}", + "hello", "world" + ); +}