Skip to content

35 files changed

+245
-245
lines changed
 

‎src/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,7 @@ version = "0.0.0"
20492049
dependencies = [
20502050
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
20512051
"rustc 0.0.0",
2052+
"rustc_data_structures 0.0.0",
20522053
"rustc_errors 0.0.0",
20532054
"rustc_target 0.0.0",
20542055
"syntax 0.0.0",

‎src/librustc/hir/lowering.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
5151
ELIDED_LIFETIMES_IN_PATHS};
5252
use middle::cstore::CrateStore;
5353
use rustc_data_structures::indexed_vec::IndexVec;
54+
use rustc_data_structures::small_vec::OneVector;
55+
use rustc_data_structures::thin_vec::ThinVec;
5456
use session::Session;
5557
use util::common::FN_OUTPUT_NAME;
5658
use util::nodemap::{DefIdMap, NodeMap};
@@ -71,7 +73,6 @@ use syntax::std_inject;
7173
use syntax::symbol::{keywords, Symbol};
7274
use syntax::tokenstream::{Delimited, TokenStream, TokenTree};
7375
use syntax::parse::token::Token;
74-
use syntax::util::small_vector::SmallVector;
7576
use syntax::visit::{self, Visitor};
7677
use syntax_pos::{Span, MultiSpan};
7778

@@ -3136,12 +3137,12 @@ impl<'a> LoweringContext<'a> {
31363137
&mut self,
31373138
decl: &FnDecl,
31383139
header: &FnHeader,
3139-
ids: &mut SmallVector<hir::ItemId>,
3140+
ids: &mut OneVector<hir::ItemId>,
31403141
) {
31413142
if let Some(id) = header.asyncness.opt_return_id() {
31423143
ids.push(hir::ItemId { id });
31433144
}
3144-
struct IdVisitor<'a> { ids: &'a mut SmallVector<hir::ItemId> }
3145+
struct IdVisitor<'a> { ids: &'a mut OneVector<hir::ItemId> }
31453146
impl<'a, 'b> Visitor<'a> for IdVisitor<'b> {
31463147
fn visit_ty(&mut self, ty: &'a Ty) {
31473148
match ty.node {
@@ -3174,36 +3175,36 @@ impl<'a> LoweringContext<'a> {
31743175
}
31753176
}
31763177

3177-
fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> {
3178+
fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
31783179
match i.node {
31793180
ItemKind::Use(ref use_tree) => {
3180-
let mut vec = SmallVector::one(hir::ItemId { id: i.id });
3181+
let mut vec = OneVector::one(hir::ItemId { id: i.id });
31813182
self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
31823183
vec
31833184
}
3184-
ItemKind::MacroDef(..) => SmallVector::new(),
3185+
ItemKind::MacroDef(..) => OneVector::new(),
31853186
ItemKind::Fn(ref decl, ref header, ..) => {
3186-
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
3187+
let mut ids = OneVector::one(hir::ItemId { id: i.id });
31873188
self.lower_impl_trait_ids(decl, header, &mut ids);
31883189
ids
31893190
},
31903191
ItemKind::Impl(.., None, _, ref items) => {
3191-
let mut ids = SmallVector::one(hir::ItemId { id: i.id });
3192+
let mut ids = OneVector::one(hir::ItemId { id: i.id });
31923193
for item in items {
31933194
if let ImplItemKind::Method(ref sig, _) = item.node {
31943195
self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids);
31953196
}
31963197
}
31973198
ids
31983199
},
3199-
_ => SmallVector::one(hir::ItemId { id: i.id }),
3200+
_ => OneVector::one(hir::ItemId { id: i.id }),
32003201
}
32013202
}
32023203

32033204
fn lower_item_id_use_tree(&mut self,
32043205
tree: &UseTree,
32053206
base_id: NodeId,
3206-
vec: &mut SmallVector<hir::ItemId>)
3207+
vec: &mut OneVector<hir::ItemId>)
32073208
{
32083209
match tree.kind {
32093210
UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec {
@@ -4295,8 +4296,8 @@ impl<'a> LoweringContext<'a> {
42954296
}
42964297
}
42974298

4298-
fn lower_stmt(&mut self, s: &Stmt) -> SmallVector<hir::Stmt> {
4299-
SmallVector::one(match s.node {
4299+
fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
4300+
OneVector::one(match s.node {
43004301
StmtKind::Local(ref l) => Spanned {
43014302
node: hir::StmtKind::Decl(
43024303
P(Spanned {

‎src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ use syntax::ext::hygiene::SyntaxContext;
3333
use syntax::ptr::P;
3434
use syntax::symbol::{Symbol, keywords};
3535
use syntax::tokenstream::TokenStream;
36-
use syntax::util::ThinVec;
3736
use syntax::util::parser::ExprPrecedence;
3837
use ty::AdtKind;
3938
use ty::query::Providers;
4039

4140
use rustc_data_structures::indexed_vec;
4241
use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope};
42+
use rustc_data_structures::thin_vec::ThinVec;
4343

4444
use serialize::{self, Encoder, Encodable, Decoder, Decodable};
4545
use std::collections::BTreeMap;

‎src/librustc_allocator/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test = false
1010

1111
[dependencies]
1212
rustc = { path = "../librustc" }
13+
rustc_data_structures = { path = "../librustc_data_structures" }
1314
rustc_errors = { path = "../librustc_errors" }
1415
rustc_target = { path = "../librustc_target" }
1516
syntax = { path = "../libsyntax" }

‎src/librustc_allocator/expand.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use rustc::middle::allocator::AllocatorKind;
12+
use rustc_data_structures::small_vec::OneVector;
1213
use rustc_errors;
1314
use syntax::{
1415
ast::{
@@ -28,8 +29,7 @@ use syntax::{
2829
fold::{self, Folder},
2930
parse::ParseSess,
3031
ptr::P,
31-
symbol::Symbol,
32-
util::small_vector::SmallVector,
32+
symbol::Symbol
3333
};
3434
use syntax_pos::Span;
3535

@@ -65,7 +65,7 @@ struct ExpandAllocatorDirectives<'a> {
6565
}
6666

6767
impl<'a> Folder for ExpandAllocatorDirectives<'a> {
68-
fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> {
68+
fn fold_item(&mut self, item: P<Item>) -> OneVector<P<Item>> {
6969
debug!("in submodule {}", self.in_submod);
7070

7171
let name = if attr::contains_name(&item.attrs, "global_allocator") {
@@ -78,20 +78,20 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
7878
_ => {
7979
self.handler
8080
.span_err(item.span, "allocators must be statics");
81-
return SmallVector::one(item);
81+
return OneVector::one(item);
8282
}
8383
}
8484

8585
if self.in_submod > 0 {
8686
self.handler
8787
.span_err(item.span, "`global_allocator` cannot be used in submodules");
88-
return SmallVector::one(item);
88+
return OneVector::one(item);
8989
}
9090

9191
if self.found {
9292
self.handler
9393
.span_err(item.span, "cannot define more than one #[global_allocator]");
94-
return SmallVector::one(item);
94+
return OneVector::one(item);
9595
}
9696
self.found = true;
9797

@@ -152,7 +152,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
152152
let module = f.cx.monotonic_expander().fold_item(module).pop().unwrap();
153153

154154
// Return the item and new submodule
155-
let mut ret = SmallVector::with_capacity(2);
155+
let mut ret = OneVector::with_capacity(2);
156156
ret.push(item);
157157
ret.push(module);
158158

‎src/librustc_allocator/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#[macro_use] extern crate log;
1515
extern crate rustc;
16+
extern crate rustc_data_structures;
1617
extern crate rustc_errors;
1718
extern crate rustc_target;
1819
extern crate syntax;

‎src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub mod sorted_map;
7979
#[macro_use] pub mod stable_hasher;
8080
pub mod sync;
8181
pub mod tiny_list;
82+
pub mod thin_vec;
8283
pub mod transitive_relation;
8384
pub mod tuple_slice;
8485
pub use ena::unify;

‎src/librustc_data_structures/small_vec.rs

+65
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use array_vec::Array;
2929

3030
pub struct SmallVec<A: Array>(AccumulateVec<A>);
3131

32+
pub type OneVector<T> = SmallVec<[T; 1]>;
33+
3234
impl<A> Clone for SmallVec<A>
3335
where A: Array,
3436
A::Element: Clone {
@@ -227,6 +229,69 @@ mod tests {
227229

228230
use super::*;
229231

232+
#[test]
233+
fn test_len() {
234+
let v: OneVector<isize> = OneVector::new();
235+
assert_eq!(0, v.len());
236+
237+
assert_eq!(1, OneVector::one(1).len());
238+
assert_eq!(5, OneVector::many(vec![1, 2, 3, 4, 5]).len());
239+
}
240+
241+
#[test]
242+
fn test_push_get() {
243+
let mut v = OneVector::new();
244+
v.push(1);
245+
assert_eq!(1, v.len());
246+
assert_eq!(1, v[0]);
247+
v.push(2);
248+
assert_eq!(2, v.len());
249+
assert_eq!(2, v[1]);
250+
v.push(3);
251+
assert_eq!(3, v.len());
252+
assert_eq!(3, v[2]);
253+
}
254+
255+
#[test]
256+
fn test_from_iter() {
257+
let v: OneVector<isize> = (vec![1, 2, 3]).into_iter().collect();
258+
assert_eq!(3, v.len());
259+
assert_eq!(1, v[0]);
260+
assert_eq!(2, v[1]);
261+
assert_eq!(3, v[2]);
262+
}
263+
264+
#[test]
265+
fn test_move_iter() {
266+
let v = OneVector::new();
267+
let v: Vec<isize> = v.into_iter().collect();
268+
assert_eq!(v, Vec::new());
269+
270+
let v = OneVector::one(1);
271+
assert_eq!(v.into_iter().collect::<Vec<_>>(), [1]);
272+
273+
let v = OneVector::many(vec![1, 2, 3]);
274+
assert_eq!(v.into_iter().collect::<Vec<_>>(), [1, 2, 3]);
275+
}
276+
277+
#[test]
278+
#[should_panic]
279+
fn test_expect_one_zero() {
280+
let _: isize = OneVector::new().expect_one("");
281+
}
282+
283+
#[test]
284+
#[should_panic]
285+
fn test_expect_one_many() {
286+
OneVector::many(vec![1, 2]).expect_one("");
287+
}
288+
289+
#[test]
290+
fn test_expect_one_one() {
291+
assert_eq!(1, OneVector::one(1).expect_one(""));
292+
assert_eq!(1, OneVector::many(vec![1]).expect_one(""));
293+
}
294+
230295
#[bench]
231296
fn fill_small_vec_1_10_with_cap(b: &mut Bencher) {
232297
b.iter(|| {
File renamed without changes.

‎src/librustc_driver/pretty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use rustc::session::Session;
2424
use rustc::session::config::{Input, OutputFilenames};
2525
use rustc_borrowck as borrowck;
2626
use rustc_borrowck::graphviz as borrowck_dot;
27+
use rustc_data_structures::small_vec::OneVector;
28+
use rustc_data_structures::thin_vec::ThinVec;
2729
use rustc_metadata::cstore::CStore;
2830

2931
use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
@@ -33,8 +35,6 @@ use syntax::fold::{self, Folder};
3335
use syntax::print::{pprust};
3436
use syntax::print::pprust::PrintState;
3537
use syntax::ptr::P;
36-
use syntax::util::ThinVec;
37-
use syntax::util::small_vector::SmallVector;
3838
use syntax_pos::{self, FileName};
3939

4040
use graphviz as dot;
@@ -727,7 +727,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
727727
self.run(is_const, |s| fold::noop_fold_item_kind(i, s))
728728
}
729729

730-
fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem> {
730+
fn fold_trait_item(&mut self, i: ast::TraitItem) -> OneVector<ast::TraitItem> {
731731
let is_const = match i.node {
732732
ast::TraitItemKind::Const(..) => true,
733733
ast::TraitItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) =>
@@ -737,7 +737,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
737737
self.run(is_const, |s| fold::noop_fold_trait_item(i, s))
738738
}
739739

740-
fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector<ast::ImplItem> {
740+
fn fold_impl_item(&mut self, i: ast::ImplItem) -> OneVector<ast::ImplItem> {
741741
let is_const = match i.node {
742742
ast::ImplItemKind::Const(..) => true,
743743
ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) =>
@@ -785,7 +785,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
785785
node: ast::ExprKind::Loop(P(empty_block), None),
786786
id: self.sess.next_node_id(),
787787
span: syntax_pos::DUMMY_SP,
788-
attrs: ast::ThinVec::new(),
788+
attrs: ThinVec::new(),
789789
});
790790

791791
let loop_stmt = ast::Stmt {

‎src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
pub use self::UnsafeSource::*;
1414
pub use self::GenericArgs::*;
1515
pub use symbol::{Ident, Symbol as Name};
16-
pub use util::ThinVec;
1716
pub use util::parser::ExprPrecedence;
1817

1918
use syntax_pos::{Span, DUMMY_SP};
@@ -25,6 +24,7 @@ use ptr::P;
2524
use rustc_data_structures::indexed_vec;
2625
use rustc_data_structures::indexed_vec::Idx;
2726
use symbol::{Symbol, keywords};
27+
use ThinVec;
2828
use tokenstream::{ThinTokenStream, TokenStream};
2929

3030
use serialize::{self, Encoder, Decoder};

‎src/libsyntax/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use parse::{self, ParseSess, PResult};
3333
use parse::token::{self, Token};
3434
use ptr::P;
3535
use symbol::Symbol;
36+
use ThinVec;
3637
use tokenstream::{TokenStream, TokenTree, Delimited};
37-
use util::ThinVec;
3838
use GLOBALS;
3939

4040
use std::iter;

‎src/libsyntax/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use ast;
1515
use codemap::Spanned;
1616
use edition::Edition;
1717
use parse::{token, ParseSess};
18+
use OneVector;
1819

1920
use ptr::P;
20-
use util::small_vector::SmallVector;
2121

2222
/// A folder that strips out items that do not belong in the current configuration.
2323
pub struct StripUnconfigured<'a> {
@@ -319,22 +319,22 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
319319
Some(P(fold::noop_fold_expr(expr, self)))
320320
}
321321

322-
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
322+
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
323323
match self.configure_stmt(stmt) {
324324
Some(stmt) => fold::noop_fold_stmt(stmt, self),
325-
None => return SmallVector::new(),
325+
None => return OneVector::new(),
326326
}
327327
}
328328

329-
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
329+
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
330330
fold::noop_fold_item(configure!(self, item), self)
331331
}
332332

333-
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector<ast::ImplItem> {
333+
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
334334
fold::noop_fold_impl_item(configure!(self, item), self)
335335
}
336336

337-
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitItem> {
337+
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
338338
fold::noop_fold_trait_item(configure!(self, item), self)
339339
}
340340

0 commit comments

Comments
 (0)
Please sign in to comment.