Skip to content

Commit a7d4ec9

Browse files
topecongiroscampi
authored andcommitted
Implement Serialize on IgnoreList (rust-lang#3565)
* Implement Serialize on IgnoreList * Add a test for rust-lang#3536
1 parent b5449ba commit a7d4ec9

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

src/config/mod.rs

+73
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,79 @@ mod test {
462462
assert_eq!(s.contains("(unstable)"), true);
463463
}
464464

465+
#[test]
466+
fn test_dump_default_config() {
467+
const DEFAULT_CONFIG: &str = r#"max_width = 100
468+
hard_tabs = false
469+
tab_spaces = 4
470+
newline_style = "Auto"
471+
use_small_heuristics = "Default"
472+
indent_style = "Block"
473+
wrap_comments = false
474+
format_code_in_doc_comments = false
475+
comment_width = 80
476+
normalize_comments = false
477+
normalize_doc_attributes = false
478+
license_template_path = ""
479+
format_strings = false
480+
format_macro_matchers = false
481+
format_macro_bodies = true
482+
empty_item_single_line = true
483+
struct_lit_single_line = true
484+
fn_single_line = false
485+
where_single_line = false
486+
imports_indent = "Block"
487+
imports_layout = "Mixed"
488+
merge_imports = false
489+
reorder_imports = true
490+
reorder_modules = true
491+
reorder_impl_items = false
492+
type_punctuation_density = "Wide"
493+
space_before_colon = false
494+
space_after_colon = true
495+
spaces_around_ranges = false
496+
binop_separator = "Front"
497+
remove_nested_parens = true
498+
combine_control_expr = true
499+
overflow_delimited_expr = false
500+
struct_field_align_threshold = 0
501+
enum_discrim_align_threshold = 0
502+
match_arm_blocks = true
503+
force_multiline_blocks = false
504+
fn_args_density = "Tall"
505+
brace_style = "SameLineWhere"
506+
control_brace_style = "AlwaysSameLine"
507+
trailing_semicolon = true
508+
trailing_comma = "Vertical"
509+
match_block_trailing_comma = false
510+
blank_lines_upper_bound = 1
511+
blank_lines_lower_bound = 0
512+
edition = "2015"
513+
version = "One"
514+
inline_attribute_width = 0
515+
merge_derives = true
516+
use_try_shorthand = false
517+
use_field_init_shorthand = false
518+
force_explicit_abi = true
519+
condense_wildcard_suffixes = false
520+
color = "Auto"
521+
required_version = "1.2.2"
522+
unstable_features = false
523+
disable_all_formatting = false
524+
skip_children = false
525+
hide_parse_errors = false
526+
error_on_line_overflow = false
527+
error_on_unformatted = false
528+
report_todo = "Never"
529+
report_fixme = "Never"
530+
ignore = []
531+
emit_mode = "Files"
532+
make_backup = false
533+
"#;
534+
let toml = Config::default().all_options().to_toml().unwrap();
535+
assert_eq!(&toml, DEFAULT_CONFIG);
536+
}
537+
465538
// FIXME(#2183): these tests cannot be run in parallel because they use env vars.
466539
// #[test]
467540
// fn test_as_not_nightly_channel() {

src/config/options.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::path::{Path, PathBuf};
55
use atty;
66
use config_proc_macro::config_type;
77
use serde::de::{SeqAccess, Visitor};
8-
use serde::{Deserialize, Deserializer, Serialize};
8+
use serde::ser::SerializeSeq;
9+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
910

1011
use crate::config::lists::*;
1112
use crate::config::Config;
@@ -254,16 +255,27 @@ impl Default for EmitMode {
254255
}
255256

256257
/// A set of directories, files and modules that rustfmt should ignore.
257-
#[derive(Default, Serialize, Clone, Debug, PartialEq)]
258+
#[derive(Default, Clone, Debug, PartialEq)]
258259
pub struct IgnoreList {
259260
/// A set of path specified in rustfmt.toml.
260-
#[serde(flatten)]
261261
path_set: HashSet<PathBuf>,
262262
/// A path to rustfmt.toml.
263-
#[serde(skip_serializing)]
264263
rustfmt_toml_path: PathBuf,
265264
}
266265

266+
impl Serialize for IgnoreList {
267+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
268+
where
269+
S: Serializer,
270+
{
271+
let mut seq = serializer.serialize_seq(Some(self.path_set.len()))?;
272+
for e in &self.path_set {
273+
seq.serialize_element(e)?;
274+
}
275+
seq.end()
276+
}
277+
}
278+
267279
impl<'de> Deserialize<'de> for IgnoreList {
268280
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
269281
where

0 commit comments

Comments
 (0)