From f2bad9c7af308e6290f69bdf31390f9359a0e77b Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Wed, 5 Jul 2023 14:05:53 -0500 Subject: [PATCH] fix: handle skip_macro_invocations from config file --- src/config/macro_names.rs | 14 ++++++++++++-- tests/config/issue-5816.toml | 1 + tests/source/skip_macro_invocations/config_file.rs | 9 +++++++++ tests/target/skip_macro_invocations/config_file.rs | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/config/issue-5816.toml create mode 100644 tests/source/skip_macro_invocations/config_file.rs create mode 100644 tests/target/skip_macro_invocations/config_file.rs diff --git a/src/config/macro_names.rs b/src/config/macro_names.rs index 26ad78d6dca..61658f0a212 100644 --- a/src/config/macro_names.rs +++ b/src/config/macro_names.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use std::{fmt, str}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize}; use serde_json as json; use thiserror::Error; @@ -30,12 +30,22 @@ fn from(other: MacroName) -> Self { } /// Defines a selector to match against a macro. -#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize)] pub enum MacroSelector { Name(MacroName), All, } +impl<'de> Deserialize<'de> for MacroSelector { + fn deserialize(de: D) -> Result + where + D: Deserializer<'de>, + { + let s = String::deserialize(de)?; + std::str::FromStr::from_str(&s).map_err(serde::de::Error::custom) + } +} + impl fmt::Display for MacroSelector { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/tests/config/issue-5816.toml b/tests/config/issue-5816.toml new file mode 100644 index 00000000000..00375746e3f --- /dev/null +++ b/tests/config/issue-5816.toml @@ -0,0 +1 @@ +skip_macro_invocations=["*", "println"] diff --git a/tests/source/skip_macro_invocations/config_file.rs b/tests/source/skip_macro_invocations/config_file.rs new file mode 100644 index 00000000000..e0f5ddf52e7 --- /dev/null +++ b/tests/source/skip_macro_invocations/config_file.rs @@ -0,0 +1,9 @@ +// rustfmt-unstable: true +// rustfmt-config: issue-5816.toml + +fn main() { + println!( "Hello, world!"); + let x = +7 +; +} diff --git a/tests/target/skip_macro_invocations/config_file.rs b/tests/target/skip_macro_invocations/config_file.rs new file mode 100644 index 00000000000..008e28db42d --- /dev/null +++ b/tests/target/skip_macro_invocations/config_file.rs @@ -0,0 +1,7 @@ +// rustfmt-unstable: true +// rustfmt-config: issue-5816.toml + +fn main() { + println!( "Hello, world!"); + let x = 7; +}