From d773580715ae3f4dd7ea1a4561b25f0b29f47bf8 Mon Sep 17 00:00:00 2001 From: Aaron Lobb Date: Mon, 14 Sep 2015 13:43:55 -0700 Subject: [PATCH] Changed ConfigType trait to only return a string of variants, rather than a vec --- src/bin/rustfmt.rs | 10 ++-------- src/config.rs | 37 +++++++++++++------------------------ src/utils.rs | 6 +++--- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index ee023c9eca82..2bc6e255ac0e 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -17,7 +17,7 @@ extern crate rustfmt; extern crate toml; use rustfmt::{WriteMode, run}; -use rustfmt::config::{Config, ConfigHelpVariantTypes}; +use rustfmt::config::Config; use std::env; use std::fs::{File, PathExt}; @@ -87,13 +87,7 @@ fn print_usage>(reason: S) { reason.into()); for option in Config::get_docs() { - let variants = option.variant_names(); - let variant_names: String = match *variants { - ConfigHelpVariantTypes::UsizeConfig => "".into(), - ConfigHelpVariantTypes::BoolConfig => "".into(), - ConfigHelpVariantTypes::EnumConfig(ref variants) => variants.join(", "), - }; - println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), variant_names); + println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), option.variant_names()); } } diff --git a/src/config.rs b/src/config.rs index 4026ea856cbb..e3ff126ee837 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,34 +82,28 @@ macro_rules! create_config { $(pub $i: Option<$ty>),+ } - // This trait and the following impl blocks are there only so that we - // can use UCFS inside the get_docs() function on builtin types for configs. - trait IsConfigType { - fn get_variant_names() -> Vec<&'static str>; + // This trait and the following impl blocks are there so that we an use + // UCFS inside the get_docs() function on types for configs. + pub trait ConfigType { + fn get_variant_names() -> String; } - impl IsConfigType for bool { - fn get_variant_names() -> Vec<&'static str> { - unreachable!() + impl ConfigType for bool { + fn get_variant_names() -> String { + String::from("") } } - impl IsConfigType for usize { - fn get_variant_names() -> Vec<&'static str> { - unreachable!() + impl ConfigType for usize { + fn get_variant_names() -> String { + String::from("") } } pub struct ConfigHelpItem { option_name: &'static str, doc_string : &'static str, - variant_names: ConfigHelpVariantTypes, - } - - pub enum ConfigHelpVariantTypes { - UsizeConfig, - BoolConfig, - EnumConfig(Vec<&'static str>), + variant_names: String, } impl ConfigHelpItem { @@ -121,7 +115,7 @@ macro_rules! create_config { self.doc_string } - pub fn variant_names(&self) -> &ConfigHelpVariantTypes { + pub fn variant_names(&self) -> &String { &self.variant_names } } @@ -165,15 +159,10 @@ macro_rules! create_config { pub fn get_docs() -> Vec { let mut options: Vec = Vec::new(); $( - let config_variant_type = match stringify!($ty) { - "bool" => ConfigHelpVariantTypes::BoolConfig, - "usize" => ConfigHelpVariantTypes::UsizeConfig, - _ => ConfigHelpVariantTypes::EnumConfig(<$ty>::get_variant_names()), - }; options.push(ConfigHelpItem { option_name: stringify!($i), doc_string: stringify!($dstring), - variant_names: config_variant_type, + variant_names: <$ty>::get_variant_names(), }); )+ options diff --git a/src/utils.rs b/src/utils.rs index 0ba0c2c4a48b..42d1151ba38c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -162,14 +162,14 @@ macro_rules! impl_enum_decodable { } } - impl $e { - pub fn get_variant_names() -> Vec<&'static str> { + impl ::config::ConfigType for $e { + fn get_variant_names() -> String { let mut variants = Vec::new(); $( variants.push(stringify!($x)); )* - variants + variants.join(", ") } } };