]> git.proxmox.com Git - rustc.git/blobdiff - src/libgraphviz/lib.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / libgraphviz / lib.rs
index b82b7d122b3ce8205c760602202243faed391eeb..c1bd188d3a286ef9b4ca1a84ecf103595f12ed18 100644 (file)
@@ -47,7 +47,7 @@
 //! which is cyclic.
 //!
 //! ```rust
-//! #![feature(rustc_private, core, into_cow)]
+//! #![feature(rustc_private, into_cow)]
 //!
 //! use std::borrow::IntoCow;
 //! use std::io::Write;
 //! entity `&sube`).
 //!
 //! ```rust
-//! #![feature(rustc_private, core, into_cow)]
+//! #![feature(rustc_private)]
 //!
-//! use std::borrow::IntoCow;
 //! use std::io::Write;
 //! use graphviz as dot;
 //!
 //!         dot::Id::new(format!("N{}", n)).unwrap()
 //!     }
 //!     fn node_label<'b>(&'b self, n: &Nd) -> dot::LabelText<'b> {
-//!         dot::LabelText::LabelStr(self.nodes[*n].as_slice().into_cow())
+//!         dot::LabelText::LabelStr(self.nodes[*n].into())
 //!     }
 //!     fn edge_label<'b>(&'b self, _: &Ed) -> dot::LabelText<'b> {
-//!         dot::LabelText::LabelStr("&sube;".into_cow())
+//!         dot::LabelText::LabelStr("&sube;".into())
 //!     }
 //! }
 //!
 //! Hasse-diagram for the subsets of the set `{x, y}`.
 //!
 //! ```rust
-//! #![feature(rustc_private, core, into_cow)]
+//! #![feature(rustc_private)]
 //!
-//! use std::borrow::IntoCow;
 //! use std::io::Write;
 //! use graphviz as dot;
 //!
 //!     }
 //!     fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> {
 //!         let &(i, _) = n;
-//!         dot::LabelText::LabelStr(self.nodes[i].into_cow())
+//!         dot::LabelText::LabelStr(self.nodes[i].into())
 //!     }
 //!     fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> {
-//!         dot::LabelText::LabelStr("&sube;".into_cow())
+//!         dot::LabelText::LabelStr("&sube;".into())
 //!     }
 //! }
 //!
 #![crate_name = "graphviz"]
 #![unstable(feature = "rustc_private", issue = "27812")]
 #![feature(staged_api)]
-#![staged_api]
+#![cfg_attr(stage0, staged_api)]
 #![crate_type = "rlib"]
 #![crate_type = "dylib"]
 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
-       html_root_url = "https://doc.rust-lang.org/nightly/")]
+       html_root_url = "https://doc.rust-lang.org/nightly/",
+       test(attr(allow(unused_variables), deny(warnings))))]
 
 #![feature(into_cow)]
 #![feature(str_escape)]
@@ -417,10 +416,10 @@ impl<'a> Id<'a> {
                 _ => return Err(()),
             }
             if !chars.all(is_constituent) {
-                return Err(())
+                return Err(());
             }
         }
-        return Ok(Id{ name: name });
+        return Ok(Id { name: name });
 
         fn is_letter_or_underscore(c: char) -> bool {
             in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
@@ -497,11 +496,10 @@ pub trait Labeller<'a,N,E> {
 /// Escape tags in such a way that it is suitable for inclusion in a
 /// Graphviz HTML label.
 pub fn escape_html(s: &str) -> String {
-    s
-        .replace("&", "&amp;")
-        .replace("\"", "&quot;")
-        .replace("<", "&lt;")
-        .replace(">", "&gt;")
+    s.replace("&", "&amp;")
+     .replace("\"", "&quot;")
+     .replace("<", "&lt;")
+     .replace(">", "&gt;")
 }
 
 impl<'a> LabelText<'a> {
@@ -524,9 +522,11 @@ impl<'a> LabelText<'a> {
             // not escaping \\, since Graphviz escString needs to
             // interpret backslashes; see EscStr above.
             '\\' => f(c),
-            _ => for c in c.escape_default() {
-                f(c)
-            },
+            _ => {
+                for c in c.escape_default() {
+                    f(c)
+                }
+            }
         }
     }
     fn escape_str(s: &str) -> String {
@@ -554,11 +554,13 @@ impl<'a> LabelText<'a> {
     fn pre_escaped_content(self) -> Cow<'a, str> {
         match self {
             EscStr(s) => s,
-            LabelStr(s) => if s.contains('\\') {
-                (&*s).escape_default().into_cow()
-            } else {
-                s
-            },
+            LabelStr(s) => {
+                if s.contains('\\') {
+                    (&*s).escape_default().into_cow()
+                } else {
+                    s
+                }
+            }
             HtmlStr(s) => s,
         }
     }
@@ -739,7 +741,12 @@ mod tests {
     }
 
     fn edge(from: usize, to: usize, label: &'static str, style: Style) -> Edge {
-        Edge { from: from, to: to, label: label, style: style }
+        Edge {
+            from: from,
+            to: to,
+            label: label,
+            style: style,
+        }
     }
 
     struct LabelledGraph {
@@ -1010,7 +1017,7 @@ r#"digraph single_cyclic_node {
 
     #[test]
     fn hasse_diagram() {
-        let labels = AllNodesLabelled(vec!("{x,y}", "{x}", "{y}", "{}"));
+        let labels = AllNodesLabelled(vec!["{x,y}", "{x}", "{y}", "{}"]);
         let r = test_input(LabelledGraph::new("hasse_diagram",
                                               labels,
                                               vec![edge(0, 1, "", Style::None),
@@ -1034,7 +1041,7 @@ r#"digraph hasse_diagram {
 
     #[test]
     fn left_aligned_text() {
-        let labels = AllNodesLabelled(vec!(
+        let labels = AllNodesLabelled(vec![
             "if test {\
            \\l    branch1\
            \\l} else {\
@@ -1044,7 +1051,7 @@ r#"digraph hasse_diagram {
            \\l",
             "branch1",
             "branch2",
-            "afterward"));
+            "afterward"]);
 
         let mut writer = Vec::new();