]> git.lizzy.rs Git - rust.git/blobdiff - crates/project_model/src/cfg_flag.rs
Merge #11391
[rust.git] / crates / project_model / src / cfg_flag.rs
index e92962cf6727ba94f245d56f035886fe2cef25c2..f3dd8f51333be447b350e4baf402c0272c7e15b7 100644 (file)
@@ -1,10 +1,9 @@
 //! Parsing of CfgFlags as command line arguments, as in
 //!
 //! rustc main.rs --cfg foo --cfg 'feature="bar"'
-use std::str::FromStr;
+use std::{fmt, str::FromStr};
 
 use cfg::CfgOptions;
-use stdx::split_once;
 
 #[derive(Clone, Eq, PartialEq, Debug)]
 pub enum CfgFlag {
@@ -15,7 +14,7 @@ pub enum CfgFlag {
 impl FromStr for CfgFlag {
     type Err = String;
     fn from_str(s: &str) -> Result<Self, Self::Err> {
-        let res = match split_once(s, '=') {
+        let res = match s.split_once('=') {
             Some((key, value)) => {
                 if !(value.starts_with('"') && value.ends_with('"')) {
                     return Err(format!("Invalid cfg ({:?}), value should be in quotes", s));
@@ -49,3 +48,16 @@ fn extend<T: IntoIterator<Item = CfgFlag>>(&mut self, iter: T) {
         }
     }
 }
+
+impl fmt::Display for CfgFlag {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            CfgFlag::Atom(atom) => f.write_str(atom),
+            CfgFlag::KeyValue { key, value } => {
+                f.write_str(key)?;
+                f.write_str("=")?;
+                f.write_str(value)
+            }
+        }
+    }
+}