Skip to content

Commit db61fc7

Browse files
committed
Add compatibility methods for OwnedSlice + use blanket impl for MoveMap
+ fix rustdoc
1 parent 6ba2602 commit db61fc7

File tree

5 files changed

+99
-65
lines changed

5 files changed

+99
-65
lines changed

src/librustdoc/clean/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ impl PrimitiveType {
15591559
impl Clean<Type> for hir::Ty {
15601560
fn clean(&self, cx: &DocContext) -> Type {
15611561
use rustc_front::hir::*;
1562+
use std::vec;
15621563
match self.node {
15631564
TyPtr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
15641565
TyRptr(ref l, ref m) =>
@@ -1572,8 +1573,13 @@ impl Clean<Type> for hir::Ty {
15721573
resolve_type(cx, p.clean(cx), self.id)
15731574
}
15741575
TyPath(Some(ref qself), ref p) => {
1575-
let mut trait_path = p.clone();
1576-
trait_path.segments.pop();
1576+
let mut segments: vec::Vec<_> = p.segments.clone().into();
1577+
segments.pop();
1578+
let trait_path = hir::Path {
1579+
span: p.span,
1580+
global: p.global,
1581+
segments: segments.into(),
1582+
};
15771583
Type::QPath {
15781584
name: p.segments.last().unwrap().identifier.name.clean(cx),
15791585
self_type: box qself.ty.clean(cx),

src/librustdoc/doctree.rs

+31-28
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,32 @@ use syntax::ast::{Name, NodeId};
2121
use syntax::attr;
2222
use syntax::ptr::P;
2323
use rustc_front::hir;
24+
use rustc_front::hir::Vec;
25+
26+
use std::vec;
2427

2528
pub struct Module {
2629
pub name: Option<Name>,
2730
pub attrs: Vec<ast::Attribute>,
2831
pub where_outer: Span,
2932
pub where_inner: Span,
30-
pub extern_crates: Vec<ExternCrate>,
31-
pub imports: Vec<Import>,
32-
pub structs: Vec<Struct>,
33-
pub enums: Vec<Enum>,
34-
pub fns: Vec<Function>,
35-
pub mods: Vec<Module>,
33+
pub extern_crates: vec::Vec<ExternCrate>,
34+
pub imports: vec::Vec<Import>,
35+
pub structs: vec::Vec<Struct>,
36+
pub enums: vec::Vec<Enum>,
37+
pub fns: vec::Vec<Function>,
38+
pub mods: vec::Vec<Module>,
3639
pub id: NodeId,
37-
pub typedefs: Vec<Typedef>,
38-
pub statics: Vec<Static>,
39-
pub constants: Vec<Constant>,
40-
pub traits: Vec<Trait>,
40+
pub typedefs: vec::Vec<Typedef>,
41+
pub statics: vec::Vec<Static>,
42+
pub constants: vec::Vec<Constant>,
43+
pub traits: vec::Vec<Trait>,
4144
pub vis: hir::Visibility,
4245
pub stab: Option<attr::Stability>,
43-
pub impls: Vec<Impl>,
44-
pub def_traits: Vec<DefaultImpl>,
45-
pub foreigns: Vec<hir::ForeignMod>,
46-
pub macros: Vec<Macro>,
46+
pub impls: vec::Vec<Impl>,
47+
pub def_traits: vec::Vec<DefaultImpl>,
48+
pub foreigns: vec::Vec<hir::ForeignMod>,
49+
pub macros: vec::Vec<Macro>,
4750
pub is_crate: bool,
4851
}
4952

@@ -57,20 +60,20 @@ impl Module {
5760
where_outer: syntax::codemap::DUMMY_SP,
5861
where_inner: syntax::codemap::DUMMY_SP,
5962
attrs : Vec::new(),
60-
extern_crates: Vec::new(),
61-
imports : Vec::new(),
62-
structs : Vec::new(),
63-
enums : Vec::new(),
64-
fns : Vec::new(),
65-
mods : Vec::new(),
66-
typedefs : Vec::new(),
67-
statics : Vec::new(),
68-
constants : Vec::new(),
69-
traits : Vec::new(),
70-
impls : Vec::new(),
71-
def_traits : Vec::new(),
72-
foreigns : Vec::new(),
73-
macros : Vec::new(),
63+
extern_crates: vec::Vec::new(),
64+
imports : vec::Vec::new(),
65+
structs : vec::Vec::new(),
66+
enums : vec::Vec::new(),
67+
fns : vec::Vec::new(),
68+
mods : vec::Vec::new(),
69+
typedefs : vec::Vec::new(),
70+
statics : vec::Vec::new(),
71+
constants : vec::Vec::new(),
72+
traits : vec::Vec::new(),
73+
impls : vec::Vec::new(),
74+
def_traits : vec::Vec::new(),
75+
foreigns : vec::Vec::new(),
76+
macros : vec::Vec::new(),
7477
is_crate : false,
7578
}
7679
}

src/librustdoc/visit_ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use doctree::*;
3838

3939
pub struct RustdocVisitor<'a, 'tcx: 'a> {
4040
pub module: Module,
41-
pub attrs: Vec<ast::Attribute>,
41+
pub attrs: hir::Vec<ast::Attribute>,
4242
pub cx: &'a core::DocContext<'a, 'tcx>,
4343
pub analysis: Option<&'a core::CrateAnalysis>,
4444
view_item_stack: HashSet<ast::NodeId>,
@@ -53,7 +53,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
5353
stack.insert(ast::CRATE_NODE_ID);
5454
RustdocVisitor {
5555
module: Module::new(None),
56-
attrs: Vec::new(),
56+
attrs: hir::Vec::new(),
5757
cx: cx,
5858
analysis: analysis,
5959
view_item_stack: stack,
@@ -146,7 +146,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
146146
}
147147
}
148148

149-
pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec<ast::Attribute> ,
149+
pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::Vec<ast::Attribute> ,
150150
vis: hir::Visibility, id: ast::NodeId,
151151
m: &hir::Mod,
152152
name: Option<ast::Name>) -> Module {
@@ -180,7 +180,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
180180
let mine = paths.into_iter().filter(|path| {
181181
!self.resolve_id(path.node.id(), None, false, om,
182182
please_inline)
183-
}).collect::<Vec<hir::PathListItem>>();
183+
}).collect::<hir::Vec<_>>();
184184

185185
if mine.is_empty() {
186186
None

src/libsyntax/owned_slice.rs

+36-16
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
use std::fmt;
1212
use std::iter::FromIterator;
1313
use std::ops::Deref;
14-
use std::ptr;
1514
use std::slice;
1615
use std::vec;
1716

18-
use util::MoveMap;
19-
2017
/// A non-growable owned slice. This is a separate type to allow the
2118
/// representation to change.
2219
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
@@ -28,6 +25,42 @@ impl<T> OwnedSlice<T> {
2825
pub fn new() -> OwnedSlice<T> {
2926
OwnedSlice { data: Box::new([]) }
3027
}
28+
29+
#[unstable(feature = "rustc_private", issue = "0")]
30+
#[rustc_deprecated(since = "1.6.0", reason = "use `OwnedSlice::new` instead")]
31+
pub fn empty() -> OwnedSlice<T> {
32+
OwnedSlice { data: Box::new([]) }
33+
}
34+
35+
#[unstable(feature = "rustc_private", issue = "0")]
36+
#[rustc_deprecated(since = "1.6.0", reason = "use `OwnedSlice::from` instead")]
37+
pub fn from_vec(v: Vec<T>) -> OwnedSlice<T> {
38+
OwnedSlice { data: v.into_boxed_slice() }
39+
}
40+
41+
#[unstable(feature = "rustc_private", issue = "0")]
42+
#[rustc_deprecated(since = "1.6.0", reason = "use `OwnedSlice::into` instead")]
43+
pub fn into_vec(self) -> Vec<T> {
44+
self.data.into_vec()
45+
}
46+
47+
#[unstable(feature = "rustc_private", issue = "0")]
48+
#[rustc_deprecated(since = "1.6.0", reason = "use `&owned_slice[..]` instead")]
49+
pub fn as_slice<'a>(&'a self) -> &'a [T] {
50+
&*self.data
51+
}
52+
53+
#[unstable(feature = "rustc_private", issue = "0")]
54+
#[rustc_deprecated(since = "1.6.0", reason = "use `OwnedSlice::into_iter` instead")]
55+
pub fn move_iter(self) -> vec::IntoIter<T> {
56+
self.data.into_vec().into_iter()
57+
}
58+
59+
#[unstable(feature = "rustc_private", issue = "0")]
60+
#[rustc_deprecated(since = "1.6.0", reason = "use `iter().map(f).collect()` instead")]
61+
pub fn map<U, F: FnMut(&T) -> U>(&self, f: F) -> OwnedSlice<U> {
62+
self.iter().map(f).collect()
63+
}
3164
}
3265

3366
impl<T> Deref for OwnedSlice<T> {
@@ -86,16 +119,3 @@ impl<'a, T> IntoIterator for &'a mut OwnedSlice<T> {
86119
self.data.iter_mut()
87120
}
88121
}
89-
90-
impl<T> MoveMap for OwnedSlice<T> {
91-
type Item = T;
92-
fn move_map<F>(mut self, mut f: F) -> OwnedSlice<T> where F: FnMut(T) -> T {
93-
for p in &mut self {
94-
unsafe {
95-
// FIXME(#5016) this shouldn't need to zero to be safe.
96-
ptr::write(p, f(ptr::read_and_drop(p)));
97-
}
98-
}
99-
self
100-
}
101-
}

src/libsyntax/util/small_vector.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use std::mem;
1616
use std::slice;
1717
use std::vec;
1818

19-
use util::MoveMap;
20-
2119
/// A vector type optimized for cases where the size is almost always 0 or 1
2220
pub struct SmallVector<T> {
2321
repr: SmallVectorRepr<T>,
@@ -37,6 +35,14 @@ impl<T> FromIterator<T> for SmallVector<T> {
3735
}
3836
}
3937

38+
impl<'a, T> IntoIterator for &'a mut SmallVector<T> {
39+
type Item = &'a mut T;
40+
type IntoIter = slice::IterMut<'a, T>;
41+
fn into_iter(self) -> Self::IntoIter {
42+
self.as_slice_mut().iter_mut()
43+
}
44+
}
45+
4046
impl<T> Extend<T> for SmallVector<T> {
4147
fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
4248
for val in iter {
@@ -71,6 +77,18 @@ impl<T> SmallVector<T> {
7177
}
7278
}
7379

80+
pub fn as_slice_mut(&mut self) -> &mut [T] {
81+
match self.repr {
82+
Zero => {
83+
&mut []
84+
}
85+
One(ref mut v) => {
86+
unsafe { slice::from_raw_parts_mut(v, 1) }
87+
}
88+
Many(ref mut vs) => vs
89+
}
90+
}
91+
7492
pub fn pop(&mut self) -> Option<T> {
7593
match self.repr {
7694
Zero => None,
@@ -195,19 +213,6 @@ impl<T> Iterator for IntoIter<T> {
195213
}
196214
}
197215

198-
impl<T> MoveMap<T> for SmallVector<T> {
199-
fn move_flat_map<F, I>(self, mut f: F) -> Self
200-
where F: FnMut(T) -> I,
201-
I: IntoIterator<Item=T>
202-
{
203-
match self.repr {
204-
Zero => Self::zero(),
205-
One(v) => f(v).into_iter().collect(),
206-
Many(vs) => SmallVector { repr: Many(vs.move_flat_map(f)) },
207-
}
208-
}
209-
}
210-
211216
#[cfg(test)]
212217
mod tests {
213218
use super::*;

0 commit comments

Comments
 (0)