Remove dependency on Itertools

This commit is contained in:
Nick Cameron 2017-05-25 16:23:07 +12:00
parent 80f3b3c9c4
commit 393ba27311
8 changed files with 33 additions and 62 deletions

16
Cargo.lock generated
View file

@ -5,7 +5,6 @@ dependencies = [
"diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -46,11 +45,6 @@ name = "dtoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "either"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "env_logger"
version = "0.4.2"
@ -65,14 +59,6 @@ name = "getopts"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itertools"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.3.1"
@ -328,10 +314,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
"checksum env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e3856f1697098606fc6cb97a93de88ca3f3bc35bb878c725920e6e82ecf05e83"
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc"
"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e7eb6b826bfc1fdea7935d46556250d1799b7fe2d9f7951071f4291710665e3e"

View file

@ -33,7 +33,6 @@ syntex_errors = "0.58"
log = "0.3"
env_logger = "0.4"
getopts = "0.2"
itertools = "0.5.8"
[build-dependencies]
walkdir = "1.0.3"

View file

@ -160,9 +160,10 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
.chain(::std::iter::repeat(other_child_shape)
.take(subexpr_list.len() - 1));
let iter = subexpr_list.iter().rev().zip(child_shape_iter);
let mut rewrites =
try_opt!(iter.map(|(e, shape)| rewrite_chain_subexpr(e, total_span, context, shape))
.collect::<Option<Vec<_>>>());
let mut rewrites = try_opt!(iter.map(|(e, shape)| {
rewrite_chain_subexpr(e, total_span, context, shape)
})
.collect::<Option<Vec<_>>>());
// Total of all items excluding the last.
let almost_total = rewrites[..rewrites.len() - 1]

View file

@ -22,7 +22,6 @@ use comment::{FindUncommented, contains_comment};
use visitor::FmtVisitor;
use rewrite::{Rewrite, RewriteContext};
use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style, TypeDensity};
use itertools::Itertools;
use syntax::{ast, abi, codemap, ptr, symbol};
use syntax::codemap::{Span, BytePos, mk_sp};
@ -1324,8 +1323,8 @@ pub fn rewrite_associated_type(ident: ast::Ident,
Shape::legacy(context.config.max_width(),
indent))
})
.intersperse(Some(joiner.to_string()))
.collect::<Option<String>>());
.collect::<Option<Vec<_>>>())
.join(joiner);
if bounds.len() > 0 {
format!(": {}", bound_str)
} else {
@ -2041,8 +2040,8 @@ fn rewrite_trait_bounds(context: &RewriteContext,
let bound_str = try_opt!(bounds
.iter()
.map(|ty_bound| ty_bound.rewrite(&context, shape))
.intersperse(Some(joiner.to_string()))
.collect::<Option<String>>());
.collect::<Option<Vec<_>>>())
.join(joiner);
let mut result = String::new();
result.push_str(": ");
@ -2050,18 +2049,6 @@ fn rewrite_trait_bounds(context: &RewriteContext,
Some(result)
}
// fn reflow_list_node_with_rule(
// &self,
// node: &CompoundNode,
// rule: &Rule,
// args: &[Arg],
// shape: &Shape
// ) -> Result<String, ()>
// where
// T: Foo,
// {
fn rewrite_where_clause_rfc_style(context: &RewriteContext,
where_clause: &ast::WhereClause,
shape: Shape,

View file

@ -29,7 +29,6 @@ extern crate unicode_segmentation;
extern crate regex;
extern crate diff;
extern crate term;
extern crate itertools;
use errors::{Handler, DiagnosticBuilder};
use errors::emitter::{ColorConfig, EmitterWriter};

View file

@ -198,13 +198,17 @@ pub fn rewrite_macro(mac: &ast::Mac,
} else {
// Format macro invocation as array literal.
let rewrite =
try_opt!(rewrite_array(expr_vec.iter().map(|x| &**x),
mk_sp(context.codemap.span_after(mac.span,
original_style
.opener()),
mac.span.hi - BytePos(1)),
context,
mac_shape));
try_opt!(rewrite_array(
expr_vec.iter().map(|x| &**x),
mk_sp(
context
.codemap
.span_after(mac.span, original_style.opener()),
mac.span.hi - BytePos(1)
),
context,
mac_shape
));
Some(format!("{}{}", macro_name, rewrite))
}

View file

@ -24,7 +24,6 @@ use rewrite::{Rewrite, RewriteContext};
use utils::{extra_offset, format_mutability, colon_spaces, wrap_str};
use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple_type};
use config::TypeDensity;
use itertools::Itertools;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PathContext {
@ -367,8 +366,8 @@ impl Rewrite for ast::WherePredicate {
let lifetime_str: String = try_opt!(bound_lifetimes
.iter()
.map(|lt| lt.rewrite(context, shape))
.intersperse(Some(", ".to_string()))
.collect());
.collect::<Option<Vec<_>>>())
.join(", ");
let joiner = match context.config.type_punctuation_density() {
TypeDensity::Compressed => "+",
@ -382,8 +381,8 @@ impl Rewrite for ast::WherePredicate {
.map(|ty_bound| {
ty_bound.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
})
.intersperse(Some(joiner.to_string()))
.collect());
.collect::<Option<Vec<_>>>())
.join(joiner);
if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 {
format!("for< {} > {}{}{}",
@ -406,8 +405,8 @@ impl Rewrite for ast::WherePredicate {
.map(|ty_bound| {
ty_bound.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
})
.intersperse(Some(joiner.to_string()))
.collect());
.collect::<Option<Vec<_>>>())
.join(joiner);
format!("{}{}{}", type_str, colon, bounds_str)
}
@ -526,8 +525,8 @@ impl Rewrite for ast::TyParam {
let bounds: String = try_opt!(self.bounds
.iter()
.map(|ty_bound| ty_bound.rewrite(context, shape))
.intersperse(Some(joiner.to_string()))
.collect());
.collect::<Option<Vec<_>>>())
.join(joiner);
result.push_str(&bounds);
}
@ -554,8 +553,8 @@ impl Rewrite for ast::PolyTraitRef {
let lifetime_str: String = try_opt!(self.bound_lifetimes
.iter()
.map(|lt| lt.rewrite(context, shape))
.intersperse(Some(", ".to_string()))
.collect());
.collect::<Option<Vec<_>>>())
.join(", ");
// 6 is "for<> ".len()
let extra_offset = lifetime_str.len() + 6;
@ -701,8 +700,8 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
l.rewrite(context,
Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
})
.intersperse(Some(", ".to_string()))
.collect::<Option<String>>()));
.collect::<Option<Vec<_>>>())
.join(", "));
result.push_str("> ");
}

View file

@ -11,8 +11,6 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use itertools::Itertools;
use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind, NestedMetaItem,
NestedMetaItemKind, Path};
use syntax::codemap::BytePos;
@ -44,14 +42,14 @@ pub fn format_visibility(vis: &Visibility) -> Cow<'static, str> {
Visibility::Crate(_) => Cow::from("pub(crate) "),
Visibility::Restricted { ref path, .. } => {
let Path { ref segments, .. } = **path;
let mut segments_iter = segments.iter().map(|seg| seg.identifier.name.as_str());
let mut segments_iter = segments.iter().map(|seg| seg.identifier.name.to_string());
if path.is_global() {
segments_iter
.next()
.expect("Non-global path in pub(restricted)?");
}
Cow::from(format!("pub({}) ", segments_iter.join("::")))
Cow::from(format!("pub({}) ", segments_iter.collect::<Vec<_>>().join("::")))
}
}
}