Skip to content

Commit af595a3

Browse files
committed
Rollup merge of #22276 - ruud-v-a:map-clone, r=nikomatsakis
This resolves #22243 for the single-letter variables that I could grep. Some occurences could not be replaced.
2 parents e354763 + c9ad0d1 commit af595a3

File tree

33 files changed

+46
-48
lines changed

33 files changed

+46
-48
lines changed

src/libcollections/bit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ mod tests {
22822282
#[test]
22832283
fn test_from_bools() {
22842284
let bools = vec![true, false, true, true];
2285-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2285+
let bitv: Bitv = bools.iter().cloned().collect();
22862286
assert_eq!(format!("{:?}", bitv), "1011");
22872287
}
22882288

@@ -2295,12 +2295,12 @@ mod tests {
22952295
#[test]
22962296
fn test_bitv_iterator() {
22972297
let bools = vec![true, false, true, true];
2298-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2298+
let bitv: Bitv = bools.iter().cloned().collect();
22992299

23002300
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools);
23012301

23022302
let long: Vec<_> = (0i32..10000).map(|i| i % 2 == 0).collect();
2303-
let bitv: Bitv = long.iter().map(|n| *n).collect();
2303+
let bitv: Bitv = long.iter().cloned().collect();
23042304
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
23052305
}
23062306

src/libcollections/dlist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ impl<A: Ord> Ord for DList<A> {
895895
#[stable(feature = "rust1", since = "1.0.0")]
896896
impl<A: Clone> Clone for DList<A> {
897897
fn clone(&self) -> DList<A> {
898-
self.iter().map(|x| x.clone()).collect()
898+
self.iter().cloned().collect()
899899
}
900900
}
901901

@@ -1013,7 +1013,7 @@ mod tests {
10131013

10141014
#[cfg(test)]
10151015
fn list_from<T: Clone>(v: &[T]) -> DList<T> {
1016-
v.iter().map(|x| (*x).clone()).collect()
1016+
v.iter().cloned().collect()
10171017
}
10181018

10191019
#[test]

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub trait IteratorExt: Iterator + Sized {
325325
///
326326
/// ```
327327
/// let xs = [100, 200, 300];
328-
/// let mut it = xs.iter().map(|x| *x).peekable();
328+
/// let mut it = xs.iter().cloned().peekable();
329329
/// assert_eq!(*it.peek().unwrap(), 100);
330330
/// assert_eq!(it.next().unwrap(), 100);
331331
/// assert_eq!(it.next().unwrap(), 200);

src/libcoretest/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn test_random_access_inspect() {
713713
fn test_random_access_map() {
714714
let xs = [1, 2, 3, 4, 5];
715715

716-
let mut it = xs.iter().map(|x| *x);
716+
let mut it = xs.iter().cloned();
717717
assert_eq!(xs.len(), it.indexable());
718718
for (i, elt) in xs.iter().enumerate() {
719719
assert_eq!(Some(*elt), it.idx(i));

src/librustc/metadata/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl CStore {
218218

219219
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
220220
-> Option<ast::CrateNum> {
221-
self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x)
221+
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
222222
}
223223
}
224224

src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> fmt::Debug for Matrix<'a> {
7575
pretty_printed_matrix.iter().map(|row| row[col].len()).max().unwrap_or(0)
7676
}).collect();
7777

78-
let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1;
78+
let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1;
7979
let br = repeat('+').take(total_width).collect::<String>();
8080
try!(write!(f, "{}\n", br));
8181
for row in pretty_printed_matrix {

src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val {
600600
match lit.node {
601601
ast::LitStr(ref s, _) => const_str((*s).clone()),
602602
ast::LitBinary(ref data) => {
603-
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
603+
const_binary(Rc::new(data.iter().cloned().collect()))
604604
}
605605
ast::LitByte(n) => const_uint(n as u64),
606606
ast::LitChar(n) => const_uint(n as u64),

src/librustc/middle/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session,
158158

159159
// Collect what we've got so far in the return vector.
160160
let mut ret = (1..sess.cstore.next_crate_num()).map(|i| {
161-
match formats.get(&i).map(|v| *v) {
161+
match formats.get(&i).cloned() {
162162
v @ Some(cstore::RequireDynamic) => v,
163163
_ => None,
164164
}

src/librustc/middle/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
924924

925925
fn rebuild(&self)
926926
-> (ast::FnDecl, Option<ast::ExplicitSelf_>, ast::Generics) {
927-
let mut expl_self_opt = self.expl_self_opt.map(|x| x.clone());
927+
let mut expl_self_opt = self.expl_self_opt.cloned();
928928
let mut inputs = self.fn_decl.inputs.clone();
929929
let mut output = self.fn_decl.output.clone();
930930
let mut ty_params = self.generics.ty_params.clone();

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
149149
fn visit_item(&mut self, item: &ast::Item) {
150150
match extract(&item.attrs) {
151151
Some(value) => {
152-
let item_index = self.item_refs.get(&value[]).map(|x| *x);
152+
let item_index = self.item_refs.get(&value[]).cloned();
153153

154154
match item_index {
155155
Some(item_index) => {

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl RegionMaps {
407407

408408
pub fn opt_encl_scope(&self, id: CodeExtent) -> Option<CodeExtent> {
409409
//! Returns the narrowest scope that encloses `id`, if any.
410-
self.scope_map.borrow().get(&id).map(|x| *x)
410+
self.scope_map.borrow().get(&id).cloned()
411411
}
412412

413413
#[allow(dead_code)] // used in middle::cfg

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
562562

563563
generics.lifetimes.iter()
564564
.filter(|l| referenced_idents.iter().any(|&i| i == l.lifetime.name))
565-
.map(|l| (*l).clone())
565+
.cloned()
566566
.collect()
567567
}
568568

src/librustc/middle/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
738738
{
739739
let cache = self.pick_candidate_cache();
740740
let hashmap = cache.hashmap.borrow();
741-
hashmap.get(&cache_fresh_trait_pred.0.trait_ref).map(|c| (*c).clone())
741+
hashmap.get(&cache_fresh_trait_pred.0.trait_ref).cloned()
742742
}
743743

744744
fn insert_candidate_cache(&mut self,

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
49444944
}
49454945

49464946
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
4947-
cx.provided_method_sources.borrow().get(&id).map(|x| *x)
4947+
cx.provided_method_sources.borrow().get(&id).cloned()
49484948
}
49494949

49504950
pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)

src/librustc_trans/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
32283228
reachable.push("rust_eh_personality_catch".to_string());
32293229

32303230
if codegen_units > 1 {
3231-
internalize_symbols(&shared_ccx, &reachable.iter().map(|x| x.clone()).collect());
3231+
internalize_symbols(&shared_ccx, &reachable.iter().cloned().collect());
32323232
}
32333233

32343234
let metadata_module = ModuleTranslation {

src/librustc_trans/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11531153
let trait_ref =
11541154
bcx.tcx().object_cast_map.borrow()
11551155
.get(&expr.id)
1156-
.map(|t| (*t).clone())
1156+
.cloned()
11571157
.unwrap();
11581158
let trait_ref = bcx.monomorphize(&trait_ref);
11591159
let datum = unpack_datum!(bcx, trans(bcx, &**val));

src/librustc_trans/trans/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
6767
abi: abi::Abi)
6868
-> Vec<Ty<'tcx>> {
6969
if abi != abi::RustCall {
70-
return inputs.iter().map(|x| (*x).clone()).collect()
70+
return inputs.iter().cloned().collect()
7171
}
7272

7373
if inputs.len() == 0 {

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
32233223
for field in ast_fields {
32243224
let mut expected_field_type = tcx.types.err;
32253225

3226-
let pair = class_field_map.get(&field.ident.node.name).map(|x| *x);
3226+
let pair = class_field_map.get(&field.ident.node.name).cloned();
32273227
match pair {
32283228
None => {
32293229
fcx.type_error_message(
@@ -3871,7 +3871,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
38713871
}
38723872
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
38733873
// Resolve the path.
3874-
let def = tcx.def_map.borrow().get(&id).map(|i| *i);
3874+
let def = tcx.def_map.borrow().get(&id).cloned();
38753875
let struct_id = match def {
38763876
Some(def::DefVariant(enum_id, variant_id, true)) => {
38773877
check_struct_enum_variant(fcx, id, expr.span, enum_id,

src/librustdoc/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
293293
let mut a: Vec<clean::Attribute> = i.attrs.iter().filter(|&a| match a {
294294
&clean::NameValue(ref x, _) if "doc" == *x => false,
295295
_ => true
296-
}).map(|x| x.clone()).collect();
296+
}).cloned().collect();
297297
if docstr.len() > 0 {
298298
a.push(clean::NameValue("doc".to_string(), docstr));
299299
}

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
333333
name: name,
334334
items: items.clone(),
335335
generics: gen.clone(),
336-
bounds: b.iter().map(|x| (*x).clone()).collect(),
336+
bounds: b.iter().cloned().collect(),
337337
id: item.id,
338338
attrs: item.attrs.clone(),
339339
whence: item.span,

src/libstd/env.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ mod tests {
918918
#[cfg(unix)]
919919
fn join_paths_unix() {
920920
fn test_eq(input: &[&str], output: &str) -> bool {
921-
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
921+
&*join_paths(input.iter().cloned()).unwrap() ==
922922
OsStr::from_str(output)
923923
}
924924

@@ -927,14 +927,14 @@ mod tests {
927927
"/bin:/usr/bin:/usr/local/bin"));
928928
assert!(test_eq(&["", "/bin", "", "", "/usr/bin", ""],
929929
":/bin:::/usr/bin:"));
930-
assert!(join_paths(["/te:st"].iter().map(|s| *s)).is_err());
930+
assert!(join_paths(["/te:st"].iter().cloned()).is_err());
931931
}
932932

933933
#[test]
934934
#[cfg(windows)]
935935
fn join_paths_windows() {
936936
fn test_eq(input: &[&str], output: &str) -> bool {
937-
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
937+
&*join_paths(input.iter().cloned()).unwrap() ==
938938
OsStr::from_str(output)
939939
}
940940

@@ -945,6 +945,6 @@ mod tests {
945945
r";c:\windows;;;c:\;"));
946946
assert!(test_eq(&[r"c:\te;st", r"c:\"],
947947
r#""c:\te;st";c:\"#));
948-
assert!(join_paths([r#"c:\te"st"#].iter().map(|s| *s)).is_err());
948+
assert!(join_paths([r#"c:\te"st"#].iter().cloned()).is_err());
949949
}
950950
}

src/libstd/sys/windows/thread_local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ unsafe fn run_dtors() {
244244
let ret = if DTORS.is_null() {
245245
Vec::new()
246246
} else {
247-
(*DTORS).iter().map(|s| *s).collect()
247+
(*DTORS).iter().cloned().collect()
248248
};
249249
DTOR_LOCK.unlock();
250250
ret

src/libsyntax/ast_map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'ast> Map<'ast> {
251251
}
252252

253253
fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
254-
self.map.borrow().get(id as usize).map(|e| *e)
254+
self.map.borrow().get(id as usize).cloned()
255255
}
256256

257257
pub fn krate(&self) -> &'ast Crate {

src/libsyntax/ext/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl<'a> ExtCtxt<'a> {
639639
pub fn mod_path(&self) -> Vec<ast::Ident> {
640640
let mut v = Vec::new();
641641
v.push(token::str_to_ident(&self.ecfg.crate_name[]));
642-
v.extend(self.mod_path.iter().map(|a| *a));
642+
v.extend(self.mod_path.iter().cloned());
643643
return v;
644644
}
645645
pub fn bt_push(&mut self, ei: ExpnInfo) {

src/libsyntax/ext/deriving/generic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a> TraitDef<'a> {
367367
"allow" | "warn" | "deny" | "forbid" => true,
368368
_ => false,
369369
}
370-
}).map(|a| a.clone()));
370+
}).cloned());
371371
push(P(ast::Item {
372372
attrs: attrs,
373373
..(*newitem).clone()
@@ -410,7 +410,7 @@ impl<'a> TraitDef<'a> {
410410
let mut ty_params = ty_params.into_vec();
411411

412412
// Copy the lifetimes
413-
lifetimes.extend(generics.lifetimes.iter().map(|l| (*l).clone()));
413+
lifetimes.extend(generics.lifetimes.iter().cloned());
414414

415415
// Create the type parameters.
416416
ty_params.extend(generics.ty_params.iter().map(|ty_param| {
@@ -445,14 +445,14 @@ impl<'a> TraitDef<'a> {
445445
span: self.span,
446446
bound_lifetimes: wb.bound_lifetimes.clone(),
447447
bounded_ty: wb.bounded_ty.clone(),
448-
bounds: OwnedSlice::from_vec(wb.bounds.iter().map(|b| b.clone()).collect())
448+
bounds: OwnedSlice::from_vec(wb.bounds.iter().cloned().collect())
449449
})
450450
}
451451
ast::WherePredicate::RegionPredicate(ref rb) => {
452452
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
453453
span: self.span,
454454
lifetime: rb.lifetime,
455-
bounds: rb.bounds.iter().map(|b| b.clone()).collect()
455+
bounds: rb.bounds.iter().cloned().collect()
456456
})
457457
}
458458
ast::WherePredicate::EqPredicate(ref we) => {
@@ -500,7 +500,7 @@ impl<'a> TraitDef<'a> {
500500
let opt_trait_ref = Some(trait_ref);
501501
let ident = ast_util::impl_pretty_name(&opt_trait_ref, &*self_type);
502502
let mut a = vec![attr];
503-
a.extend(self.attributes.iter().map(|a| a.clone()));
503+
a.extend(self.attributes.iter().cloned());
504504
cx.item(
505505
self.span,
506506
ident,

src/libsyntax/ext/source_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
179179
return DummyResult::expr(sp);
180180
}
181181
Ok(bytes) => {
182-
let bytes = bytes.iter().map(|x| *x).collect();
182+
let bytes = bytes.iter().cloned().collect();
183183
base::MacExpr::new(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
184184
}
185185
}

src/libsyntax/ext/tt/macro_parser.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ pub fn parse(sess: &ParseSess,
282282
ms: &[TokenTree])
283283
-> ParseResult {
284284
let mut cur_eis = Vec::new();
285-
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter()
286-
.map(|x| (*x).clone())
287-
.collect()),
285+
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter().cloned().collect()),
288286
None,
289287
rdr.peek().sp.lo));
290288

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
160160
None,
161161
None,
162162
arg.iter()
163-
.map(|x| (*x).clone())
163+
.cloned()
164164
.collect(),
165165
true);
166166
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, lhs_tt) {

src/libsyntax/parse/lexer/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
8282
while j > i && lines[j - 1].trim().is_empty() {
8383
j -= 1;
8484
}
85-
return lines[i..j].iter().map(|x| (*x).clone()).collect();
85+
return lines[i..j].iter().cloned().collect();
8686
}
8787

8888
/// remove a "[ \t]*\*" block from each line, if possible

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ macro_rules! maybe_whole {
241241
fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
242242
-> Vec<Attribute> {
243243
match rhs {
244-
Some(ref attrs) => lhs.extend(attrs.iter().map(|a| a.clone())),
244+
Some(ref attrs) => lhs.extend(attrs.iter().cloned()),
245245
None => {}
246246
}
247247
lhs
@@ -467,7 +467,7 @@ impl<'a> Parser<'a> {
467467
debug!("commit_expr {:?}", e);
468468
if let ExprPath(..) = e.node {
469469
// might be unit-struct construction; check for recoverableinput error.
470-
let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
470+
let mut expected = edible.iter().cloned().collect::<Vec<_>>();
471471
expected.push_all(inedible);
472472
self.check_for_erroneous_unit_struct_expecting(&expected[]);
473473
}
@@ -485,7 +485,7 @@ impl<'a> Parser<'a> {
485485
if self.last_token
486486
.as_ref()
487487
.map_or(false, |t| t.is_ident() || t.is_path()) {
488-
let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
488+
let mut expected = edible.iter().cloned().collect::<Vec<_>>();
489489
expected.push_all(&inedible[]);
490490
self.check_for_erroneous_unit_struct_expecting(
491491
&expected[]);

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl<'a> State<'a> {
983983
try!(self.word_nbsp("trait"));
984984
try!(self.print_ident(item.ident));
985985
try!(self.print_generics(generics));
986-
let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect();
986+
let bounds: Vec<_> = bounds.iter().cloned().collect();
987987
let mut real_bounds = Vec::with_capacity(bounds.len());
988988
for b in bounds {
989989
if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b {

0 commit comments

Comments
 (0)