warn on use of default value for an option

This commit is contained in:
Stéphane Campinas 2018-06-30 17:03:18 +02:00
parent f8f9457e20
commit f7a25a1177
No known key found for this signature in database
GPG Key ID: 6D5620D908210133
5 changed files with 18 additions and 4 deletions

View File

@ -205,7 +205,7 @@ and `ListFormatting` the key structure for configuration. You'll need to make a
Rustfmt strives to be highly configurable. Often the first part of a patch is
creating a configuration option for the feature you are implementing. All
handling of configuration options is done in [src/config.rs](src/config.rs). Look for the
handling of configuration options is done in [src/config/mod.rs](src/config/mod.rs). Look for the
`create_config!` macro at the end of the file for all the options. The rest of
the file defines a bunch of enums used for options, and the machinery to produce
the config struct and parse a config file, etc. Checking an option is done by

View File

@ -281,6 +281,7 @@ macro_rules! create_config {
match key {
$(
stringify!($i) => {
self.$i.1 = true;
self.$i.2 = val.parse::<$ty>()
.expect(&format!("Failed to parse override for {} (\"{}\") as a {}",
stringify!($i),
@ -421,6 +422,16 @@ macro_rules! create_config {
fn set_ignore(&mut self, dir: &Path) {
self.ignore.2.add_prefix(dir);
}
/// Returns true if the config key was explicitely set and is the default value.
pub fn is_default(&self, key: &str) -> bool {
$(
if let stringify!($i) = key {
return self.$i.1 && self.$i.2 == $def;
}
)+
false
}
}
// Template for the default configuration

View File

@ -126,7 +126,7 @@ impl Range {
/// It is represented as a multimap keyed on file names, with values a collection of
/// non-overlapping ranges sorted by their start point. An inner `None` is interpreted to mean all
/// lines in all files.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct FileLines(Option<HashMap<FileName, Vec<Range>>>);
/// Normalizes the ranges so that the invariants for `FileLines` hold: ranges are non-overlapping,

View File

@ -223,7 +223,7 @@ configuration_option_enum! { Verbosity:
Quiet,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
pub struct WidthHeuristics {
// Maximum width of the args of a function call before falling back
// to vertical formatting.
@ -293,7 +293,7 @@ impl Default for EmitMode {
}
/// A set of directories, files and modules that rustfmt should ignore.
#[derive(Default, Deserialize, Serialize, Clone, Debug)]
#[derive(Default, Deserialize, Serialize, Clone, Debug, PartialEq)]
pub struct IgnoreList(HashSet<PathBuf>);
impl IgnoreList {

View File

@ -363,6 +363,9 @@ fn read_config(filename: &Path) -> Config {
for (key, val) in &sig_comments {
if key != "target" && key != "config" {
config.override_value(key, val);
if config.is_default(key) {
warn!("Default value {} used explicitly for {}", val, key);
}
}
}