Skip to content

Commit d79fbba

Browse files
committed
auto merge of #13203 : Kimundi/rust/de-map-vec3, r=cmr
They required unnecessary temporaries, are replaced with iterators, and would conflict with a possible future `Iterable` trait.
2 parents 86890b9 + c356e3b commit d79fbba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+278
-325
lines changed

src/doc/tutorial.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,10 @@ access local variables in the enclosing scope.
17641764
17651765
~~~~
17661766
let mut max = 0;
1767-
[1, 2, 3].map(|x| if *x > max { max = *x });
1767+
let f = |x: int| if x > max { max = x };
1768+
for x in [1, 2, 3].iter() {
1769+
f(*x);
1770+
}
17681771
~~~~
17691772
17701773
Stack closures are very efficient because their environment is

src/libnative/io/process.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: proc:(**libc::c_char) -> T) -> T
597597
// Next, convert each of the byte strings into a pointer. This is
598598
// technically unsafe as the caller could leak these pointers out of our
599599
// scope.
600-
let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf));
600+
let mut ptrs: Vec<_> = tmps.iter().map(|tmp| tmp.with_ref(|buf| buf)).collect();
601601

602602
// Finally, make sure we add a null pointer.
603603
ptrs.push(ptr::null());
@@ -622,7 +622,9 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: proc:(*c_void) -> T) -> T {
622622
}
623623

624624
// Once again, this is unsafe.
625-
let mut ptrs = tmps.map(|tmp| tmp.with_ref(|buf| buf));
625+
let mut ptrs: Vec<*libc::c_char> = tmps.iter()
626+
.map(|tmp| tmp.with_ref(|buf| buf))
627+
.collect();
626628
ptrs.push(ptr::null());
627629

628630
cb(ptrs.as_ptr() as *c_void)

src/librustc/back/lto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
6969
}
7070

7171
// Internalize everything but the reachable symbols of the current module
72-
let cstrs = reachable.map(|s| s.to_c_str());
73-
let arr = cstrs.map(|c| c.with_ref(|p| p));
72+
let cstrs: Vec<::std::c_str::CString> = reachable.iter().map(|s| s.to_c_str()).collect();
73+
let arr: Vec<*i8> = cstrs.iter().map(|c| c.with_ref(|p| p)).collect();
7474
let ptr = arr.as_ptr();
7575
unsafe {
7676
llvm::LLVMRustRunRestrictionPass(llmod, ptr as **libc::c_char,

src/librustc/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
943943
NoDebugInfo
944944
};
945945

946-
let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
946+
let addl_lib_search_paths = matches.opt_strs("L").iter().map(|s| {
947947
Path::new(s.as_slice())
948-
}).move_iter().collect();
948+
}).collect();
949949

950950
let cfg = parse_cfgspecs(matches.opt_strs("cfg").move_iter().collect());
951951
let test = matches.opt_present("test");

src/librustc/lib/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ impl TypeNames {
18611861
}
18621862

18631863
pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1864-
let strs = tys.map(|t| self.type_to_str(*t));
1864+
let strs: Vec<~str> = tys.iter().map(|t| self.type_to_str(*t)).collect();
18651865
format!("[{}]", strs.connect(","))
18661866
}
18671867

src/librustc/metadata/filesearch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ pub fn get_rust_path() -> Option<~str> {
200200
pub fn rust_path() -> Vec<Path> {
201201
let mut env_rust_path: Vec<Path> = match get_rust_path() {
202202
Some(env_path) => {
203-
let env_path_components: Vec<&str> =
204-
env_path.split_str(PATH_ENTRY_SEPARATOR).collect();
205-
env_path_components.map(|&s| Path::new(s))
203+
let env_path_components =
204+
env_path.split_str(PATH_ENTRY_SEPARATOR);
205+
env_path_components.map(|s| Path::new(s)).collect()
206206
}
207207
None => Vec::new()
208208
};

src/librustc/middle/check_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn raw_pat(p: @Pat) -> @Pat {
163163

164164
fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
165165
assert!((!pats.is_empty()));
166-
let ext = match is_useful(cx, &pats.map(|p| vec!(*p)), [wild()]) {
166+
let ext = match is_useful(cx, &pats.iter().map(|p| vec!(*p)).collect(), [wild()]) {
167167
not_useful => {
168168
// This is good, wildcard pattern isn't reachable
169169
return;
@@ -692,12 +692,12 @@ fn specialize(cx: &MatchCheckCtxt,
692692
DefVariant(_, variant_id, _) => {
693693
if variant(variant_id) == *ctor_id {
694694
let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id);
695-
let args = struct_fields.map(|sf| {
695+
let args = struct_fields.iter().map(|sf| {
696696
match pattern_fields.iter().find(|f| f.ident.name == sf.name) {
697697
Some(f) => f.pat,
698698
_ => wild()
699699
}
700-
});
700+
}).collect();
701701
Some(vec::append(args, r.tail()))
702702
} else {
703703
None

src/librustc/middle/resolve.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4707,18 +4707,20 @@ impl<'a> Resolver<'a> {
47074707
path: &Path,
47084708
namespace: Namespace)
47094709
-> Option<(Def, LastPrivate)> {
4710-
let module_path_idents = path.segments.init().map(|ps| ps.identifier);
4710+
let module_path_idents = path.segments.init().iter()
4711+
.map(|ps| ps.identifier)
4712+
.collect::<Vec<_>>();
47114713

47124714
let containing_module;
47134715
let last_private;
47144716
match self.resolve_module_path(self.current_module,
4715-
module_path_idents,
4717+
module_path_idents.as_slice(),
47164718
UseLexicalScope,
47174719
path.span,
47184720
PathSearch) {
47194721
Failed => {
47204722
let msg = format!("use of undeclared module `{}`",
4721-
self.idents_to_str(module_path_idents));
4723+
self.idents_to_str(module_path_idents.as_slice()));
47224724
self.resolve_error(path.span, msg);
47234725
return None;
47244726
}
@@ -4772,21 +4774,23 @@ impl<'a> Resolver<'a> {
47724774
path: &Path,
47734775
namespace: Namespace)
47744776
-> Option<(Def, LastPrivate)> {
4775-
let module_path_idents = path.segments.init().map(|ps| ps.identifier);
4777+
let module_path_idents = path.segments.init().iter()
4778+
.map(|ps| ps.identifier)
4779+
.collect::<Vec<_>>();
47764780

47774781
let root_module = self.graph_root.get_module();
47784782

47794783
let containing_module;
47804784
let last_private;
47814785
match self.resolve_module_path_from_root(root_module,
4782-
module_path_idents,
4786+
module_path_idents.as_slice(),
47834787
0,
47844788
path.span,
47854789
PathSearch,
47864790
LastMod(AllPublic)) {
47874791
Failed => {
47884792
let msg = format!("use of undeclared module `::{}`",
4789-
self.idents_to_str(module_path_idents));
4793+
self.idents_to_str(module_path_idents.as_slice()));
47904794
self.resolve_error(path.span, msg);
47914795
return None;
47924796
}

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'a> LifetimeContext<'a> {
216216
referenced_idents={:?} \
217217
early_count={}",
218218
n,
219-
referenced_idents.map(lifetime_show),
219+
referenced_idents.iter().map(lifetime_show).collect::<Vec<token::InternedString>>(),
220220
early_count);
221221
if referenced_idents.is_empty() {
222222
let scope1 = LateScope(n, &generics.lifetimes, scope);

src/librustc/middle/subst.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<T:Subst> Subst for Vec<T> {
134134
fn subst_spanned(&self, tcx: &ty::ctxt,
135135
substs: &ty::substs,
136136
span: Option<Span>) -> Vec<T> {
137-
self.map(|t| t.subst_spanned(tcx, substs, span))
137+
self.iter().map(|t| t.subst_spanned(tcx, substs, span)).collect()
138138
}
139139
}
140140
impl<T:Subst> Subst for Rc<T> {
@@ -189,7 +189,7 @@ impl Subst for ty::substs {
189189
ty::substs {
190190
regions: self.regions.subst_spanned(tcx, substs, span),
191191
self_ty: self.self_ty.map(|typ| typ.subst_spanned(tcx, substs, span)),
192-
tps: self.tps.map(|typ| typ.subst_spanned(tcx, substs, span))
192+
tps: self.tps.iter().map(|typ| typ.subst_spanned(tcx, substs, span)).collect()
193193
}
194194
}
195195
}

0 commit comments

Comments
 (0)