From d739d93787314690b5e7823d9e3aae2a8ffd2111 Mon Sep 17 00:00:00 2001 From: Aleksey Kononov Date: Sat, 16 Dec 2023 19:43:26 +0300 Subject: [PATCH] rename `hide_parse_errors` as `show_parse_errors` Closes 3390 `hide_parse_errors` is now deprecated, and was renamed `show_parse_errors` to avoid confusion around the double negative default of `hide_parse_errors=false`. --- Configurations.md | 10 +++++++++- src/config/config_type.rs | 20 ++++++++++++++++++-- src/config/mod.rs | 13 +++++++++++-- src/lib.rs | 2 +- src/macros.rs | 2 +- src/parse/session.rs | 6 +++--- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Configurations.md b/Configurations.md index ac5747800b2..c9e908d3b47 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1248,12 +1248,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/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/mod.rs b/src/config/mod.rs index 58f8a9c264a..f1474fd3e61 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -169,7 +169,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, \ @@ -204,6 +205,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) } @@ -456,6 +458,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 \ @@ -681,7 +690,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 = [] 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 b4c58d2fefb..86694089fd6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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/parse/session.rs b/src/parse/session.rs index 0573df9de2f..162a8caf373 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -122,7 +122,7 @@ fn default_handler( source_map: Lrc, ignore_path_set: Lrc, can_reset: Lrc, - hide_parse_errors: bool, + show_parse_errors: bool, color: Color, ) -> Handler { let supports_color = term::stderr().map_or(false, |term| term.supports_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( @@ -163,7 +163,7 @@ impl ParseSess { 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);