Skip to content

Commit

Permalink
Auto merge of #52764 - sinkuu:cleanup, r=nikomatsakis
Browse files Browse the repository at this point in the history
Misc cleanups
  • Loading branch information
bors committed Jul 29, 2018
2 parents fb0653e + e995a91 commit a5c2d0f
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 73 deletions.
3 changes: 1 addition & 2 deletions src/libcore/tests/num/dec2flt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::iter;
use core::num::dec2flt::parse::{Decimal, parse_decimal};
use core::num::dec2flt::parse::ParseResult::{Valid, Invalid};

Expand Down Expand Up @@ -46,7 +45,7 @@ fn valid() {
assert_eq!(parse_decimal("1.e300"), Valid(Decimal::new(b"1", b"", 300)));
assert_eq!(parse_decimal(".1e300"), Valid(Decimal::new(b"", b"1", 300)));
assert_eq!(parse_decimal("101e-33"), Valid(Decimal::new(b"101", b"", -33)));
let zeros: String = iter::repeat('0').take(25).collect();
let zeros = "0".repeat(25);
let s = format!("1.5e{}", zeros);
assert_eq!(parse_decimal(&s), Valid(Decimal::new(b"1", b"5", 0)));
}
7 changes: 2 additions & 5 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,8 @@ macro_rules! define_dep_nodes {
pub fn extract_def_id(&self, tcx: TyCtxt) -> Option<DefId> {
if self.kind.can_reconstruct_query_key() {
let def_path_hash = DefPathHash(self.hash);
if let Some(ref def_path_map) = tcx.def_path_hash_to_def_id.as_ref() {
def_path_map.get(&def_path_hash).cloned()
} else {
None
}
tcx.def_path_hash_to_def_id.as_ref()?
.get(&def_path_hash).cloned()
} else {
None
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,12 @@ impl DepGraph {
}

pub(super) fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {
self.data.as_ref().and_then(|t| t.dep_node_debug.borrow().get(&dep_node).cloned())
self.data
.as_ref()?
.dep_node_debug
.borrow()
.get(&dep_node)
.cloned()
}

pub fn edge_deduplication_data(&self) -> (u64, u64) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
let actual_len = self.len();
EnumerateAndAdjust {
enumerate: self.enumerate(),
gap_pos: if let Some(gap_pos) = gap_pos { gap_pos } else { expected_len },
gap_pos: gap_pos.unwrap_or(expected_len),
gap_len: expected_len - actual_len,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// Foo<_, Qux>
// ^ elided type as this type argument was the same in both sides
let type_arguments = sub1.types().zip(sub2.types());
let regions_len = sub1.regions().collect::<Vec<_>>().len();
let regions_len = sub1.regions().count();
for (i, (ta1, ta2)) in type_arguments.take(len).enumerate() {
let i = i + regions_len;
if ta1 == ta2 {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::collections::HashMap;
use std::ffi::CString;
use std::fmt::Debug;
use std::hash::{Hash, BuildHasher};
use std::iter::repeat;
use std::panic;
use std::env;
use std::path::Path;
Expand Down Expand Up @@ -219,7 +218,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) {
None => "".to_owned(),
};
println!("{}time: {}{}\t{}",
repeat(" ").take(indentation).collect::<String>(),
" ".repeat(indentation),
duration_to_secs_str(dur),
mem_string,
what);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_codegen_llvm/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
})
.collect();

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

symbols.push((exported_symbol, SymbolExportLevel::C));
}
Expand Down
11 changes: 3 additions & 8 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ use std::error::Error;
use std::ffi::OsString;
use std::fmt::{self, Display};
use std::io::{self, Read, Write};
use std::iter::repeat;
use std::mem;
use std::panic;
use std::path::{PathBuf, Path};
Expand Down Expand Up @@ -1227,7 +1226,7 @@ Available lint options:
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
-> Vec<(&'static str, Vec<lint::LintId>)> {
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
lints.sort_by_key(|ref l| l.0);
lints.sort_by_key(|l| l.0);
lints
}

Expand All @@ -1251,9 +1250,7 @@ Available lint options:
.max()
.unwrap_or(0);
let padded = |x: &str| {
let mut s = repeat(" ")
.take(max_name_len - x.chars().count())
.collect::<String>();
let mut s = " ".repeat(max_name_len - x.chars().count());
s.push_str(x);
s
};
Expand Down Expand Up @@ -1285,9 +1282,7 @@ Available lint options:
.unwrap_or(0));

let padded = |x: &str| {
let mut s = repeat(" ")
.take(max_name_len - x.chars().count())
.collect::<String>();
let mut s = " ".repeat(max_name_len - x.chars().count());
s.push_str(x);
s
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/profile/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetr
for (ref cons, ref qm) in counts.iter() {
data.push((cons.clone(), qm.count.clone(), qm.dur_total.clone(), qm.dur_self.clone()));
};
data.sort_by_key(|&k| Reverse(k.3));
data.sort_by_key(|k| Reverse(k.3));
for (cons, count, dur_total, dur_self) in data {
write!(count_file, "{}, {}, {}, {}\n",
cons, count,
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,7 @@ impl EmitterWriter {

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

Expand Down Expand Up @@ -901,9 +899,7 @@ impl EmitterWriter {
// | | length of label
// | magic `3`
// `max_line_num_len`
let padding = (0..padding + label.len() + 5)
.map(|_| " ")
.collect::<String>();
let padding = " ".repeat(padding + label.len() + 5);

/// Return whether `style`, or the override if present and the style is `NoStyle`.
fn style_or_override(style: Style, override_style: Option<Style>) -> Style {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,8 @@ impl Handler {
if can_show_explain && are_there_diagnostics {
let mut error_codes =
self.emitted_diagnostic_codes.borrow()
.clone()
.into_iter()
.filter_map(|x| match x {
.iter()
.filter_map(|x| match *x {
DiagnosticId::Error(ref s) => Some(s.clone()),
_ => None,
})
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ impl NonCamelCaseTypes {
} else {
c.to_lowercase().collect()
})
.collect::<Vec<_>>()
.concat()
.collect::<String>()
})
.filter(|x| !x.is_empty())
.collect::<Vec<_>>()
.iter().fold((String::new(), None), |(acc, prev): (String, Option<&String>), next| {
.fold((String::new(), None), |(acc, prev): (String, Option<String>), next| {
// separate two components with an underscore if their boundary cannot
// be distinguished using a uppercase/lowercase case distinction
let join = if let Some(prev) = prev {
let l = prev.chars().last().unwrap();
let f = next.chars().next().unwrap();
!char_has_case(l) && !char_has_case(f)
} else { false };
(acc + if join { "_" } else { "" } + next, Some(next))
(acc + if join { "_" } else { "" } + &next, Some(next))
}).0
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use arena::TypedArena;

use std::cmp::{self, Ordering};
use std::fmt;
use std::iter::{FromIterator, IntoIterator, repeat};
use std::iter::{FromIterator, IntoIterator};

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

let total_width = column_widths.iter().cloned().sum::<usize>() + column_count * 3 + 1;
let br = repeat('+').take(total_width).collect::<String>();
let br = "+".repeat(total_width);
write!(f, "{}\n", br)?;
for row in pretty_printed_matrix {
write!(f, "+")?;
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_mir/monomorphize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mon
(mono_item, mono_item.symbol_name(tcx))
}).collect();

(&mut symbols[..]).sort_by_key(|&sym| sym.1);
symbols.sort_by_key(|sym| sym.1);

for pair in (&symbols[..]).windows(2) {
for pair in symbols.windows(2) {
let sym1 = &pair[0].1;
let sym2 = &pair[1].1;

if *sym1 == *sym2 {
if sym1 == sym2 {
let mono_item1 = pair[0].0;
let mono_item2 = pair[1].0;

Expand All @@ -51,9 +51,7 @@ pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mon
span2
})
}
(Some(span), None) |
(None, Some(span)) => Some(span),
_ => None
(span1, span2) => span1.or(span2),
};

let error_message = format!("symbol `{}` is already defined", sym1);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
err
}
ResolutionError::VariableNotBoundInPattern(binding_error) => {
let target_sp = binding_error.target.iter().map(|x| *x).collect::<Vec<_>>();
let target_sp = binding_error.target.iter().cloned().collect::<Vec<_>>();
let msp = MultiSpan::from_spans(target_sp.clone());
let msg = format!("variable `{}` is not bound in all patterns", binding_error.name);
let mut err = resolver.session.struct_span_err_with_code(
Expand All @@ -280,7 +280,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
for sp in target_sp {
err.span_label(sp, format!("pattern doesn't bind `{}`", binding_error.name));
}
let origin_sp = binding_error.origin.iter().map(|x| *x).collect::<Vec<_>>();
let origin_sp = binding_error.origin.iter().cloned();
for sp in origin_sp {
err.span_label(sp, "variable not in all patterns");
}
Expand Down
20 changes: 9 additions & 11 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! them in the future to instead emit any format desired.

use std::fmt;
use std::iter::repeat;

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

if !f.alternate() {
clause.push_str("</span>");
let padding = repeat("&nbsp;").take(indent + 4).collect::<String>();
let padding = "&nbsp;".repeat(indent + 4);
clause = clause.replace("<br>", &format!("<br>{}", padding));
clause.insert_str(0, &repeat("&nbsp;").take(indent.saturating_sub(1))
.collect::<String>());
clause.insert_str(0, &"&nbsp;".repeat(indent.saturating_sub(1)));
if !end_newline {
clause.insert_str(0, "<br>");
}
Expand Down Expand Up @@ -409,13 +407,13 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
Some(&(ref fqp, shortty)) => {
(fqp, shortty, repeat("../").take(loc.len()).collect())
(fqp, shortty, "../".repeat(loc.len()))
}
None => {
let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
(fqp, shortty, match cache.extern_locations[&did.krate] {
(.., render::Remote(ref s)) => s.to_string(),
(.., render::Local) => repeat("../").take(loc.len()).collect(),
(.., render::Local) => "../".repeat(loc.len()),
(.., render::Unknown) => return None,
})
}
Expand Down Expand Up @@ -481,7 +479,7 @@ fn primitive_link(f: &mut fmt::Formatter,
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
let len = if len == 0 {0} else {len - 1};
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
repeat("../").take(len).collect::<String>(),
"../".repeat(len),
prim.to_url_str())?;
needs_termination = true;
}
Expand All @@ -492,7 +490,7 @@ fn primitive_link(f: &mut fmt::Formatter,
}
(ref cname, _, render::Local) => {
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
Some((cname, repeat("../").take(len).collect::<String>()))
Some((cname, "../".repeat(len)))
}
(.., render::Unknown) => None,
};
Expand Down Expand Up @@ -907,15 +905,15 @@ impl<'a> fmt::Display for Method<'a> {
format!("{}", decl.output)
};

let pad = repeat(" ").take(name_len).collect::<String>();
let pad = " ".repeat(name_len);
let plain = format!("{pad}({args}){arrow}",
pad = pad,
args = args_plain,
arrow = arrow_plain);

let output = if plain.len() > 80 {
let full_pad = format!("<br>{}", repeat("&nbsp;").take(indent + 4).collect::<String>());
let close_pad = format!("<br>{}", repeat("&nbsp;").take(indent).collect::<String>());
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
format!("({args}{close}){arrow}",
args = args.replace("<br>", &full_pad),
close = close_pad,
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use std::ffi::OsStr;
use std::fs::{self, File, OpenOptions};
use std::io::prelude::*;
use std::io::{self, BufWriter, BufReader};
use std::iter::repeat;
use std::mem;
use std::path::{PathBuf, Path, Component};
use std::str;
Expand Down Expand Up @@ -1712,7 +1711,7 @@ impl Context {
/// String representation of how to get back to the root path of the 'doc/'
/// folder in terms of a relative URL.
fn root_path(&self) -> String {
repeat("../").take(self.current.len()).collect::<String>()
"../".repeat(self.current.len())
}

/// Recurse in the directory structure and change the "root path" to make
Expand Down Expand Up @@ -2113,8 +2112,7 @@ impl<'a> fmt::Display for Item<'a> {
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
for (i, component) in cur.iter().enumerate().take(amt) {
write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
repeat("../").take(cur.len() - i - 1)
.collect::<String>(),
"../".repeat(cur.len() - i - 1),
component)?;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
extern crate rand;

use std::env::*;
use std::iter::repeat;
use std::ffi::{OsString, OsStr};

use rand::Rng;
Expand Down Expand Up @@ -72,7 +71,7 @@ fn test_var_big() {
#[cfg_attr(target_os = "emscripten", ignore)]
fn test_env_set_get_huge() {
let n = make_rand_name();
let s = repeat("x").take(10000).collect::<String>();
let s = "x".repeat(10000);
set_var(&n, &s);
eq(var_os(&n), Some(&s));
remove_var(&n);
Expand Down
Loading

0 comments on commit a5c2d0f

Please sign in to comment.