From 130a32fa7259d348dc3a684b38e688da398c30bb Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 30 Aug 2018 11:42:16 +0200 Subject: [PATCH] Remove OneVector --- src/Cargo.lock | 1 + src/librustc/hir/lowering.rs | 20 +++---- src/librustc_allocator/expand.rs | 10 +--- src/librustc_data_structures/lib.rs | 2 - src/librustc_data_structures/small_vec.rs | 55 ------------------- src/librustc_driver/Cargo.toml | 1 + src/librustc_driver/lib.rs | 1 + src/librustc_driver/pretty.rs | 6 +- src/librustc_resolve/macros.rs | 5 +- src/libsyntax/config.rs | 13 +++-- src/libsyntax/diagnostics/plugin.rs | 9 ++- src/libsyntax/ext/base.rs | 50 ++++++++--------- src/libsyntax/ext/expand.rs | 41 ++++++++------ src/libsyntax/ext/placeholders.rs | 12 ++-- src/libsyntax/ext/source_util.rs | 8 +-- src/libsyntax/ext/tt/macro_parser.rs | 12 ++-- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/fold.rs | 40 +++++++++----- src/libsyntax/lib.rs | 1 - src/libsyntax/test.rs | 9 ++- src/libsyntax/util/move_map.rs | 4 +- .../auxiliary/issue-16723.rs | 7 ++- 22 files changed, 134 insertions(+), 177 deletions(-) delete mode 100644 src/librustc_data_structures/small_vec.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 6725c23135090..40a5ea6b12bf0 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2177,6 +2177,7 @@ dependencies = [ "rustc_typeck 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_ext 0.0.0", "syntax_pos 0.0.0", diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 1e9936fdc13fc..aa1bd6dd59ccf 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -52,7 +52,6 @@ use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, use middle::cstore::CrateStore; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::indexed_vec::IndexVec; -use rustc_data_structures::small_vec::OneVector; use rustc_data_structures::thin_vec::ThinVec; use session::Session; use util::common::FN_OUTPUT_NAME; @@ -62,6 +61,7 @@ use std::collections::BTreeMap; use std::fmt::Debug; use std::iter; use std::mem; +use smallvec::SmallVec; use syntax::attr; use syntax::ast; use syntax::ast::*; @@ -307,7 +307,7 @@ enum AnonymousLifetimeMode { PassThrough, } -struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut OneVector } +struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut SmallVec<[hir::ItemId; 1]> } impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> { fn visit_ty(&mut self, ty: &'a Ty) { @@ -1901,9 +1901,9 @@ impl<'a> LoweringContext<'a> { ) } - fn lower_local(&mut self, l: &Local) -> (P, OneVector) { + fn lower_local(&mut self, l: &Local) -> (P, SmallVec<[hir::ItemId; 1]>) { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id); - let mut ids = OneVector::::new(); + let mut ids = SmallVec::<[hir::ItemId; 1]>::new(); if self.sess.features_untracked().impl_trait_in_bindings { if let Some(ref ty) = l.ty { let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids }; @@ -3211,7 +3211,7 @@ impl<'a> LoweringContext<'a> { &mut self, decl: &FnDecl, header: &FnHeader, - ids: &mut OneVector, + ids: &mut SmallVec<[hir::ItemId; 1]>, ) { if let Some(id) = header.asyncness.opt_return_id() { ids.push(hir::ItemId { id }); @@ -3223,14 +3223,14 @@ impl<'a> LoweringContext<'a> { } } - fn lower_item_id(&mut self, i: &Item) -> OneVector { + fn lower_item_id(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> { match i.node { ItemKind::Use(ref use_tree) => { let mut vec = smallvec![hir::ItemId { id: i.id }]; self.lower_item_id_use_tree(use_tree, i.id, &mut vec); vec } - ItemKind::MacroDef(..) => OneVector::new(), + ItemKind::MacroDef(..) => SmallVec::new(), ItemKind::Fn(ref decl, ref header, ..) => { let mut ids = smallvec![hir::ItemId { id: i.id }]; self.lower_fn_impl_trait_ids(decl, header, &mut ids); @@ -3268,7 +3268,7 @@ impl<'a> LoweringContext<'a> { fn lower_item_id_use_tree(&mut self, tree: &UseTree, base_id: NodeId, - vec: &mut OneVector) + vec: &mut SmallVec<[hir::ItemId; 1]>) { match tree.kind { UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec { @@ -4369,11 +4369,11 @@ impl<'a> LoweringContext<'a> { } } - fn lower_stmt(&mut self, s: &Stmt) -> OneVector { + fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> { smallvec![match s.node { StmtKind::Local(ref l) => { let (l, item_ids) = self.lower_local(l); - let mut ids: OneVector = item_ids + let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids .into_iter() .map(|item_id| Spanned { node: hir::StmtKind::Decl( diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 11e8c30760b8a..5df68d49af5f7 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -9,8 +9,8 @@ // except according to those terms. use rustc::middle::allocator::AllocatorKind; -use rustc_data_structures::small_vec::OneVector; use rustc_errors; +use smallvec::SmallVec; use syntax::{ ast::{ self, Arg, Attribute, Crate, Expr, FnHeader, Generics, Ident, Item, ItemKind, @@ -65,7 +65,7 @@ struct ExpandAllocatorDirectives<'a> { } impl<'a> Folder for ExpandAllocatorDirectives<'a> { - fn fold_item(&mut self, item: P) -> OneVector> { + fn fold_item(&mut self, item: P) -> SmallVec<[P; 1]> { debug!("in submodule {}", self.in_submod); let name = if attr::contains_name(&item.attrs, "global_allocator") { @@ -152,11 +152,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { let module = f.cx.monotonic_expander().fold_item(module).pop().unwrap(); // Return the item and new submodule - let mut ret = OneVector::with_capacity(2); - ret.push(item); - ret.push(module); - - return ret; + smallvec![item, module] } // If we enter a submodule, take note. diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 70b960ac351c0..43ab386980626 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -50,7 +50,6 @@ extern crate rustc_rayon as rayon; extern crate rustc_rayon_core as rayon_core; extern crate rustc_hash; extern crate serialize; -#[cfg_attr(test, macro_use)] extern crate smallvec; // See librustc_cratesio_shim/Cargo.toml for a comment explaining this. @@ -72,7 +71,6 @@ pub mod owning_ref; pub mod ptr_key; pub mod sip128; pub mod small_c_str; -pub mod small_vec; pub mod snapshot_map; pub use ena::snapshot_vec; pub mod sorted_map; diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs deleted file mode 100644 index 075b70c6426fb..0000000000000 --- a/src/librustc_data_structures/small_vec.rs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A vector type intended to be used for small vectors. -//! -//! Space for up to N elements is provided on the stack. If more elements are collected, Vec is -//! used to store the values on the heap. -//! -//! The N above is determined by Array's implementor, by way of an associated constant. - -use smallvec::{Array, SmallVec}; - -pub type OneVector = SmallVec<[T; 1]>; - -pub trait ExpectOne { - fn expect_one(self, err: &'static str) -> A::Item; -} - -impl ExpectOne for SmallVec { - fn expect_one(self, err: &'static str) -> A::Item { - assert!(self.len() == 1, err); - self.into_iter().next().unwrap() - } -} - -#[cfg(test)] -mod tests { - extern crate test; - use super::*; - - #[test] - #[should_panic] - fn test_expect_one_zero() { - let _: isize = OneVector::new().expect_one(""); - } - - #[test] - #[should_panic] - fn test_expect_one_many() { - OneVector::from_vec(vec![1, 2]).expect_one(""); - } - - #[test] - fn test_expect_one_one() { - assert_eq!(1, (smallvec![1] as OneVector<_>).expect_one("")); - assert_eq!(1, OneVector::from_vec(vec![1]).expect_one("")); - } -} diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 7a020f331e50b..470c8b03d0bca 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -35,5 +35,6 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" } rustc_typeck = { path = "../librustc_typeck" } serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } +smallvec = { version = "0.6.5", features = ["union"] } syntax_ext = { path = "../libsyntax_ext" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index a96c277d4b555..f8ca154d168ba 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -58,6 +58,7 @@ extern crate rustc_codegen_utils; extern crate rustc_typeck; extern crate scoped_tls; extern crate serialize; +extern crate smallvec; #[macro_use] extern crate log; extern crate syntax; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index c49631515eab9..7e395f1e9a92f 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -24,7 +24,6 @@ use rustc::session::Session; use rustc::session::config::{Input, OutputFilenames}; use rustc_borrowck as borrowck; use rustc_borrowck::graphviz as borrowck_dot; -use rustc_data_structures::small_vec::OneVector; use rustc_data_structures::thin_vec::ThinVec; use rustc_metadata::cstore::CStore; @@ -38,6 +37,7 @@ use syntax::ptr::P; use syntax_pos::{self, FileName}; use graphviz as dot; +use smallvec::SmallVec; use std::cell::Cell; use std::fs::File; @@ -727,7 +727,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_item_kind(i, s)) } - fn fold_trait_item(&mut self, i: ast::TraitItem) -> OneVector { + fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> { let is_const = match i.node { ast::TraitItemKind::Const(..) => true, ast::TraitItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => @@ -737,7 +737,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_trait_item(i, s)) } - fn fold_impl_item(&mut self, i: ast::ImplItem) -> OneVector { + fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> { let is_const = match i.node { ast::ImplItemKind::Const(..) => true, ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 89bc2f2709a3c..ed79ff62f176c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -42,7 +42,6 @@ use errors::Applicability; use std::cell::Cell; use std::mem; use rustc_data_structures::sync::Lrc; -use rustc_data_structures::small_vec::ExpectOne; #[derive(Clone, Copy)] crate struct FromPrelude(bool); @@ -190,7 +189,9 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> { } } - EliminateCrateVar(self, item.span).fold_item(item).expect_one("") + let ret = EliminateCrateVar(self, item.span).fold_item(item); + assert!(ret.len() == 1); + ret.into_iter().next().unwrap() } fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool { diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 5d978b6b9e662..3d9f4a92f818a 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -15,7 +15,7 @@ use ast; use source_map::Spanned; use edition::Edition; use parse::{token, ParseSess}; -use OneVector; +use smallvec::SmallVec; use errors::Applicability; use ptr::P; @@ -338,22 +338,23 @@ impl<'a> fold::Folder for StripUnconfigured<'a> { Some(P(fold::noop_fold_expr(expr, self))) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { match self.configure_stmt(stmt) { Some(stmt) => fold::noop_fold_stmt(stmt, self), - None => return OneVector::new(), + None => return SmallVec::new(), } } - fn fold_item(&mut self, item: P) -> OneVector> { + fn fold_item(&mut self, item: P) -> SmallVec<[P; 1]> { fold::noop_fold_item(configure!(self, item), self) } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> + { fold::noop_fold_impl_item(configure!(self, item), self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> { fold::noop_fold_trait_item(configure!(self, item), self) } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index c5a2cd5ac0b43..1229db9b0e038 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -19,7 +19,6 @@ use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::build::AstBuilder; use parse::token; use ptr::P; -use OneVector; use symbol::{keywords, Symbol}; use tokenstream::{TokenTree}; @@ -131,7 +130,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, let sym = Ident::with_empty_ctxt(Symbol::gensym(&format!( "__register_diagnostic_{}", code ))); - MacEager::items(OneVector::from_vec(vec![ + MacEager::items(smallvec![ ecx.item_mod( span, span, @@ -139,7 +138,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, Vec::new(), Vec::new() ) - ])) + ]) } pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, @@ -214,7 +213,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ), ); - MacEager::items(OneVector::from_vec(vec![ + MacEager::items(smallvec![ P(ast::Item { ident: *name, attrs: Vec::new(), @@ -227,5 +226,5 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, span, tokens: None, }) - ])) + ]) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index e42624bf41f0a..5bf1a7dd663cc 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -22,7 +22,7 @@ use fold::{self, Folder}; use parse::{self, parser, DirectoryOwnership}; use parse::token; use ptr::P; -use OneVector; +use smallvec::SmallVec; use symbol::{keywords, Ident, Symbol}; use ThinVec; @@ -332,22 +332,22 @@ pub trait MacResult { None } /// Create zero or more items. - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option; 1]>> { None } /// Create zero or more impl items. - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { None } /// Create zero or more trait items. - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { None } /// Create zero or more items in an `extern {}` block - fn make_foreign_items(self: Box) -> Option> { None } + fn make_foreign_items(self: Box) -> Option> { None } /// Create a pattern. fn make_pat(self: Box) -> Option> { @@ -358,7 +358,7 @@ pub trait MacResult { /// /// By default this attempts to create an expression statement, /// returning None if that fails. - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { make_stmts_default!(self) } @@ -394,11 +394,11 @@ macro_rules! make_MacEager { make_MacEager! { expr: P, pat: P, - items: OneVector>, - impl_items: OneVector, - trait_items: OneVector, - foreign_items: OneVector, - stmts: OneVector, + items: SmallVec<[P; 1]>, + impl_items: SmallVec<[ast::ImplItem; 1]>, + trait_items: SmallVec<[ast::TraitItem; 1]>, + foreign_items: SmallVec<[ast::ForeignItem; 1]>, + stmts: SmallVec<[ast::Stmt; 1]>, ty: P, } @@ -407,23 +407,23 @@ impl MacResult for MacEager { self.expr } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option; 1]>> { self.items } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { self.impl_items } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { self.trait_items } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { self.foreign_items } - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { match self.stmts.as_ref().map_or(0, |s| s.len()) { 0 => make_stmts_default!(self), _ => self.stmts, @@ -514,40 +514,40 @@ impl MacResult for DummyResult { Some(P(DummyResult::raw_pat(self.span))) } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option; 1]>> { // this code needs a comment... why not always just return the Some() ? if self.expr_only { None } else { - Some(OneVector::new()) + Some(SmallVec::new()) } } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(OneVector::new()) + Some(SmallVec::new()) } } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(OneVector::new()) + Some(SmallVec::new()) } } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(OneVector::new()) + Some(SmallVec::new()) } } - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { Some(smallvec![ast::Stmt { id: ast::DUMMY_NODE_ID, node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 33d0e76ca481c..87c53d1687543 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -25,7 +25,7 @@ use parse::{DirectoryOwnership, PResult, ParseSess}; use parse::token::{self, Token}; use parse::parser::Parser; use ptr::P; -use OneVector; +use smallvec::SmallVec; use symbol::Symbol; use symbol::keywords; use syntax_pos::{Span, DUMMY_SP, FileName}; @@ -147,15 +147,19 @@ ast_fragments! { Expr(P) { "expression"; one fn fold_expr; fn visit_expr; fn make_expr; } Pat(P) { "pattern"; one fn fold_pat; fn visit_pat; fn make_pat; } Ty(P) { "type"; one fn fold_ty; fn visit_ty; fn make_ty; } - Stmts(OneVector) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; } - Items(OneVector>) { "item"; many fn fold_item; fn visit_item; fn make_items; } - TraitItems(OneVector) { + Stmts(SmallVec<[ast::Stmt; 1]>) { + "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; + } + Items(SmallVec<[P; 1]>) { + "item"; many fn fold_item; fn visit_item; fn make_items; + } + TraitItems(SmallVec<[ast::TraitItem; 1]>) { "trait item"; many fn fold_trait_item; fn visit_trait_item; fn make_trait_items; } - ImplItems(OneVector) { + ImplItems(SmallVec<[ast::ImplItem; 1]>) { "impl item"; many fn fold_impl_item; fn visit_impl_item; fn make_impl_items; } - ForeignItems(OneVector) { + ForeignItems(SmallVec<[ast::ForeignItem; 1]>) { "foreign item"; many fn fold_foreign_item; fn visit_foreign_item; fn make_foreign_items; } } @@ -980,28 +984,28 @@ impl<'a> Parser<'a> { -> PResult<'a, AstFragment> { Ok(match kind { AstFragmentKind::Items => { - let mut items = OneVector::new(); + let mut items = SmallVec::new(); while let Some(item) = self.parse_item()? { items.push(item); } AstFragment::Items(items) } AstFragmentKind::TraitItems => { - let mut items = OneVector::new(); + let mut items = SmallVec::new(); while self.token != token::Eof { items.push(self.parse_trait_item(&mut false)?); } AstFragment::TraitItems(items) } AstFragmentKind::ImplItems => { - let mut items = OneVector::new(); + let mut items = SmallVec::new(); while self.token != token::Eof { items.push(self.parse_impl_item(&mut false)?); } AstFragment::ImplItems(items) } AstFragmentKind::ForeignItems => { - let mut items = OneVector::new(); + let mut items = SmallVec::new(); while self.token != token::Eof { if let Some(item) = self.parse_foreign_item()? { items.push(item); @@ -1010,7 +1014,7 @@ impl<'a> Parser<'a> { AstFragment::ForeignItems(items) } AstFragmentKind::Stmts => { - let mut stmts = OneVector::new(); + let mut stmts = SmallVec::new(); while self.token != token::Eof && // won't make progress on a `}` self.token != token::CloseDelim(token::Brace) { @@ -1245,10 +1249,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { }) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { let mut stmt = match self.cfg.configure_stmt(stmt) { Some(stmt) => stmt, - None => return OneVector::new(), + None => return SmallVec::new(), }; // we'll expand attributes on expressions separately @@ -1303,7 +1307,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { result } - fn fold_item(&mut self, item: P) -> OneVector> { + fn fold_item(&mut self, item: P) -> SmallVec<[P; 1]> { let item = configure!(self, item); let (attr, traits, item, together_with) = self.classify_item(item); @@ -1378,7 +1382,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> { let item = configure!(self, item); let (attr, traits, item, together_with) = self.classify_item(item); @@ -1397,7 +1401,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> { let item = configure!(self, item); let (attr, traits, item, together_with) = self.classify_item(item); @@ -1432,8 +1436,9 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { noop_fold_foreign_mod(self.cfg.configure_foreign_mod(foreign_mod), self) } - fn fold_foreign_item(&mut self, - foreign_item: ast::ForeignItem) -> OneVector { + fn fold_foreign_item(&mut self, foreign_item: ast::ForeignItem) + -> SmallVec<[ast::ForeignItem; 1]> + { let (attr, traits, foreign_item, together_with) = self.classify_item(foreign_item); if attr.is_some() || !traits.is_empty() { diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 5906412883ad0..7f31b04ef9c3c 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -16,7 +16,7 @@ use ext::hygiene::Mark; use tokenstream::TokenStream; use fold::*; use ptr::P; -use OneVector; +use smallvec::SmallVec; use symbol::keywords; use ThinVec; use util::move_map::MoveMap; @@ -115,7 +115,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> { } impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { - fn fold_item(&mut self, item: P) -> OneVector> { + fn fold_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.node { ast::ItemKind::Mac(_) => return self.remove(item.id).make_items(), ast::ItemKind::MacroDef(_) => return smallvec![item], @@ -125,21 +125,21 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { noop_fold_item(item, self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> { match item.node { ast::TraitItemKind::Macro(_) => self.remove(item.id).make_trait_items(), _ => noop_fold_trait_item(item, self), } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> { match item.node { ast::ImplItemKind::Macro(_) => self.remove(item.id).make_impl_items(), _ => noop_fold_impl_item(item, self), } } - fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> OneVector { + fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> SmallVec<[ast::ForeignItem; 1]> { match item.node { ast::ForeignItemKind::Macro(_) => self.remove(item.id).make_foreign_items(), _ => noop_fold_foreign_item(item, self), @@ -160,7 +160,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { } } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { let (style, mut stmts) = match stmt.node { ast::StmtKind::Mac(mac) => (mac.1, self.remove(stmt.id).make_stmts()), _ => return noop_fold_stmt(stmt, self), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index e4b9e3216b13b..f5d1bd6255e2a 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -17,7 +17,7 @@ use parse::{token, DirectoryOwnership}; use parse; use print::pprust; use ptr::P; -use OneVector; +use smallvec::SmallVec; use symbol::Symbol; use tokenstream; @@ -110,9 +110,9 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T fn make_expr(mut self: Box>) -> Option> { Some(panictry!(self.p.parse_expr())) } - fn make_items(mut self: Box>) - -> Option>> { - let mut ret = OneVector::new(); + + fn make_items(mut self: Box>) -> Option; 1]>> { + let mut ret = SmallVec::new(); while self.p.token != token::Eof { match panictry!(self.p.parse_item()) { Some(item) => ret.push(item), diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 941fd6f1000a3..03a8376e76361 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -92,7 +92,7 @@ use parse::{Directory, ParseSess}; use parse::parser::{Parser, PathStyle}; use parse::token::{self, DocComment, Nonterminal, Token}; use print::pprust; -use OneVector; +use smallvec::SmallVec; use symbol::keywords; use tokenstream::{DelimSpan, TokenStream}; @@ -440,10 +440,10 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { /// A `ParseResult`. Note that matches are kept track of through the items generated. fn inner_parse_loop<'a>( sess: &ParseSess, - cur_items: &mut OneVector>, + cur_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>, next_items: &mut Vec>, - eof_items: &mut OneVector>, - bb_items: &mut OneVector>, + eof_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>, + bb_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>, token: &Token, span: syntax_pos::Span, ) -> ParseResult<()> { @@ -649,10 +649,10 @@ pub fn parse( loop { // Matcher positions black-box parsed by parser.rs (`parser`) - let mut bb_items = OneVector::new(); + let mut bb_items = SmallVec::new(); // Matcher positions that would be valid if the macro invocation was over now - let mut eof_items = OneVector::new(); + let mut eof_items = SmallVec::new(); assert!(next_items.is_empty()); // Process `cur_items` until either we have finished the input or we need to get some diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 2ed469e8e77f8..ae486158fee69 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -15,7 +15,7 @@ use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; use ext::tt::quoted; use fold::noop_fold_tt; use parse::token::{self, Token, NtTT}; -use OneVector; +use smallvec::SmallVec; use syntax_pos::DUMMY_SP; use tokenstream::{TokenStream, TokenTree, Delimited, DelimSpan}; @@ -70,7 +70,7 @@ pub fn transcribe(cx: &ExtCtxt, interp: Option>>, src: Vec) -> TokenStream { - let mut stack: OneVector = smallvec![Frame::new(src)]; + let mut stack: SmallVec<[Frame; 1]> = smallvec![Frame::new(src)]; let interpolations = interp.unwrap_or_else(FxHashMap::default); /* just a convenience */ let mut repeats = Vec::new(); let mut result: Vec = Vec::new(); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 032393b4f1253..3e422f5af81a7 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -24,14 +24,24 @@ use syntax_pos::Span; use source_map::{Spanned, respan}; use parse::token::{self, Token}; use ptr::P; -use OneVector; +use smallvec::{Array, SmallVec}; use symbol::keywords; use ThinVec; use tokenstream::*; use util::move_map::MoveMap; use rustc_data_structures::sync::Lrc; -use rustc_data_structures::small_vec::ExpectOne; + +pub trait ExpectOne { + fn expect_one(self, err: &'static str) -> A::Item; +} + +impl ExpectOne for SmallVec { + fn expect_one(self, err: &'static str) -> A::Item { + assert!(self.len() == 1, err); + self.into_iter().next().unwrap() + } +} pub trait Folder : Sized { // Any additions to this trait should happen in form @@ -62,7 +72,7 @@ pub trait Folder : Sized { noop_fold_use_tree(use_tree, self) } - fn fold_foreign_item(&mut self, ni: ForeignItem) -> OneVector { + fn fold_foreign_item(&mut self, ni: ForeignItem) -> SmallVec<[ForeignItem; 1]> { noop_fold_foreign_item(ni, self) } @@ -70,7 +80,7 @@ pub trait Folder : Sized { noop_fold_foreign_item_simple(ni, self) } - fn fold_item(&mut self, i: P) -> OneVector> { + fn fold_item(&mut self, i: P) -> SmallVec<[P; 1]> { noop_fold_item(i, self) } @@ -90,11 +100,11 @@ pub trait Folder : Sized { noop_fold_item_kind(i, self) } - fn fold_trait_item(&mut self, i: TraitItem) -> OneVector { + fn fold_trait_item(&mut self, i: TraitItem) -> SmallVec<[TraitItem; 1]> { noop_fold_trait_item(i, self) } - fn fold_impl_item(&mut self, i: ImplItem) -> OneVector { + fn fold_impl_item(&mut self, i: ImplItem) -> SmallVec<[ImplItem; 1]> { noop_fold_impl_item(i, self) } @@ -110,7 +120,7 @@ pub trait Folder : Sized { noop_fold_block(b, self) } - fn fold_stmt(&mut self, s: Stmt) -> OneVector { + fn fold_stmt(&mut self, s: Stmt) -> SmallVec<[Stmt; 1]> { noop_fold_stmt(s, self) } @@ -974,8 +984,7 @@ pub fn noop_fold_item_kind(i: ItemKind, folder: &mut T) -> ItemKind { } } -pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) - -> OneVector { +pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) -> SmallVec<[TraitItem; 1]> { smallvec![TraitItem { id: folder.new_id(i.id), ident: folder.fold_ident(i.ident), @@ -1003,8 +1012,7 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) }] } -pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) - -> OneVector { +pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T)-> SmallVec<[ImplItem; 1]> { smallvec![ImplItem { id: folder.new_id(i.id), vis: folder.fold_vis(i.vis), @@ -1080,7 +1088,7 @@ pub fn noop_fold_crate(Crate {module, attrs, span}: Crate, } // fold one item into possibly many items -pub fn noop_fold_item(i: P, folder: &mut T) -> OneVector> { +pub fn noop_fold_item(i: P, folder: &mut T) -> SmallVec<[P; 1]> { smallvec![i.map(|i| folder.fold_item_simple(i))] } @@ -1102,7 +1110,8 @@ pub fn noop_fold_item_simple(Item {id, ident, attrs, node, vis, span, } pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) --> OneVector { + -> SmallVec<[ForeignItem; 1]> +{ smallvec![folder.fold_foreign_item_simple(ni)] } @@ -1381,7 +1390,8 @@ pub fn noop_fold_exprs(es: Vec>, folder: &mut T) -> Vec(Stmt {node, span, id}: Stmt, folder: &mut T) -> OneVector { +pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVec<[Stmt; 1]> +{ let id = folder.new_id(id); let span = folder.new_span(span); noop_fold_stmt_kind(node, folder).into_iter().map(|node| { @@ -1389,7 +1399,7 @@ pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> }).collect() } -pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> OneVector { +pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> SmallVec<[StmtKind; 1]> { match node { StmtKind::Local(local) => smallvec![StmtKind::Local(folder.fold_local(local))], StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 68b468417182a..a1b031a655f85 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -47,7 +47,6 @@ extern crate serialize as rustc_serialize; // used by deriving use rustc_data_structures::sync::Lock; use rustc_data_structures::bit_set::GrowableBitSet; -pub use rustc_data_structures::small_vec::OneVector; pub use rustc_data_structures::thin_vec::ThinVec; use ast::AttrId; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index ab67736c389c0..744e2e4a5fdb8 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -33,15 +33,14 @@ use ext::hygiene::{self, Mark, SyntaxContext}; use fold::Folder; use feature_gate::Features; use util::move_map::MoveMap; -use fold; +use fold::{self, ExpectOne}; use parse::{token, ParseSess}; use print::pprust; use ast::{self, Ident}; use ptr::P; -use OneVector; +use smallvec::SmallVec; use symbol::{self, Symbol, keywords}; use ThinVec; -use rustc_data_structures::small_vec::ExpectOne; struct Test { span: Span, @@ -113,7 +112,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { folded } - fn fold_item(&mut self, i: P) -> OneVector> { + fn fold_item(&mut self, i: P) -> SmallVec<[P; 1]> { let ident = i.ident; if ident.name != keywords::Invalid.name() { self.cx.path.push(ident); @@ -171,7 +170,7 @@ struct EntryPointCleaner { } impl fold::Folder for EntryPointCleaner { - fn fold_item(&mut self, i: P) -> OneVector> { + fn fold_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; let folded = fold::noop_fold_item(i, self).expect_one("noop did something"); self.depth -= 1; diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/move_map.rs index eb2c5a2458c15..51cae1b5d84ac 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/move_map.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::ptr; -use OneVector; +use smallvec::{Array, SmallVec}; pub trait MoveMap: Sized { fn move_map(self, mut f: F) -> Self where F: FnMut(T) -> T { @@ -77,7 +77,7 @@ impl MoveMap for ::ptr::P<[T]> { } } -impl MoveMap for OneVector { +impl> MoveMap for SmallVec { fn move_flat_map(mut self, mut f: F) -> Self where F: FnMut(T) -> I, I: IntoIterator diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs index 533d0ac490c41..7b7092c7e22e3 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs @@ -17,9 +17,10 @@ extern crate syntax; extern crate rustc; extern crate rustc_data_structures; extern crate rustc_plugin; +#[macro_use] extern crate smallvec; extern crate syntax_pos; -use rustc_data_structures::small_vec::OneVector; +use smallvec::SmallVec; use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; use syntax::tokenstream; use rustc_plugin::Registry; @@ -31,8 +32,8 @@ pub fn plugin_registrar(reg: &mut Registry) { fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree]) -> Box { - MacEager::items(OneVector::from_vec(vec![ + MacEager::items(smallvec![ quote_item!(cx, struct Struct1;).unwrap(), quote_item!(cx, struct Struct2;).unwrap() - ])) + ]) }