about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2021-09-24 18:02:02 +0300
committerSimonas Kazlauskas <git@kazlauskas.me>2022-03-01 01:57:25 +0200
commitdf701a292ce552fddad2048cfcb6edaf90222d85 (patch)
tree7e299460e96c3f5eb09851ef56e729332caedff3 /compiler/rustc_data_structures/src
parentc97c216efd542fbec5a7ccf9555f3cebb3198cec (diff)
downloadrust-df701a292ce552fddad2048cfcb6edaf90222d85.tar.gz
rust-df701a292ce552fddad2048cfcb6edaf90222d85.zip
Querify `global_backend_features`
At the very least this serves to deduplicate the diagnostics that are
output about unknown target features provided via CLI.
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/small_c_str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/small_c_str.rs b/compiler/rustc_data_structures/src/small_c_str.rs
index 33e72914e19..cd902524562 100644
--- a/compiler/rustc_data_structures/src/small_c_str.rs
+++ b/compiler/rustc_data_structures/src/small_c_str.rs
@@ -66,3 +66,15 @@ impl Deref for SmallCStr {
         self.as_c_str()
     }
 }
+
+impl<'a> FromIterator<&'a str> for SmallCStr {
+    fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
+        let mut data =
+            iter.into_iter().flat_map(|s| s.as_bytes()).copied().collect::<SmallVec<_>>();
+        data.push(0);
+        if let Err(e) = ffi::CStr::from_bytes_with_nul(&data) {
+            panic!("The iterator {:?} cannot be converted into a CStr: {}", data, e);
+        }
+        Self { data }
+    }
+}