Skip to content

Commit dc3b857

Browse files
committed
Fix rebase
1 parent 727fb63 commit dc3b857

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

src/librustc_front/fold.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir;
1919
use syntax::codemap::{respan, Span, Spanned};
2020
use syntax::ptr::P;
2121
use syntax::parse::token;
22-
use syntax::util::MoveMap;
22+
use syntax::util::{MoveMap, MoveFlatMap};
2323

2424
pub trait Folder : Sized {
2525
// Any additions to this trait should happen in form
@@ -477,7 +477,7 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
477477
pat: fld.fold_pat(pat),
478478
init: init.map(|e| fld.fold_expr(e)),
479479
span: fld.new_span(span),
480-
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, fld)),
480+
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), fld).into()),
481481
}
482482
})
483483
}
@@ -1132,7 +1132,7 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
11321132
}
11331133
},
11341134
span: folder.new_span(span),
1135-
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, folder)),
1135+
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), folder).into()),
11361136
}
11371137
}
11381138

src/librustc_front/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
12981298
let pat_under = pat_wild(lctx, e.span);
12991299
let else_expr =
13001300
else_opt.unwrap_or_else(
1301-
|| expr_tuple(lctx, e.span, hir_vec![]), None);
1301+
|| expr_tuple(lctx, e.span, hir_vec![], None));
13021302
arm(hir_vec![pat_under], else_expr)
13031303
};
13041304

@@ -1460,7 +1460,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
14601460
};
14611461

14621462
let into_iter = expr_path(lctx, into_iter_path, None);
1463-
expr_call(lctx, e.span, into_iter, hir_vec![head])
1463+
expr_call(lctx, e.span, into_iter, hir_vec![head], None)
14641464
};
14651465

14661466
let match_expr = expr_match(lctx,

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ use ext::base::*;
2424
use feature_gate::{self, Features, GatedCfgAttr};
2525
use fold;
2626
use fold::*;
27-
use util::move_map::MoveMap;
2827
use parse;
2928
use parse::token::{fresh_mark, fresh_name, intern};
3029
use ptr::P;
3130
use util::small_vector::SmallVector;
3231
use visit;
3332
use visit::Visitor;
3433
use std_inject;
34+
use util::MoveMap;
3535

3636
use std::collections::HashSet;
3737

src/libsyntax/fold.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use ast_util;
2525
use codemap::{respan, Span, Spanned};
2626
use parse::token;
2727
use ptr::P;
28-
// Reexported for backward compatibility, it was defined here before
29-
pub use util::MoveMap;
28+
use util::{MoveMap, MoveFlatMap};
3029
use util::small_vector::SmallVector;
3130

3231
use std::rc::Rc;

src/libsyntax/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ macro_rules! panictry {
6262
}
6363

6464
pub mod util {
65-
pub use self::move_map::MoveMap;
65+
pub use self::move_map::{MoveMap, MoveFlatMap};
6666

6767
pub mod interner;
6868
pub mod lev_distance;
@@ -72,7 +72,6 @@ pub mod util {
7272
#[cfg(test)]
7373
pub mod parser_testing;
7474
pub mod small_vector;
75-
pub mod move_map;
7675
}
7776

7877
pub mod diagnostics {

src/libsyntax/util/move_map.rs

+30-11
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,38 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use owned_slice::OwnedSlice;
12-
1311
use std::ptr;
1412

15-
pub trait MoveMap<T>: Sized {
16-
fn move_map<F>(self, mut f: F) -> Self where F: FnMut(T) -> T {
17-
self.move_flat_map(|e| Some(f(e)))
18-
}
13+
pub trait MoveMap {
14+
type Item;
15+
fn move_map<F>(self, f: F) -> Self
16+
where F: FnMut(Self::Item) -> Self::Item;
17+
}
1918

19+
pub trait MoveFlatMap {
20+
type Item;
2021
fn move_flat_map<F, I>(self, f: F) -> Self
21-
where F: FnMut(T) -> I,
22-
I: IntoIterator<Item=T>;
22+
where F: FnMut(Self::Item) -> I,
23+
I: IntoIterator<Item = Self::Item>;
24+
}
25+
26+
impl<Container, T> MoveMap for Container
27+
where for<'a> &'a mut Container: IntoIterator<Item = &'a mut T>
28+
{
29+
type Item = T;
30+
fn move_map<F>(mut self, mut f: F) -> Container where F: FnMut(T) -> T {
31+
for p in &mut self {
32+
unsafe {
33+
// FIXME(#5016) this shouldn't need to zero to be safe.
34+
ptr::write(p, f(ptr::read_and_drop(p)));
35+
}
36+
}
37+
self
38+
}
2339
}
2440

25-
impl<T> MoveMap<T> for Vec<T> {
41+
impl<T> MoveFlatMap for Vec<T> {
42+
type Item = T;
2643
fn move_flat_map<F, I>(mut self, mut f: F) -> Self
2744
where F: FnMut(T) -> I,
2845
I: IntoIterator<Item=T>
@@ -69,11 +86,13 @@ impl<T> MoveMap<T> for Vec<T> {
6986
}
7087
}
7188

72-
impl<T> MoveMap<T> for OwnedSlice<T> {
89+
impl<T> MoveFlatMap for ::ptr::P<[T]> {
90+
type Item = T;
7391
fn move_flat_map<F, I>(self, f: F) -> Self
7492
where F: FnMut(T) -> I,
7593
I: IntoIterator<Item=T>
7694
{
77-
OwnedSlice::from_vec(self.into_vec().move_flat_map(f))
95+
let v: Vec<_> = self.into();
96+
v.move_flat_map(f).into()
7897
}
7998
}

0 commit comments

Comments
 (0)