Skip to content

Commit a5c2d0f

Browse files
committedJul 29, 2018
Auto merge of #52764 - sinkuu:cleanup, r=nikomatsakis
Misc cleanups
2 parents fb0653e + e995a91 commit a5c2d0f

File tree

20 files changed

+50
-73
lines changed

20 files changed

+50
-73
lines changed
 

Diff for: ‎src/libcore/tests/num/dec2flt/parse.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::iter;
1211
use core::num::dec2flt::parse::{Decimal, parse_decimal};
1312
use core::num::dec2flt::parse::ParseResult::{Valid, Invalid};
1413

@@ -46,7 +45,7 @@ fn valid() {
4645
assert_eq!(parse_decimal("1.e300"), Valid(Decimal::new(b"1", b"", 300)));
4746
assert_eq!(parse_decimal(".1e300"), Valid(Decimal::new(b"", b"1", 300)));
4847
assert_eq!(parse_decimal("101e-33"), Valid(Decimal::new(b"101", b"", -33)));
49-
let zeros: String = iter::repeat('0').take(25).collect();
48+
let zeros = "0".repeat(25);
5049
let s = format!("1.5e{}", zeros);
5150
assert_eq!(parse_decimal(&s), Valid(Decimal::new(b"1", b"5", 0)));
5251
}

Diff for: ‎src/librustc/dep_graph/dep_node.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,8 @@ macro_rules! define_dep_nodes {
334334
pub fn extract_def_id(&self, tcx: TyCtxt) -> Option<DefId> {
335335
if self.kind.can_reconstruct_query_key() {
336336
let def_path_hash = DefPathHash(self.hash);
337-
if let Some(ref def_path_map) = tcx.def_path_hash_to_def_id.as_ref() {
338-
def_path_map.get(&def_path_hash).cloned()
339-
} else {
340-
None
341-
}
337+
tcx.def_path_hash_to_def_id.as_ref()?
338+
.get(&def_path_hash).cloned()
342339
} else {
343340
None
344341
}

Diff for: ‎src/librustc/dep_graph/graph.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,12 @@ impl DepGraph {
489489
}
490490

491491
pub(super) fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {
492-
self.data.as_ref().and_then(|t| t.dep_node_debug.borrow().get(&dep_node).cloned())
492+
self.data
493+
.as_ref()?
494+
.dep_node_debug
495+
.borrow()
496+
.get(&dep_node)
497+
.cloned()
493498
}
494499

495500
pub fn edge_deduplication_data(&self) -> (u64, u64) {

Diff for: ‎src/librustc/hir/pat_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
4747
let actual_len = self.len();
4848
EnumerateAndAdjust {
4949
enumerate: self.enumerate(),
50-
gap_pos: if let Some(gap_pos) = gap_pos { gap_pos } else { expected_len },
50+
gap_pos: gap_pos.unwrap_or(expected_len),
5151
gap_len: expected_len - actual_len,
5252
}
5353
}

Diff for: ‎src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
805805
// Foo<_, Qux>
806806
// ^ elided type as this type argument was the same in both sides
807807
let type_arguments = sub1.types().zip(sub2.types());
808-
let regions_len = sub1.regions().collect::<Vec<_>>().len();
808+
let regions_len = sub1.regions().count();
809809
for (i, (ta1, ta2)) in type_arguments.take(len).enumerate() {
810810
let i = i + regions_len;
811811
if ta1 == ta2 {

Diff for: ‎src/librustc/util/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::collections::HashMap;
1717
use std::ffi::CString;
1818
use std::fmt::Debug;
1919
use std::hash::{Hash, BuildHasher};
20-
use std::iter::repeat;
2120
use std::panic;
2221
use std::env;
2322
use std::path::Path;
@@ -219,7 +218,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) {
219218
None => "".to_owned(),
220219
};
221220
println!("{}time: {}{}\t{}",
222-
repeat(" ").take(indentation).collect::<String>(),
221+
" ".repeat(indentation),
223222
duration_to_secs_str(dur),
224223
mem_string,
225224
what);

Diff for: ‎src/librustc_codegen_llvm/back/symbol_export.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,8 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
206206
})
207207
.collect();
208208

209-
if let Some(_) = *tcx.sess.entry_fn.borrow() {
210-
let symbol_name = "main".to_string();
211-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
209+
if tcx.sess.entry_fn.borrow().is_some() {
210+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new("main"));
212211

213212
symbols.push((exported_symbol, SymbolExportLevel::C));
214213
}

Diff for: ‎src/librustc_driver/lib.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ use std::error::Error;
9696
use std::ffi::OsString;
9797
use std::fmt::{self, Display};
9898
use std::io::{self, Read, Write};
99-
use std::iter::repeat;
10099
use std::mem;
101100
use std::panic;
102101
use std::path::{PathBuf, Path};
@@ -1227,7 +1226,7 @@ Available lint options:
12271226
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
12281227
-> Vec<(&'static str, Vec<lint::LintId>)> {
12291228
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
1230-
lints.sort_by_key(|ref l| l.0);
1229+
lints.sort_by_key(|l| l.0);
12311230
lints
12321231
}
12331232

@@ -1251,9 +1250,7 @@ Available lint options:
12511250
.max()
12521251
.unwrap_or(0);
12531252
let padded = |x: &str| {
1254-
let mut s = repeat(" ")
1255-
.take(max_name_len - x.chars().count())
1256-
.collect::<String>();
1253+
let mut s = " ".repeat(max_name_len - x.chars().count());
12571254
s.push_str(x);
12581255
s
12591256
};
@@ -1285,9 +1282,7 @@ Available lint options:
12851282
.unwrap_or(0));
12861283

12871284
let padded = |x: &str| {
1288-
let mut s = repeat(" ")
1289-
.take(max_name_len - x.chars().count())
1290-
.collect::<String>();
1285+
let mut s = " ".repeat(max_name_len - x.chars().count());
12911286
s.push_str(x);
12921287
s
12931288
};

Diff for: ‎src/librustc_driver/profile/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetr
208208
for (ref cons, ref qm) in counts.iter() {
209209
data.push((cons.clone(), qm.count.clone(), qm.dur_total.clone(), qm.dur_self.clone()));
210210
};
211-
data.sort_by_key(|&k| Reverse(k.3));
211+
data.sort_by_key(|k| Reverse(k.3));
212212
for (cons, count, dur_total, dur_self) in data {
213213
write!(count_file, "{}, {}, {}, {}\n",
214214
cons, count,

Diff for: ‎src/librustc_errors/emitter.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,7 @@ impl EmitterWriter {
528528

529529
// If there are no annotations or the only annotations on this line are
530530
// MultilineLine, then there's only code being shown, stop processing.
531-
if line.annotations.is_empty() || line.annotations.iter()
532-
.filter(|a| !a.is_line()).collect::<Vec<_>>().len() == 0
533-
{
531+
if line.annotations.iter().all(|a| a.is_line()) {
534532
return vec![];
535533
}
536534

@@ -901,9 +899,7 @@ impl EmitterWriter {
901899
// | | length of label
902900
// | magic `3`
903901
// `max_line_num_len`
904-
let padding = (0..padding + label.len() + 5)
905-
.map(|_| " ")
906-
.collect::<String>();
902+
let padding = " ".repeat(padding + label.len() + 5);
907903

908904
/// Return whether `style`, or the override if present and the style is `NoStyle`.
909905
fn style_or_override(style: Style, override_style: Option<Style>) -> Style {

Diff for: ‎src/librustc_errors/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,8 @@ impl Handler {
608608
if can_show_explain && are_there_diagnostics {
609609
let mut error_codes =
610610
self.emitted_diagnostic_codes.borrow()
611-
.clone()
612-
.into_iter()
613-
.filter_map(|x| match x {
611+
.iter()
612+
.filter_map(|x| match *x {
614613
DiagnosticId::Error(ref s) => Some(s.clone()),
615614
_ => None,
616615
})

Diff for: ‎src/librustc_lint/bad_style.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,18 @@ impl NonCamelCaseTypes {
8383
} else {
8484
c.to_lowercase().collect()
8585
})
86-
.collect::<Vec<_>>()
87-
.concat()
86+
.collect::<String>()
8887
})
8988
.filter(|x| !x.is_empty())
90-
.collect::<Vec<_>>()
91-
.iter().fold((String::new(), None), |(acc, prev): (String, Option<&String>), next| {
89+
.fold((String::new(), None), |(acc, prev): (String, Option<String>), next| {
9290
// separate two components with an underscore if their boundary cannot
9391
// be distinguished using a uppercase/lowercase case distinction
9492
let join = if let Some(prev) = prev {
9593
let l = prev.chars().last().unwrap();
9694
let f = next.chars().next().unwrap();
9795
!char_has_case(l) && !char_has_case(f)
9896
} else { false };
99-
(acc + if join { "_" } else { "" } + next, Some(next))
97+
(acc + if join { "_" } else { "" } + &next, Some(next))
10098
}).0
10199
}
102100

Diff for: ‎src/librustc_mir/hair/pattern/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use arena::TypedArena;
3232

3333
use std::cmp::{self, Ordering};
3434
use std::fmt;
35-
use std::iter::{FromIterator, IntoIterator, repeat};
35+
use std::iter::{FromIterator, IntoIterator};
3636

3737
pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pattern<'tcx>)
3838
-> &'a Pattern<'tcx>
@@ -115,7 +115,7 @@ impl<'a, 'tcx> fmt::Debug for Matrix<'a, 'tcx> {
115115
}).collect();
116116

117117
let total_width = column_widths.iter().cloned().sum::<usize>() + column_count * 3 + 1;
118-
let br = repeat('+').take(total_width).collect::<String>();
118+
let br = "+".repeat(total_width);
119119
write!(f, "{}\n", br)?;
120120
for row in pretty_printed_matrix {
121121
write!(f, "+")?;

Diff for: ‎src/librustc_mir/monomorphize/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mon
2929
(mono_item, mono_item.symbol_name(tcx))
3030
}).collect();
3131

32-
(&mut symbols[..]).sort_by_key(|&sym| sym.1);
32+
symbols.sort_by_key(|sym| sym.1);
3333

34-
for pair in (&symbols[..]).windows(2) {
34+
for pair in symbols.windows(2) {
3535
let sym1 = &pair[0].1;
3636
let sym2 = &pair[1].1;
3737

38-
if *sym1 == *sym2 {
38+
if sym1 == sym2 {
3939
let mono_item1 = pair[0].0;
4040
let mono_item2 = pair[1].0;
4141

@@ -51,9 +51,7 @@ pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mon
5151
span2
5252
})
5353
}
54-
(Some(span), None) |
55-
(None, Some(span)) => Some(span),
56-
_ => None
54+
(span1, span2) => span1.or(span2),
5755
};
5856

5957
let error_message = format!("symbol `{}` is already defined", sym1);

Diff for: ‎src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
269269
err
270270
}
271271
ResolutionError::VariableNotBoundInPattern(binding_error) => {
272-
let target_sp = binding_error.target.iter().map(|x| *x).collect::<Vec<_>>();
272+
let target_sp = binding_error.target.iter().cloned().collect::<Vec<_>>();
273273
let msp = MultiSpan::from_spans(target_sp.clone());
274274
let msg = format!("variable `{}` is not bound in all patterns", binding_error.name);
275275
let mut err = resolver.session.struct_span_err_with_code(
@@ -280,7 +280,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
280280
for sp in target_sp {
281281
err.span_label(sp, format!("pattern doesn't bind `{}`", binding_error.name));
282282
}
283-
let origin_sp = binding_error.origin.iter().map(|x| *x).collect::<Vec<_>>();
283+
let origin_sp = binding_error.origin.iter().cloned();
284284
for sp in origin_sp {
285285
err.span_label(sp, "variable not in all patterns");
286286
}

Diff for: ‎src/librustdoc/html/format.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//! them in the future to instead emit any format desired.
1717
1818
use std::fmt;
19-
use std::iter::repeat;
2019

2120
use rustc::hir::def_id::DefId;
2221
use rustc_target::spec::abi::Abi;
@@ -235,10 +234,9 @@ impl<'a> fmt::Display for WhereClause<'a> {
235234

236235
if !f.alternate() {
237236
clause.push_str("</span>");
238-
let padding = repeat("&nbsp;").take(indent + 4).collect::<String>();
237+
let padding = "&nbsp;".repeat(indent + 4);
239238
clause = clause.replace("<br>", &format!("<br>{}", padding));
240-
clause.insert_str(0, &repeat("&nbsp;").take(indent.saturating_sub(1))
241-
.collect::<String>());
239+
clause.insert_str(0, &"&nbsp;".repeat(indent.saturating_sub(1)));
242240
if !end_newline {
243241
clause.insert_str(0, "<br>");
244242
}
@@ -409,13 +407,13 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
409407
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
410408
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
411409
Some(&(ref fqp, shortty)) => {
412-
(fqp, shortty, repeat("../").take(loc.len()).collect())
410+
(fqp, shortty, "../".repeat(loc.len()))
413411
}
414412
None => {
415413
let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
416414
(fqp, shortty, match cache.extern_locations[&did.krate] {
417415
(.., render::Remote(ref s)) => s.to_string(),
418-
(.., render::Local) => repeat("../").take(loc.len()).collect(),
416+
(.., render::Local) => "../".repeat(loc.len()),
419417
(.., render::Unknown) => return None,
420418
})
421419
}
@@ -481,7 +479,7 @@ fn primitive_link(f: &mut fmt::Formatter,
481479
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
482480
let len = if len == 0 {0} else {len - 1};
483481
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
484-
repeat("../").take(len).collect::<String>(),
482+
"../".repeat(len),
485483
prim.to_url_str())?;
486484
needs_termination = true;
487485
}
@@ -492,7 +490,7 @@ fn primitive_link(f: &mut fmt::Formatter,
492490
}
493491
(ref cname, _, render::Local) => {
494492
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
495-
Some((cname, repeat("../").take(len).collect::<String>()))
493+
Some((cname, "../".repeat(len)))
496494
}
497495
(.., render::Unknown) => None,
498496
};
@@ -907,15 +905,15 @@ impl<'a> fmt::Display for Method<'a> {
907905
format!("{}", decl.output)
908906
};
909907

910-
let pad = repeat(" ").take(name_len).collect::<String>();
908+
let pad = " ".repeat(name_len);
911909
let plain = format!("{pad}({args}){arrow}",
912910
pad = pad,
913911
args = args_plain,
914912
arrow = arrow_plain);
915913

916914
let output = if plain.len() > 80 {
917-
let full_pad = format!("<br>{}", repeat("&nbsp;").take(indent + 4).collect::<String>());
918-
let close_pad = format!("<br>{}", repeat("&nbsp;").take(indent).collect::<String>());
915+
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
916+
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
919917
format!("({args}{close}){arrow}",
920918
args = args.replace("<br>", &full_pad),
921919
close = close_pad,

Diff for: ‎src/librustdoc/html/render.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use std::ffi::OsStr;
4646
use std::fs::{self, File, OpenOptions};
4747
use std::io::prelude::*;
4848
use std::io::{self, BufWriter, BufReader};
49-
use std::iter::repeat;
5049
use std::mem;
5150
use std::path::{PathBuf, Path, Component};
5251
use std::str;
@@ -1712,7 +1711,7 @@ impl Context {
17121711
/// String representation of how to get back to the root path of the 'doc/'
17131712
/// folder in terms of a relative URL.
17141713
fn root_path(&self) -> String {
1715-
repeat("../").take(self.current.len()).collect::<String>()
1714+
"../".repeat(self.current.len())
17161715
}
17171716

17181717
/// Recurse in the directory structure and change the "root path" to make
@@ -2113,8 +2112,7 @@ impl<'a> fmt::Display for Item<'a> {
21132112
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
21142113
for (i, component) in cur.iter().enumerate().take(amt) {
21152114
write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
2116-
repeat("../").take(cur.len() - i - 1)
2117-
.collect::<String>(),
2115+
"../".repeat(cur.len() - i - 1),
21182116
component)?;
21192117
}
21202118
}

Diff for: ‎src/libstd/tests/env.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
extern crate rand;
1212

1313
use std::env::*;
14-
use std::iter::repeat;
1514
use std::ffi::{OsString, OsStr};
1615

1716
use rand::Rng;
@@ -72,7 +71,7 @@ fn test_var_big() {
7271
#[cfg_attr(target_os = "emscripten", ignore)]
7372
fn test_env_set_get_huge() {
7473
let n = make_rand_name();
75-
let s = repeat("x").take(10000).collect::<String>();
74+
let s = "x".repeat(10000);
7675
set_var(&n, &s);
7776
eq(var_os(&n), Some(&s));
7877
remove_var(&n);

0 commit comments

Comments
 (0)