fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
match i.node {
ItemKind::Use(ref use_tree) => {
- let mut vec = OneVector::one(hir::ItemId { id: i.id });
+ 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::Fn(ref decl, ref header, ..) => {
- let mut ids = OneVector::one(hir::ItemId { id: i.id });
+ let mut ids = smallvec![hir::ItemId { id: i.id }];
self.lower_impl_trait_ids(decl, header, &mut ids);
ids
},
ItemKind::Impl(.., None, _, ref items) => {
- let mut ids = OneVector::one(hir::ItemId { id: i.id });
+ let mut ids = smallvec![hir::ItemId { id: i.id }];
for item in items {
if let ImplItemKind::Method(ref sig, _) = item.node {
self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids);
}
ids
},
- _ => OneVector::one(hir::ItemId { id: i.id }),
+ _ => smallvec![hir::ItemId { id: i.id }],
}
}
hir::LoopSource::Loop,
)
}),
- ExprKind::Catch(ref body) => {
+ ExprKind::TryBlock(ref body) => {
self.with_catch_scope(body.id, |this| {
let unstable_span =
- this.allow_internal_unstable(CompilerDesugaringKind::Catch, body.span);
+ this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span);
let mut block = this.lower_block(body, true).into_inner();
let tail = block.expr.take().map_or_else(
|| {
}
fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
- OneVector::one(match s.node {
+ smallvec![match s.node {
StmtKind::Local(ref l) => Spanned {
node: hir::StmtKind::Decl(
P(Spanned {
span: s.span,
},
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
- })
+ }]
}
fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
#![feature(trace_macros)]
#![feature(trusted_len)]
#![feature(vec_remove_item)]
-#![feature(catch_expr)]
#![feature(step_trait)]
#![feature(integer_atomics)]
#![feature(test)]
extern crate byteorder;
extern crate backtrace;
+ #[macro_use]
+ extern crate smallvec;
+
// Note that librustc doesn't actually depend on these crates, see the note in
// `Cargo.toml` for this crate about why these are here.
#[allow(unused_extern_crates)]
#![feature(slice_sort_by_cached_key)]
#![feature(box_patterns)]
#![feature(box_syntax)]
-#![feature(catch_expr)]
#![feature(crate_visibility_modifier)]
#![feature(const_fn)]
#![feature(core_intrinsics)]
extern crate rustc_apfloat;
extern crate byteorder;
extern crate core;
+ extern crate smallvec;
+// Once we can use edition 2018 in the compiler,
+// replace this with real try blocks.
+macro_rules! try_block {
+ ($($inside:tt)*) => (
+ (||{ ::std::ops::Try::from_ok({ $($inside)* }) })()
+ )
+}
+
mod diagnostics;
mod borrow_check;
use std::cell::Cell;
use std::mem;
use rustc_data_structures::sync::Lrc;
+ use rustc_data_structures::small_vec::ExpectOne;
crate struct FromPrelude(bool);
crate struct FromExpansion(bool);
let def = def?;
- if path.segments.len() > 1 {
- if kind != MacroKind::Bang {
- if def != Def::NonMacroAttr(NonMacroAttrKind::Tool) &&
- !self.session.features_untracked().proc_macro_path_invoc {
- let msg = format!("non-ident {} paths are unstable", kind.descr());
- emit_feature_err(&self.session.parse_sess, "proc_macro_path_invoc",
- path.span, GateIssue::Language, &msg);
- }
- }
- }
-
match def {
Def::Macro(def_id, macro_kind) => {
self.unused_macros.remove(&def_id);
Def::NonMacroAttr(attr_kind) => {
if kind == MacroKind::Attr {
let features = self.session.features_untracked();
- if attr_kind == NonMacroAttrKind::Tool && !features.tool_attributes {
- feature_err(&self.session.parse_sess, "tool_attributes", path.span,
- GateIssue::Language, "tool attributes are unstable").emit();
- }
if attr_kind == NonMacroAttrKind::Custom {
assert!(path.segments.len() == 1);
let name = path.segments[0].ident.name.as_str();
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
+ use std::iter::FromIterator;
use std::{iter, mem};
use std::rc::Rc;
use std::path::PathBuf;
self.expand_fragment(AstFragment::$Kind(ast)).$make_ast()
})*)*
$($(fn $fold_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
- self.expand_fragment(AstFragment::$Kind(OneVector::one(ast_elt))).$make_ast()
+ self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
})*)*
}
let orig_mod_span = krate.module.inner;
- let krate_item = AstFragment::Items(OneVector::one(P(ast::Item {
+ let krate_item = AstFragment::Items(smallvec![P(ast::Item {
attrs: krate.attrs,
span: krate.span,
node: ast::ItemKind::Mod(krate.module),
id: ast::DUMMY_NODE_ID,
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
tokens: None,
- })));
+ })]);
match self.expand_fragment(krate_item).make_items().pop().map(P::into_inner) {
Some(ast::Item { attrs, node: ast::ItemKind::Mod(module), .. }) => {
None => return,
};
- fragment.visit_with(&mut DisallowModules {
+ fragment.visit_with(&mut DisallowMacros {
span,
parse_sess: self.cx.parse_sess,
});
- struct DisallowModules<'a> {
+ struct DisallowMacros<'a> {
span: Span,
parse_sess: &'a ParseSess,
}
- impl<'ast, 'a> Visitor<'ast> for DisallowModules<'a> {
+ impl<'ast, 'a> Visitor<'ast> for DisallowMacros<'a> {
fn visit_item(&mut self, i: &'ast ast::Item) {
- let name = match i.node {
- ast::ItemKind::Mod(_) => Some("modules"),
- ast::ItemKind::MacroDef(_) => Some("macro definitions"),
- _ => None,
- };
- if let Some(name) = name {
+ if let ast::ItemKind::MacroDef(_) = i.node {
emit_feature_err(
self.parse_sess,
"proc_macro_gen",
self.span,
GateIssue::Language,
- &format!("procedural macros cannot expand to {}", name),
+ &format!("procedural macros cannot expand to macro definitions"),
);
}
visit::walk_item(self, i);
ui
});
- OneVector::many(
+ OneVector::from_iter(
self.fold_unnameable(item).into_iter()
.chain(self.fold_unnameable(use_item)))
} else {
use util::move_map::MoveMap;
use rustc_data_structures::sync::Lrc;
+ use rustc_data_structures::small_vec::ExpectOne;
pub trait Folder : Sized {
// Any additions to this trait should happen in form
pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T)
-> OneVector<TraitItem> {
- OneVector::one(TraitItem {
+ smallvec![TraitItem {
id: folder.new_id(i.id),
ident: folder.fold_ident(i.ident),
attrs: fold_attrs(i.attrs, folder),
},
span: folder.new_span(i.span),
tokens: i.tokens,
- })
+ }]
}
pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)
-> OneVector<ImplItem> {
- OneVector::one(ImplItem {
+ smallvec![ImplItem {
id: folder.new_id(i.id),
vis: folder.fold_vis(i.vis),
ident: folder.fold_ident(i.ident),
},
span: folder.new_span(i.span),
tokens: i.tokens,
- })
+ }]
}
pub fn noop_fold_fn_header<T: Folder>(mut header: FnHeader, folder: &mut T) -> FnHeader {
// fold one item into possibly many items
pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> OneVector<P<Item>> {
- OneVector::one(i.map(|i| folder.fold_item_simple(i)))
+ smallvec![i.map(|i| folder.fold_item_simple(i))]
}
// fold one item into exactly one item
pub fn noop_fold_foreign_item<T: Folder>(ni: ForeignItem, folder: &mut T)
-> OneVector<ForeignItem> {
- OneVector::one(folder.fold_foreign_item_simple(ni))
+ smallvec![folder.fold_foreign_item_simple(ni)]
}
pub fn noop_fold_foreign_item_simple<T: Folder>(ni: ForeignItem, folder: &mut T) -> ForeignItem {
}
ExprKind::Yield(ex) => ExprKind::Yield(ex.map(|x| folder.fold_expr(x))),
ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
- ExprKind::Catch(body) => ExprKind::Catch(folder.fold_block(body)),
+ ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)),
},
id: folder.new_id(id),
span: folder.new_span(span),
pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> OneVector<StmtKind> {
match node {
- StmtKind::Local(local) => OneVector::one(StmtKind::Local(folder.fold_local(local))),
+ StmtKind::Local(local) => smallvec![StmtKind::Local(folder.fold_local(local))],
StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),
StmtKind::Expr(expr) => {
folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect()
StmtKind::Semi(expr) => {
folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect()
}
- StmtKind::Mac(mac) => OneVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
+ StmtKind::Mac(mac) => smallvec![StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
(folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
- }))),
+ }))],
}
}
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(str_escape)]
+#![feature(try_trait)]
#![feature(unicode_internals)]
-#![feature(catch_expr)]
#![recursion_limit="256"]
extern crate rustc_data_structures;
extern crate rustc_target;
#[macro_use] extern crate scoped_tls;
+ #[macro_use]
+ extern crate smallvec;
extern crate serialize as rustc_serialize; // used by deriving