Skip to content

Map clone #22276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ mod tests {
#[test]
fn test_from_bools() {
let bools = vec![true, false, true, true];
let bitv: Bitv = bools.iter().map(|n| *n).collect();
let bitv: Bitv = bools.iter().cloned().collect();
assert_eq!(format!("{:?}", bitv), "1011");
}

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ impl<A: Ord> Ord for DList<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Clone> Clone for DList<A> {
fn clone(&self) -> DList<A> {
self.iter().map(|x| x.clone()).collect()
self.iter().cloned().collect()
}
}

Expand Down Expand Up @@ -1013,7 +1013,7 @@ mod tests {

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

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub trait IteratorExt: Iterator + Sized {
///
/// ```
/// let xs = [100, 200, 300];
/// let mut it = xs.iter().map(|x| *x).peekable();
/// let mut it = xs.iter().cloned().peekable();
/// assert_eq!(*it.peek().unwrap(), 100);
/// assert_eq!(it.next().unwrap(), 100);
/// assert_eq!(it.next().unwrap(), 200);
Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ fn test_random_access_inspect() {
fn test_random_access_map() {
let xs = [1, 2, 3, 4, 5];

let mut it = xs.iter().map(|x| *x);
let mut it = xs.iter().cloned();
assert_eq!(xs.len(), it.indexable());
for (i, elt) in xs.iter().enumerate() {
assert_eq!(Some(*elt), it.idx(i));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl CStore {

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> fmt::Debug for Matrix<'a> {
pretty_printed_matrix.iter().map(|row| row[col].len()).max().unwrap_or(0)
}).collect();

let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1;
let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1;
let br = repeat('+').take(total_width).collect::<String>();
try!(write!(f, "{}\n", br));
for row in pretty_printed_matrix {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val {
match lit.node {
ast::LitStr(ref s, _) => const_str((*s).clone()),
ast::LitBinary(ref data) => {
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
const_binary(Rc::new(data.iter().cloned().collect()))
}
ast::LitByte(n) => const_uint(n as u64),
ast::LitChar(n) => const_uint(n as u64),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session,

// Collect what we've got so far in the return vector.
let mut ret = (1..sess.cstore.next_crate_num()).map(|i| {
match formats.get(&i).map(|v| *v) {
match formats.get(&i).cloned() {
v @ Some(cstore::RequireDynamic) => v,
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {

fn rebuild(&self)
-> (ast::FnDecl, Option<ast::ExplicitSelf_>, ast::Generics) {
let mut expl_self_opt = self.expl_self_opt.map(|x| x.clone());
let mut expl_self_opt = self.expl_self_opt.cloned();
let mut inputs = self.fn_decl.inputs.clone();
let mut output = self.fn_decl.output.clone();
let mut ty_params = self.generics.ty_params.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
fn visit_item(&mut self, item: &ast::Item) {
match extract(&item.attrs) {
Some(value) => {
let item_index = self.item_refs.get(&value[]).map(|x| *x);
let item_index = self.item_refs.get(&value[]).cloned();

match item_index {
Some(item_index) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl RegionMaps {

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

#[allow(dead_code)] // used in middle::cfg
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti

generics.lifetimes.iter()
.filter(|l| referenced_idents.iter().any(|&i| i == l.lifetime.name))
.map(|l| (*l).clone())
.cloned()
.collect()
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
{
let cache = self.pick_candidate_cache();
let hashmap = cache.hashmap.borrow();
hashmap.get(&cache_fresh_trait_pred.0.trait_ref).map(|c| (*c).clone())
hashmap.get(&cache_fresh_trait_pred.0.trait_ref).cloned()
}

fn insert_candidate_cache(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4944,7 +4944,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
}

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

pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
reachable.push("rust_eh_personality_catch".to_string());

if codegen_units > 1 {
internalize_symbols(&shared_ccx, &reachable.iter().map(|x| x.clone()).collect());
internalize_symbols(&shared_ccx, &reachable.iter().cloned().collect());
}

let metadata_module = ModuleTranslation {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let trait_ref =
bcx.tcx().object_cast_map.borrow()
.get(&expr.id)
.map(|t| (*t).clone())
.cloned()
.unwrap();
let trait_ref = bcx.monomorphize(&trait_ref);
let datum = unpack_datum!(bcx, trans(bcx, &**val));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
abi: abi::Abi)
-> Vec<Ty<'tcx>> {
if abi != abi::RustCall {
return inputs.iter().map(|x| (*x).clone()).collect()
return inputs.iter().cloned().collect()
}

if inputs.len() == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3223,7 +3223,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
for field in ast_fields {
let mut expected_field_type = tcx.types.err;

let pair = class_field_map.get(&field.ident.node.name).map(|x| *x);
let pair = class_field_map.get(&field.ident.node.name).cloned();
match pair {
None => {
fcx.type_error_message(
Expand Down Expand Up @@ -3871,7 +3871,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
}
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
// Resolve the path.
let def = tcx.def_map.borrow().get(&id).map(|i| *i);
let def = tcx.def_map.borrow().get(&id).cloned();
let struct_id = match def {
Some(def::DefVariant(enum_id, variant_id, true)) => {
check_struct_enum_variant(fcx, id, expr.span, enum_id,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
let mut a: Vec<clean::Attribute> = i.attrs.iter().filter(|&a| match a {
&clean::NameValue(ref x, _) if "doc" == *x => false,
_ => true
}).map(|x| x.clone()).collect();
}).cloned().collect();
if docstr.len() > 0 {
a.push(clean::NameValue("doc".to_string(), docstr));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
name: name,
items: items.clone(),
generics: gen.clone(),
bounds: b.iter().map(|x| (*x).clone()).collect(),
bounds: b.iter().cloned().collect(),
id: item.id,
attrs: item.attrs.clone(),
whence: item.span,
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ mod tests {
#[cfg(unix)]
fn join_paths_unix() {
fn test_eq(input: &[&str], output: &str) -> bool {
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
&*join_paths(input.iter().cloned()).unwrap() ==
OsStr::from_str(output)
}

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

#[test]
#[cfg(windows)]
fn join_paths_windows() {
fn test_eq(input: &[&str], output: &str) -> bool {
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
&*join_paths(input.iter().cloned()).unwrap() ==
OsStr::from_str(output)
}

Expand All @@ -945,6 +945,6 @@ mod tests {
r";c:\windows;;;c:\;"));
assert!(test_eq(&[r"c:\te;st", r"c:\"],
r#""c:\te;st";c:\"#));
assert!(join_paths([r#"c:\te"st"#].iter().map(|s| *s)).is_err());
assert!(join_paths([r#"c:\te"st"#].iter().cloned()).is_err());
}
}
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ unsafe fn run_dtors() {
let ret = if DTORS.is_null() {
Vec::new()
} else {
(*DTORS).iter().map(|s| *s).collect()
(*DTORS).iter().cloned().collect()
};
DTOR_LOCK.unlock();
ret
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'ast> Map<'ast> {
}

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

pub fn krate(&self) -> &'ast Crate {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl<'a> ExtCtxt<'a> {
pub fn mod_path(&self) -> Vec<ast::Ident> {
let mut v = Vec::new();
v.push(token::str_to_ident(&self.ecfg.crate_name[]));
v.extend(self.mod_path.iter().map(|a| *a));
v.extend(self.mod_path.iter().cloned());
return v;
}
pub fn bt_push(&mut self, ei: ExpnInfo) {
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl<'a> TraitDef<'a> {
"allow" | "warn" | "deny" | "forbid" => true,
_ => false,
}
}).map(|a| a.clone()));
}).cloned());
push(P(ast::Item {
attrs: attrs,
..(*newitem).clone()
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<'a> TraitDef<'a> {
let mut ty_params = ty_params.into_vec();

// Copy the lifetimes
lifetimes.extend(generics.lifetimes.iter().map(|l| (*l).clone()));
lifetimes.extend(generics.lifetimes.iter().cloned());

// Create the type parameters.
ty_params.extend(generics.ty_params.iter().map(|ty_param| {
Expand Down Expand Up @@ -445,14 +445,14 @@ impl<'a> TraitDef<'a> {
span: self.span,
bound_lifetimes: wb.bound_lifetimes.clone(),
bounded_ty: wb.bounded_ty.clone(),
bounds: OwnedSlice::from_vec(wb.bounds.iter().map(|b| b.clone()).collect())
bounds: OwnedSlice::from_vec(wb.bounds.iter().cloned().collect())
})
}
ast::WherePredicate::RegionPredicate(ref rb) => {
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
span: self.span,
lifetime: rb.lifetime,
bounds: rb.bounds.iter().map(|b| b.clone()).collect()
bounds: rb.bounds.iter().cloned().collect()
})
}
ast::WherePredicate::EqPredicate(ref we) => {
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'a> TraitDef<'a> {
let opt_trait_ref = Some(trait_ref);
let ident = ast_util::impl_pretty_name(&opt_trait_ref, &*self_type);
let mut a = vec![attr];
a.extend(self.attributes.iter().map(|a| a.clone()));
a.extend(self.attributes.iter().cloned());
cx.item(
self.span,
ident,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
return DummyResult::expr(sp);
}
Ok(bytes) => {
let bytes = bytes.iter().map(|x| *x).collect();
let bytes = bytes.iter().cloned().collect();
base::MacExpr::new(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ pub fn parse(sess: &ParseSess,
ms: &[TokenTree])
-> ParseResult {
let mut cur_eis = Vec::new();
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter()
.map(|x| (*x).clone())
.collect()),
cur_eis.push(initial_matcher_pos(Rc::new(ms.iter().cloned().collect()),
None,
rdr.peek().sp.lo));

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
None,
None,
arg.iter()
.map(|x| (*x).clone())
.cloned()
.collect(),
true);
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, lhs_tt) {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
while j > i && lines[j - 1].trim().is_empty() {
j -= 1;
}
return lines[i..j].iter().map(|x| (*x).clone()).collect();
return lines[i..j].iter().cloned().collect();
}

/// remove a "[ \t]*\*" block from each line, if possible
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ macro_rules! maybe_whole {
fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
-> Vec<Attribute> {
match rhs {
Some(ref attrs) => lhs.extend(attrs.iter().map(|a| a.clone())),
Some(ref attrs) => lhs.extend(attrs.iter().cloned()),
None => {}
}
lhs
Expand Down Expand Up @@ -467,7 +467,7 @@ impl<'a> Parser<'a> {
debug!("commit_expr {:?}", e);
if let ExprPath(..) = e.node {
// might be unit-struct construction; check for recoverableinput error.
let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
let mut expected = edible.iter().cloned().collect::<Vec<_>>();
expected.push_all(inedible);
self.check_for_erroneous_unit_struct_expecting(&expected[]);
}
Expand All @@ -485,7 +485,7 @@ impl<'a> Parser<'a> {
if self.last_token
.as_ref()
.map_or(false, |t| t.is_ident() || t.is_path()) {
let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
let mut expected = edible.iter().cloned().collect::<Vec<_>>();
expected.push_all(&inedible[]);
self.check_for_erroneous_unit_struct_expecting(
&expected[]);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl<'a> State<'a> {
try!(self.word_nbsp("trait"));
try!(self.print_ident(item.ident));
try!(self.print_generics(generics));
let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect();
let bounds: Vec<_> = bounds.iter().cloned().collect();
let mut real_bounds = Vec::with_capacity(bounds.len());
for b in bounds {
if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b {
Expand Down
Loading