about summary refs log tree commit diff
path: root/src/libsyntax/ast_util.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2014-11-29 17:08:30 +1300
committerNick Cameron <ncameron@mozilla.com>2014-12-12 19:11:59 +1300
commit397dda8aa08ee540cffd36f542ebd1140227d0bd (patch)
treeee4cc3c5f3434375ef05a0092f7df8154708b765 /src/libsyntax/ast_util.rs
parentda83ad8e2c8e2c5f522dc59963e00f55b1f8c03b (diff)
downloadrust-397dda8aa08ee540cffd36f542ebd1140227d0bd.tar.gz
rust-397dda8aa08ee540cffd36f542ebd1140227d0bd.zip
Add support for equality constraints on associated types
Diffstat (limited to 'src/libsyntax/ast_util.rs')
-rw-r--r--src/libsyntax/ast_util.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 7dba6a57fc4..eec3f69ee64 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -174,12 +174,28 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
                 parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
                     lifetimes: Vec::new(),
                     types: OwnedSlice::empty(),
+                    bindings: OwnedSlice::empty(),
                 })
             }
         ),
     }
 }
 
+// If path is a single segment ident path, return that ident. Otherwise, return
+// None.
+pub fn path_to_ident(path: &Path) -> Option<Ident> {
+    if path.segments.len() != 1 {
+        return None;
+    }
+
+    let segment = &path.segments[0];
+    if !segment.parameters.is_empty() {
+        return None;
+    }
+
+    Some(segment.identifier)
+}
+
 pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> {
     P(Pat {
         id: id,