]> git.lizzy.rs Git - rust.git/blobdiff - src/config/options.rs
deps: update rustc-ap to v642.0.0
[rust.git] / src / config / options.rs
index 4de8ef928dd593d85854a7e6a0e30f6aae8ef70e..c9d51a5a71a6a31dd6e884dbe813f16a1a5c2068 100644 (file)
@@ -2,10 +2,11 @@
 use std::fmt;
 use std::path::{Path, PathBuf};
 
-use atty;
-use config_proc_macro::config_type;
+use itertools::Itertools;
+use rustfmt_config_proc_macro::config_type;
 use serde::de::{SeqAccess, Visitor};
-use serde::{Deserialize, Deserializer, Serialize};
+use serde::ser::SerializeSeq;
+use serde::{Deserialize, Deserializer, Serialize, Serializer};
 
 use crate::config::lists::*;
 use crate::config::Config;
@@ -57,10 +58,11 @@ pub enum IndentStyle {
 
 #[config_type]
 /// How to place a list-like items.
+/// FIXME: Issue-3581: this should be renamed to ItemsLayout when publishing 2.0
 pub enum Density {
     /// Fit as much on one line as possible.
     Compressed,
-    /// Use more lines.
+    /// Items are placed horizontally if sufficient space, vertically otherwise.
     Tall,
     /// Place every item on a separate line.
     Vertical,
@@ -116,6 +118,9 @@ pub enum EmitMode {
     Coverage,
     /// Unfancy stdout
     Checkstyle,
+    /// Writes the resulting diffs in a JSON format. Returns an empty array
+    /// `[]` if there were no diffs.
+    Json,
     /// Output the changed lines (for internal value only)
     ModifiedLines,
     /// Checks if a diff can be generated. If so, rustfmt outputs a diff and
@@ -141,7 +146,7 @@ pub enum Color {
 pub enum Version {
     /// 1.x.y. When specified, rustfmt will format in the same style as 1.0.0.
     One,
-    /// 2.x.y. When specified, rustfmt will formatin the the latest style.
+    /// 2.x.y. When specified, rustfmt will format in the the latest style.
     Two,
 }
 
@@ -149,9 +154,8 @@ impl Color {
     /// Whether we should use a coloured terminal.
     pub fn use_colored_tty(self) -> bool {
         match self {
-            Color::Always => true,
+            Color::Always | Color::Auto => true,
             Color::Never => false,
-            Color::Auto => atty::is(atty::Stream::Stdout),
         }
     }
 }
@@ -191,6 +195,12 @@ pub struct WidthHeuristics {
     pub single_line_if_else_max_width: usize,
 }
 
+impl fmt::Display for WidthHeuristics {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{:?}", self)
+    }
+}
+
 impl WidthHeuristics {
     // Using this WidthHeuristics means we ignore heuristics.
     pub fn null() -> WidthHeuristics {
@@ -254,16 +264,42 @@ fn default() -> EmitMode {
 }
 
 /// A set of directories, files and modules that rustfmt should ignore.
-#[derive(Default, Serialize, Clone, Debug, PartialEq)]
+#[derive(Default, Clone, Debug, PartialEq)]
 pub struct IgnoreList {
     /// A set of path specified in rustfmt.toml.
-    #[serde(flatten)]
     path_set: HashSet<PathBuf>,
     /// A path to rustfmt.toml.
-    #[serde(skip_serializing)]
     rustfmt_toml_path: PathBuf,
 }
 
+impl fmt::Display for IgnoreList {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(
+            f,
+            "[{}]",
+            self.path_set
+                .iter()
+                .format_with(", ", |path, f| f(&format_args!(
+                    "{}",
+                    path.to_string_lossy()
+                )))
+        )
+    }
+}
+
+impl Serialize for IgnoreList {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+    where
+        S: Serializer,
+    {
+        let mut seq = serializer.serialize_seq(Some(self.path_set.len()))?;
+        for e in &self.path_set {
+            seq.serialize_element(e)?;
+        }
+        seq.end()
+    }
+}
+
 impl<'de> Deserialize<'de> for IgnoreList {
     fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
     where
@@ -349,10 +385,10 @@ fn default() -> Edition {
 }
 
 impl Edition {
-    pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
+    pub(crate) fn to_libsyntax_pos_edition(self) -> rustc_span::edition::Edition {
         match self {
-            Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
-            Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,
+            Edition::Edition2015 => rustc_span::edition::Edition::Edition2015,
+            Edition::Edition2018 => rustc_span::edition::Edition::Edition2018,
         }
     }
 }