Skip to content

Commit 25a75a4

Browse files
committed
Auto merge of #54847 - ljedrz:kill_graphviz_intocow, r=pnkfelix
Cleanup: remove graphviz::IntoCow It's just `Into<Cow<...>>` and the applicable methods already exist for `Vec`/`[T]` and `String`/`str`.
2 parents ef5c00d + c30ce35 commit 25a75a4

File tree

6 files changed

+40
-81
lines changed

6 files changed

+40
-81
lines changed

src/libgraphviz/lib.rs

+18-55
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
//! ```rust
5050
//! #![feature(rustc_private)]
5151
//!
52-
//! use graphviz::IntoCow;
5352
//! use std::io::Write;
5453
//! use graphviz as dot;
5554
//!
@@ -84,12 +83,12 @@
8483
//! }
8584
//! nodes.sort();
8685
//! nodes.dedup();
87-
//! nodes.into_cow()
86+
//! nodes.into()
8887
//! }
8988
//!
9089
//! fn edges(&'a self) -> dot::Edges<'a,Ed> {
9190
//! let &Edges(ref edges) = self;
92-
//! (&edges[..]).into_cow()
91+
//! (&edges[..]).into()
9392
//! }
9493
//!
9594
//! fn source(&self, e: &Ed) -> Nd { let &(s,_) = e; s }
@@ -144,9 +143,8 @@
144143
//! Since both the set of nodes and the set of edges are always
145144
//! constructed from scratch via iterators, we use the `collect()` method
146145
//! from the `Iterator` trait to collect the nodes and edges into freshly
147-
//! constructed growable `Vec` values (rather use the `into_cow`
148-
//! from the `IntoCow` trait as was used in the first example
149-
//! above).
146+
//! constructed growable `Vec` values (rather than using `Cow` as in the
147+
//! first example above).
150148
//!
151149
//! The output from this example renders four nodes that make up the
152150
//! Hasse-diagram for the subsets of the set `{x, y}`. Each edge is
@@ -293,7 +291,7 @@
293291

294292
use self::LabelText::*;
295293

296-
use std::borrow::{Cow, ToOwned};
294+
use std::borrow::Cow;
297295
use std::io::prelude::*;
298296
use std::io;
299297

@@ -411,8 +409,8 @@ impl<'a> Id<'a> {
411409
///
412410
/// Passing an invalid string (containing spaces, brackets,
413411
/// quotes, ...) will return an empty `Err` value.
414-
pub fn new<Name: IntoCow<'a, str>>(name: Name) -> Result<Id<'a>, ()> {
415-
let name = name.into_cow();
412+
pub fn new<Name: Into<Cow<'a, str>>>(name: Name) -> Result<Id<'a>, ()> {
413+
let name = name.into();
416414
match name.chars().next() {
417415
Some(c) if c.is_ascii_alphabetic() || c == '_' => {}
418416
_ => return Err(()),
@@ -473,7 +471,7 @@ pub trait Labeller<'a> {
473471
/// The label need not be unique, and may be the empty string; the
474472
/// default is in fact the empty string.
475473
fn edge_label(&'a self, _e: &Self::Edge) -> LabelText<'a> {
476-
LabelStr("".into_cow())
474+
LabelStr("".into())
477475
}
478476

479477
/// Maps `n` to a style that will be used in the rendered output.
@@ -497,16 +495,16 @@ pub fn escape_html(s: &str) -> String {
497495
}
498496

499497
impl<'a> LabelText<'a> {
500-
pub fn label<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
501-
LabelStr(s.into_cow())
498+
pub fn label<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
499+
LabelStr(s.into())
502500
}
503501

504-
pub fn escaped<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
505-
EscStr(s.into_cow())
502+
pub fn escaped<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
503+
EscStr(s.into())
506504
}
507505

508-
pub fn html<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
509-
HtmlStr(s.into_cow())
506+
pub fn html<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
507+
HtmlStr(s.into())
510508
}
511509

512510
fn escape_char<F>(c: char, mut f: F)
@@ -550,7 +548,7 @@ impl<'a> LabelText<'a> {
550548
EscStr(s) => s,
551549
LabelStr(s) => {
552550
if s.contains('\\') {
553-
(&*s).escape_default().into_cow()
551+
(&*s).escape_default().into()
554552
} else {
555553
s
556554
}
@@ -570,7 +568,7 @@ impl<'a> LabelText<'a> {
570568
let suffix = suffix.pre_escaped_content();
571569
prefix.push_str(r"\n\n");
572570
prefix.push_str(&suffix);
573-
EscStr(prefix.into_cow())
571+
EscStr(prefix.into())
574572
}
575573
}
576574

@@ -696,48 +694,13 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
696694
writeln!(w, "}}")
697695
}
698696

699-
pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
700-
fn into_cow(self) -> Cow<'a, B>;
701-
}
702-
703-
impl<'a> IntoCow<'a, str> for String {
704-
fn into_cow(self) -> Cow<'a, str> {
705-
Cow::Owned(self)
706-
}
707-
}
708-
709-
impl<'a> IntoCow<'a, str> for &'a str {
710-
fn into_cow(self) -> Cow<'a, str> {
711-
Cow::Borrowed(self)
712-
}
713-
}
714-
715-
impl<'a> IntoCow<'a, str> for Cow<'a, str> {
716-
fn into_cow(self) -> Cow<'a, str> {
717-
self
718-
}
719-
}
720-
721-
impl<'a, T: Clone> IntoCow<'a, [T]> for Vec<T> {
722-
fn into_cow(self) -> Cow<'a, [T]> {
723-
Cow::Owned(self)
724-
}
725-
}
726-
727-
impl<'a, T: Clone> IntoCow<'a, [T]> for &'a [T] {
728-
fn into_cow(self) -> Cow<'a, [T]> {
729-
Cow::Borrowed(self)
730-
}
731-
}
732-
733697
#[cfg(test)]
734698
mod tests {
735699
use self::NodeLabels::*;
736700
use super::{Id, Labeller, Nodes, Edges, GraphWalk, render, Style};
737701
use super::LabelText::{self, LabelStr, EscStr, HtmlStr};
738702
use std::io;
739703
use std::io::prelude::*;
740-
use IntoCow;
741704

742705
/// each node is an index in a vector in the graph.
743706
type Node = usize;
@@ -852,12 +815,12 @@ mod tests {
852815
}
853816
fn node_label(&'a self, n: &Node) -> LabelText<'a> {
854817
match self.node_labels[*n] {
855-
Some(ref l) => LabelStr(l.into_cow()),
818+
Some(l) => LabelStr(l.into()),
856819
None => LabelStr(id_name(n).name()),
857820
}
858821
}
859822
fn edge_label(&'a self, e: &&'a Edge) -> LabelText<'a> {
860-
LabelStr(e.label.into_cow())
823+
LabelStr(e.label.into())
861824
}
862825
fn node_style(&'a self, n: &Node) -> Style {
863826
self.node_styles[*n]

src/librustc/cfg/graphviz.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
1414
// For clarity, rename the graphviz crate locally to dot.
1515
use graphviz as dot;
16-
use graphviz::IntoCow;
1716

1817
use cfg;
1918
use hir;
@@ -71,21 +70,21 @@ impl<'a, 'hir> dot::Labeller<'a> for LabelledCFG<'a, 'hir> {
7170

7271
fn node_label(&'a self, &(i, n): &Node<'a>) -> dot::LabelText<'a> {
7372
if i == self.cfg.entry {
74-
dot::LabelText::LabelStr("entry".into_cow())
73+
dot::LabelText::LabelStr("entry".into())
7574
} else if i == self.cfg.exit {
76-
dot::LabelText::LabelStr("exit".into_cow())
75+
dot::LabelText::LabelStr("exit".into())
7776
} else if n.data.id() == hir::DUMMY_ITEM_LOCAL_ID {
78-
dot::LabelText::LabelStr("(dummy_node)".into_cow())
77+
dot::LabelText::LabelStr("(dummy_node)".into())
7978
} else {
8079
let s = self.local_id_to_string(n.data.id());
81-
dot::LabelText::EscStr(s.into_cow())
80+
dot::LabelText::EscStr(s.into())
8281
}
8382
}
8483

8584
fn edge_label(&self, e: &Edge<'a>) -> dot::LabelText<'a> {
8685
let mut label = String::new();
8786
if !self.labelled_edges {
88-
return dot::LabelText::EscStr(label.into_cow());
87+
return dot::LabelText::EscStr(label.into());
8988
}
9089
let mut put_one = false;
9190
for (i, &id) in e.data.exiting_scopes.iter().enumerate() {
@@ -99,7 +98,7 @@ impl<'a, 'hir> dot::Labeller<'a> for LabelledCFG<'a, 'hir> {
9998
i,
10099
&s[..]));
101100
}
102-
dot::LabelText::EscStr(label.into_cow())
101+
dot::LabelText::EscStr(label.into())
103102
}
104103
}
105104

@@ -109,7 +108,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
109108
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> {
110109
let mut v = Vec::new();
111110
self.graph.each_node(|i, nd| { v.push((i, nd)); true });
112-
v.into_cow()
111+
v.into()
113112
}
114113
fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> {
115114
self.graph.all_edges().iter().collect()

src/librustc_borrowck/graphviz.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use dot;
2323
use rustc::cfg::CFGIndex;
2424
use dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
2525
use std::rc::Rc;
26-
use dot::IntoCow;
2726

2827
#[derive(Debug, Copy, Clone)]
2928
pub enum Variant {
@@ -139,8 +138,8 @@ impl<'a, 'tcx> dot::Labeller<'a> for DataflowLabeller<'a, 'tcx> {
139138
let suffix = self.dataflow_for(EntryOrExit::Exit, n);
140139
let inner_label = self.inner.node_label(n);
141140
inner_label
142-
.prefix_line(dot::LabelText::LabelStr(prefix.into_cow()))
143-
.suffix_line(dot::LabelText::LabelStr(suffix.into_cow()))
141+
.prefix_line(dot::LabelText::LabelStr(prefix.into()))
142+
.suffix_line(dot::LabelText::LabelStr(suffix.into()))
144143
}
145144
fn edge_label(&'a self, e: &Edge<'a>) -> dot::LabelText<'a> { self.inner.edge_label(e) }
146145
}

src/librustc_incremental/assert_dep_graph.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use rustc_data_structures::graph::implementation::{
5555
use rustc::hir;
5656
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
5757
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
58-
use graphviz::IntoCow;
5958
use std::env;
6059
use std::fs::{self, File};
6160
use std::io::Write;
@@ -274,10 +273,10 @@ impl<'a, 'tcx, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> {
274273
type Edge = (&'q DepNode, &'q DepNode);
275274
fn nodes(&self) -> dot::Nodes<&'q DepNode> {
276275
let nodes: Vec<_> = self.0.iter().cloned().collect();
277-
nodes.into_cow()
276+
nodes.into()
278277
}
279278
fn edges(&self) -> dot::Edges<(&'q DepNode, &'q DepNode)> {
280-
self.1[..].into_cow()
279+
self.1[..].into()
281280
}
282281
fn source(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode {
283282
edge.0

src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use super::*;
1616
use borrow_check::nll::constraints::OutlivesConstraint;
17-
use dot::{self, IntoCow};
17+
use dot;
1818
use std::borrow::Cow;
1919
use std::io::{self, Write};
2020

@@ -49,7 +49,7 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
4949
type Edge = OutlivesConstraint;
5050

5151
fn graph_id(&'this self) -> dot::Id<'this> {
52-
dot::Id::new("RegionInferenceContext".to_string()).unwrap()
52+
dot::Id::new("RegionInferenceContext").unwrap()
5353
}
5454
fn node_id(&'this self, n: &RegionVid) -> dot::Id<'this> {
5555
dot::Id::new(format!("r{}", n.index())).unwrap()
@@ -58,10 +58,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
5858
Some(dot::LabelText::LabelStr(Cow::Borrowed("box")))
5959
}
6060
fn node_label(&'this self, n: &RegionVid) -> dot::LabelText<'this> {
61-
dot::LabelText::LabelStr(format!("{:?}", n).into_cow())
61+
dot::LabelText::LabelStr(format!("{:?}", n).into())
6262
}
6363
fn edge_label(&'this self, e: &OutlivesConstraint) -> dot::LabelText<'this> {
64-
dot::LabelText::LabelStr(format!("{:?}", e.locations).into_cow())
64+
dot::LabelText::LabelStr(format!("{:?}", e.locations).into())
6565
}
6666
}
6767

@@ -71,10 +71,10 @@ impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for RawConstraints<'a, 'tcx> {
7171

7272
fn nodes(&'this self) -> dot::Nodes<'this, RegionVid> {
7373
let vids: Vec<RegionVid> = self.regioncx.definitions.indices().collect();
74-
vids.into_cow()
74+
vids.into()
7575
}
7676
fn edges(&'this self) -> dot::Edges<'this, OutlivesConstraint> {
77-
(&self.regioncx.constraints.raw[..]).into_cow()
77+
(&self.regioncx.constraints.raw[..]).into()
7878
}
7979

8080
// Render `a: b` as `a -> b`, indicating the flow
@@ -109,7 +109,7 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> {
109109
}
110110
fn node_label(&'this self, n: &ConstraintSccIndex) -> dot::LabelText<'this> {
111111
let nodes = &self.nodes_per_scc[*n];
112-
dot::LabelText::LabelStr(format!("{:?} = {:?}", n, nodes).into_cow())
112+
dot::LabelText::LabelStr(format!("{:?} = {:?}", n, nodes).into())
113113
}
114114
}
115115

@@ -119,7 +119,7 @@ impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for SccConstraints<'a, 'tcx> {
119119

120120
fn nodes(&'this self) -> dot::Nodes<'this, ConstraintSccIndex> {
121121
let vids: Vec<ConstraintSccIndex> = self.regioncx.constraint_sccs.all_sccs().collect();
122-
vids.into_cow()
122+
vids.into()
123123
}
124124
fn edges(&'this self) -> dot::Edges<'this, (ConstraintSccIndex, ConstraintSccIndex)> {
125125
let edges: Vec<_> = self.regioncx
@@ -134,7 +134,7 @@ impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for SccConstraints<'a, 'tcx> {
134134
})
135135
.collect();
136136

137-
edges.into_cow()
137+
edges.into()
138138
}
139139

140140
// Render `a: b` as `a -> b`, indicating the flow

src/librustc_mir/dataflow/graphviz.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use syntax::ast::NodeId;
1414
use rustc::mir::{BasicBlock, Mir};
1515

1616
use dot;
17-
use dot::IntoCow;
1817

1918
use std::fs;
2019
use std::io;
@@ -257,7 +256,7 @@ impl<'a, 'tcx, MWF, P> dot::GraphWalk<'a> for Graph<'a, 'tcx, MWF, P>
257256
.basic_blocks()
258257
.indices()
259258
.collect::<Vec<_>>()
260-
.into_cow()
259+
.into()
261260
}
262261

263262
fn edges(&self) -> dot::Edges<Edge> {
@@ -267,7 +266,7 @@ impl<'a, 'tcx, MWF, P> dot::GraphWalk<'a> for Graph<'a, 'tcx, MWF, P>
267266
.indices()
268267
.flat_map(|bb| outgoing(mir, bb))
269268
.collect::<Vec<_>>()
270-
.into_cow()
269+
.into()
271270
}
272271

273272
fn source(&self, edge: &Edge) -> Node {

0 commit comments

Comments
 (0)