mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-24 04:46:58 +00:00
warn on use of default value for an option
This commit is contained in:
parent
f8f9457e20
commit
f7a25a1177
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user