about summary refs log tree commit diff
path: root/src/libsyntax/attr.rs
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2015-02-27 13:34:33 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2015-04-03 15:46:03 +0300
commit723ca4bd4dd68a351dbd001ed1ae958e13c4bc8c (patch)
treef5539906e242c1ba50a7bd60ef3b8c6caeacf061 /src/libsyntax/attr.rs
parentb9a11f0f85416924487e17601458eb07b2e9fa06 (diff)
downloadrust-723ca4bd4dd68a351dbd001ed1ae958e13c4bc8c.tar.gz
rust-723ca4bd4dd68a351dbd001ed1ae958e13c4bc8c.zip
Validate export_name attribute
Diffstat (limited to 'src/libsyntax/attr.rs')
-rw-r--r--src/libsyntax/attr.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index 06e447bb12a..b966fe2c6e5 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -282,6 +282,23 @@ pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> {
     first_attr_value_str_by_name(attrs, "crate_name")
 }
 
+/// Find the value of #[export_name=*] attribute and check its validity.
+pub fn find_export_name_attr(diag: &SpanHandler, attrs: &[Attribute]) -> Option<InternedString> {
+    attrs.iter().fold(None, |ia,attr| {
+        if attr.check_name("export_name") {
+            if let s@Some(_) = attr.value_str() {
+                s
+            } else {
+                diag.span_err(attr.span, "export_name attribute has invalid format");
+                diag.handler.help("use #[export_name=\"*\"]");
+                None
+            }
+        } else {
+            ia
+        }
+    })
+}
+
 #[derive(Copy, Clone, PartialEq)]
 pub enum InlineAttr {
     None,