From 6c87b191580be9ecd5a99a34ef97375af0b9d659 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 17 Dec 2015 20:41:28 +0300 Subject: [PATCH] Abstract away differences between Vec and ptr::P in HIR --- src/librustc/middle/check_match.rs | 8 +- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/expr_use_visitor.rs | 6 +- src/librustc/middle/infer/error_reporting.rs | 12 +- src/librustc/middle/resolve_lifetime.rs | 10 +- src/librustc/middle/stability.rs | 2 +- src/librustc_front/fold.rs | 22 ++-- src/librustc_front/hir.rs | 132 +++++++++++-------- src/librustc_front/lib.rs | 1 + src/librustc_front/lowering.rs | 118 +++++++++-------- src/librustc_front/print/pprust.rs | 6 +- src/librustc_front/util.rs | 10 +- src/librustc_mir/hair/cx/pattern.rs | 6 +- src/librustc_trans/trans/consts.rs | 2 +- src/librustdoc/clean/mod.rs | 9 +- src/librustdoc/doctree.rs | 42 +++--- src/librustdoc/visit_ast.rs | 8 +- 17 files changed, 214 insertions(+), 184 deletions(-) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index ba4bdccb20b80..cab7e45ee6283 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -517,7 +517,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor, ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => { let v = adt.variant_of_ctor(ctor); if let VariantKind::Struct = v.kind() { - let field_pats: Vec<_> = v.fields.iter() + let field_pats: hir::HirVec<_> = v.fields.iter() .zip(pats) .filter(|&(_, ref pat)| pat.node != hir::PatWild) .map(|(field, pat)| Spanned { @@ -540,14 +540,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor, ty::TyArray(_, n) => match ctor { &Single => { assert_eq!(pats_len, n); - hir::PatVec(pats.collect(), None, vec!()) + hir::PatVec(pats.collect(), None, hir::HirVec::new()) }, _ => unreachable!() }, ty::TySlice(_) => match ctor { &Slice(n) => { assert_eq!(pats_len, n); - hir::PatVec(pats.collect(), None, vec!()) + hir::PatVec(pats.collect(), None, hir::HirVec::new()) }, _ => unreachable!() }, @@ -562,7 +562,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor, ty::TyArray(_, len) => { assert_eq!(pats_len, len); - hir::PatVec(pats.collect(), None, vec![]) + hir::PatVec(pats.collect(), None, hir::HirVec::new()) } _ => { diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f0cfd900fd75a..fb471fb6aaa4f 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -357,14 +357,14 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P hir::ExprVec(ref exprs) => { let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect(); - hir::PatVec(pats, None, vec![]) + hir::PatVec(pats, None, hir::HirVec::new()) } hir::ExprPath(_, ref path) => { let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def()); match opt_def { Some(def::DefStruct(..)) => - hir::PatStruct(path.clone(), vec![], false), + hir::PatStruct(path.clone(), hir::HirVec::new(), false), Some(def::DefVariant(..)) => hir::PatEnum(path.clone(), None), _ => { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 4861f0a6b6436..73776304bc846 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -324,7 +324,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { self.delegate.consume(consume_id, consume_span, cmt, mode); } - fn consume_exprs(&mut self, exprs: &Vec>) { + fn consume_exprs(&mut self, exprs: &[P]) { for expr in exprs { self.consume_expr(&**expr); } @@ -651,7 +651,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { fn walk_struct_expr(&mut self, _expr: &hir::Expr, - fields: &Vec, + fields: &[hir::Field], opt_with: &Option>) { // Consume the expressions supplying values for each field. for field in fields { @@ -697,7 +697,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { self.walk_expr(with_expr); fn contains_field_named(field: ty::FieldDef, - fields: &Vec) + fields: &[hir::Field]) -> bool { fields.iter().any( diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index d5ecb3f2e863f..2abf499185690 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -1254,7 +1254,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { let mut lifetimes = Vec::new(); for lt in add { lifetimes.push(hir::LifetimeDef { lifetime: *lt, - bounds: Vec::new() }); + bounds: hir::HirVec::new() }); } for lt in &generics.lifetimes { if keep.contains(<.lifetime.name) || @@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } } hir::Generics { - lifetimes: lifetimes, + lifetimes: lifetimes.into(), ty_params: ty_params, where_clause: where_clause, } @@ -1274,7 +1274,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { lifetime: hir::Lifetime, anon_nums: &HashSet, region_names: &HashSet) - -> Vec { + -> hir::HirVec { let mut new_inputs = Vec::new(); for arg in inputs { let new_ty = self.rebuild_arg_ty_or_output(&*arg.ty, lifetime, @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { }; new_inputs.push(possibly_new_arg); } - new_inputs + new_inputs.into() } fn rebuild_output(&self, ty: &hir::FunctionRetTy, @@ -1513,7 +1513,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } }); hir::AngleBracketedParameters(hir::AngleBracketedParameterData { - lifetimes: new_lts, + lifetimes: new_lts.into(), types: new_types, bindings: new_bindings, }) @@ -1529,7 +1529,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { hir::Path { span: path.span, global: path.global, - segments: new_segs + segments: new_segs.into() } } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 89fa76f2fa769..9b133c5401519 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -79,10 +79,10 @@ struct LifetimeContext<'a> { enum ScopeChain<'a> { /// EarlyScope(i, ['a, 'b, ...], s) extends s with early-bound /// lifetimes, assigning indexes 'a => i, 'b => i+1, ... etc. - EarlyScope(subst::ParamSpace, &'a Vec, Scope<'a>), + EarlyScope(subst::ParamSpace, &'a [hir::LifetimeDef], Scope<'a>), /// LateScope(['a, 'b, ...], s) extends s with late-bound /// lifetimes introduced by the declaration binder_id. - LateScope(&'a Vec, Scope<'a>), + LateScope(&'a [hir::LifetimeDef], Scope<'a>), /// lifetimes introduced by a fn are scoped to the call-site for that fn. FnScope { fn_id: ast::NodeId, body_id: ast::NodeId, s: Scope<'a> }, @@ -206,7 +206,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> { // a trait ref, which introduces a binding scope. match self.def_map.get(&ty.id).map(|d| (d.base_def, d.depth)) { Some((def::DefTrait(..), 0)) => { - self.with(LateScope(&Vec::new(), self.scope), |_, this| { + self.with(LateScope(&[], self.scope), |_, this| { this.visit_path(path, ty.id); }); } @@ -661,7 +661,7 @@ impl<'a> LifetimeContext<'a> { lifetime_ref.name); } - fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec) { + fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDef]) { for i in 0..lifetimes.len() { let lifetime_i = &lifetimes[i]; @@ -753,7 +753,7 @@ impl<'a> LifetimeContext<'a> { } } -fn search_lifetimes<'a>(lifetimes: &'a Vec, +fn search_lifetimes<'a>(lifetimes: &'a [hir::LifetimeDef], lifetime_ref: &hir::Lifetime) -> Option<(u32, &'a hir::Lifetime)> { for (i, lifetime_decl) in lifetimes.iter().enumerate() { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 8104d53fc936f..a41ee51fb5546 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -82,7 +82,7 @@ struct Annotator<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { // Determine the stability for a node based on its attributes and inherited // stability. The stability is recorded in the index and used as the parent. - fn annotate(&mut self, id: NodeId, attrs: &Vec, + fn annotate(&mut self, id: NodeId, attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, visit_children: F) where F: FnOnce(&mut Annotator) { diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index 0978c3f78e82f..784428cc114dc 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -34,7 +34,7 @@ pub trait Folder : Sized { noop_fold_crate(c, self) } - fn fold_meta_items(&mut self, meta_items: Vec>) -> Vec> { + fn fold_meta_items(&mut self, meta_items: HirVec>) -> HirVec> { noop_fold_meta_items(meta_items, self) } @@ -198,11 +198,11 @@ pub trait Folder : Sized { noop_fold_variant_data(vdata, self) } - fn fold_lifetimes(&mut self, lts: Vec) -> Vec { + fn fold_lifetimes(&mut self, lts: HirVec) -> HirVec { noop_fold_lifetimes(lts, self) } - fn fold_lifetime_defs(&mut self, lts: Vec) -> Vec { + fn fold_lifetime_defs(&mut self, lts: HirVec) -> HirVec { noop_fold_lifetime_defs(lts, self) } @@ -263,9 +263,9 @@ pub trait Folder : Sized { } } -pub fn noop_fold_meta_items(meta_items: Vec>, +pub fn noop_fold_meta_items(meta_items: HirVec>, fld: &mut T) - -> Vec> { + -> HirVec> { meta_items.move_map(|x| fld.fold_meta_item(x)) } @@ -304,7 +304,7 @@ pub fn noop_fold_view_path(view_path: P, fld: &mut T) -> P< }) } -pub fn fold_attrs(attrs: Vec, fld: &mut T) -> Vec { +pub fn fold_attrs(attrs: HirVec, fld: &mut T) -> HirVec { attrs.move_flat_map(|x| fld.fold_attribute(x)) } @@ -477,7 +477,7 @@ pub fn noop_fold_local(l: P, fld: &mut T) -> P { pat: fld.fold_pat(pat), init: init.map(|e| fld.fold_expr(e)), span: fld.new_span(span), - attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, fld)), + attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), fld).into()), } }) } @@ -596,11 +596,13 @@ pub fn noop_fold_lifetime_def(l: LifetimeDef, fld: &mut T) -> Lifetim } } -pub fn noop_fold_lifetimes(lts: Vec, fld: &mut T) -> Vec { +pub fn noop_fold_lifetimes(lts: HirVec, fld: &mut T) -> HirVec { lts.move_map(|l| fld.fold_lifetime(l)) } -pub fn noop_fold_lifetime_defs(lts: Vec, fld: &mut T) -> Vec { +pub fn noop_fold_lifetime_defs(lts: HirVec, + fld: &mut T) + -> HirVec { lts.move_map(|l| fld.fold_lifetime_def(l)) } @@ -1139,7 +1141,7 @@ pub fn noop_fold_expr(Expr { id, node, span, attrs }: Expr, folder: & } }, span: folder.new_span(span), - attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, folder)), + attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), folder).into()), } } diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 1491ecc89af1f..6b2664af60ba5 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -40,7 +40,7 @@ use std::collections::BTreeMap; use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId}; use syntax::abi::Abi; use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect}; -use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig}; +use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem}; use syntax::attr::ThinAttributes; use syntax::parse::token::InternedString; use syntax::ptr::P; @@ -52,6 +52,22 @@ use std::fmt; use std::hash::{Hash, Hasher}; use serialize::{Encodable, Decodable, Encoder, Decoder}; +/// HIR doesn't commit to a concrete storage type and have its own alias for a vector. +/// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar +/// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead +/// of `Vec` to avoid keeping extra capacity. +pub type HirVec = Vec; + +macro_rules! hir_vec { + ($elem:expr; $n:expr) => ( + $crate::hir::HirVec::from(vec![$elem; $n]) + ); + ($($x:expr),*) => ( + $crate::hir::HirVec::from(vec![$($x),*]) + ); + ($($x:expr,)*) => (vec![$($x),*]) +} + /// Identifier in HIR #[derive(Clone, Copy, Eq)] pub struct Ident { @@ -129,7 +145,7 @@ impl fmt::Debug for Lifetime { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct LifetimeDef { pub lifetime: Lifetime, - pub bounds: Vec, + pub bounds: HirVec, } /// A "Path" is essentially Rust's notion of a name; for instance: @@ -142,7 +158,7 @@ pub struct Path { /// module (like paths in an import). pub global: bool, /// The segments in the path: the things separated by `::`. - pub segments: Vec, + pub segments: HirVec, } impl fmt::Debug for Path { @@ -191,7 +207,7 @@ pub enum PathParameters { impl PathParameters { pub fn none() -> PathParameters { AngleBracketedParameters(AngleBracketedParameterData { - lifetimes: Vec::new(), + lifetimes: HirVec::new(), types: P::empty(), bindings: P::empty(), }) @@ -223,7 +239,7 @@ impl PathParameters { /// Returns the types that the user wrote. Note that these do not necessarily map to the type /// parameters in the parenthesized case. - pub fn types(&self) -> Vec<&P> { + pub fn types(&self) -> HirVec<&P> { match *self { AngleBracketedParameters(ref data) => { data.types.iter().collect() @@ -237,24 +253,24 @@ impl PathParameters { } } - pub fn lifetimes(&self) -> Vec<&Lifetime> { + pub fn lifetimes(&self) -> HirVec<&Lifetime> { match *self { AngleBracketedParameters(ref data) => { data.lifetimes.iter().collect() } ParenthesizedParameters(_) => { - Vec::new() + HirVec::new() } } } - pub fn bindings(&self) -> Vec<&TypeBinding> { + pub fn bindings(&self) -> HirVec<&TypeBinding> { match *self { AngleBracketedParameters(ref data) => { data.bindings.iter().collect() } ParenthesizedParameters(_) => { - Vec::new() + HirVec::new() } } } @@ -264,7 +280,7 @@ impl PathParameters { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. - pub lifetimes: Vec, + pub lifetimes: HirVec, /// The type parameters for this path segment, if present. pub types: P<[P]>, /// Bindings (equality constraints) on associated types, if present. @@ -285,7 +301,7 @@ pub struct ParenthesizedParameterData { pub span: Span, /// `(A,B)` - pub inputs: Vec>, + pub inputs: HirVec>, /// `C` pub output: Option>, @@ -324,7 +340,7 @@ pub struct TyParam { /// of a function, enum, trait, etc. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { - pub lifetimes: Vec, + pub lifetimes: HirVec, pub ty_params: P<[TyParam]>, pub where_clause: WhereClause, } @@ -345,7 +361,7 @@ impl Generics { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct WhereClause { pub id: NodeId, - pub predicates: Vec, + pub predicates: HirVec, } /// A single predicate in a `where` clause @@ -364,7 +380,7 @@ pub enum WherePredicate { pub struct WhereBoundPredicate { pub span: Span, /// Any lifetimes from a `for` binding - pub bound_lifetimes: Vec, + pub bound_lifetimes: HirVec, /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) @@ -376,7 +392,7 @@ pub struct WhereBoundPredicate { pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, - pub bounds: Vec, + pub bounds: HirVec, } /// An equality predicate (unsupported), e.g. `T=int` @@ -388,13 +404,15 @@ pub struct WhereEqPredicate { pub ty: P, } +pub type CrateConfig = HirVec>; + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] pub struct Crate { pub module: Mod, - pub attrs: Vec, + pub attrs: HirVec, pub config: CrateConfig, pub span: Span, - pub exported_macros: Vec, + pub exported_macros: HirVec, // NB: We use a BTreeMap here so that `visit_all_items` iterates // over the ids in increasing order. In principle it should not @@ -431,20 +449,20 @@ impl Crate { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct MacroDef { pub name: Name, - pub attrs: Vec, + pub attrs: HirVec, pub id: NodeId, pub span: Span, pub imported_from: Option, pub export: bool, pub use_locally: bool, pub allow_internal_unstable: bool, - pub body: Vec, + pub body: HirVec, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Block { /// Statements in a block - pub stmts: Vec, + pub stmts: HirVec, /// An expression at the end of the block /// without a semicolon, if any pub expr: Option>, @@ -503,7 +521,7 @@ pub enum Pat_ { PatIdent(BindingMode, Spanned, Option>), /// "None" means a `Variant(..)` pattern where we don't bind the fields to names. - PatEnum(Path, Option>>), + PatEnum(Path, Option>>), /// An associated const named using the qualified path `::CONST` or /// `::CONST`. Associated consts from inherent impls can be @@ -513,9 +531,9 @@ pub enum Pat_ { /// Destructuring of a struct, e.g. `Foo {x, y, ..}` /// The `bool` is `true` in the presence of a `..` - PatStruct(Path, Vec>, bool), + PatStruct(Path, HirVec>, bool), /// A tuple pattern `(a, b)` - PatTup(Vec>), + PatTup(HirVec>), /// A `box` pattern PatBox(P), /// A reference pattern, e.g. `&mut (a, b)` @@ -526,7 +544,7 @@ pub enum Pat_ { PatRange(P, P), /// `[a, b, ..i, y, z]` is represented as: /// `PatVec(box [a, b], Some(i), box [y, z])` - PatVec(Vec>, Option>, Vec>), + PatVec(HirVec>, Option>, HirVec>), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -640,8 +658,8 @@ pub enum Decl_ { /// represents one arm of a 'match' #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Arm { - pub attrs: Vec, - pub pats: Vec>, + pub attrs: HirVec, + pub pats: HirVec>, pub guard: Option>, pub body: P, } @@ -690,12 +708,12 @@ pub enum Expr_ { /// A `box x` expression. ExprBox(P), /// An array (`[a, b, c, d]`) - ExprVec(Vec>), + ExprVec(HirVec>), /// A function call /// /// The first field resolves to the function itself, /// and the second field is the list of arguments - ExprCall(P, Vec>), + ExprCall(P, HirVec>), /// A method call (`x.foo::(a, b, c, d)`) /// /// The `Spanned` is the identifier for the method name. @@ -708,9 +726,9 @@ pub enum Expr_ { /// /// Thus, `x.foo::(a, b, c, d)` is represented as /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. - ExprMethodCall(Spanned, Vec>, Vec>), + ExprMethodCall(Spanned, HirVec>, HirVec>), /// A tuple (`(a, b, c ,d)`) - ExprTup(Vec>), + ExprTup(HirVec>), /// A binary operation (For example: `a + b`, `a * b`) ExprBinary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) @@ -733,7 +751,7 @@ pub enum Expr_ { ExprLoop(P, Option), /// A `match` block, with a source that indicates whether or not it is /// the result of a desugaring, and if so, which kind. - ExprMatch(P, Vec, MatchSource), + ExprMatch(P, HirVec, MatchSource), /// A closure (for example, `move |a, b, c| {a + b + c}`) ExprClosure(CaptureClause, P, P), /// A block (`{ ... }`) @@ -760,7 +778,7 @@ pub enum Expr_ { /// parameters, e.g. foo::bar::. /// /// Optionally "qualified", - /// e.g. ` as SomeTrait>::SomeType`. + /// e.g. ` as SomeTrait>::SomeType`. ExprPath(Option, Path), /// A referencing operation (`&a` or `&mut a`) @@ -779,7 +797,7 @@ pub enum Expr_ { /// /// For example, `Foo {x: 1, y: 2}`, or /// `Foo {x: 1, .. base}`, where `base` is the `Option`. - ExprStruct(Path, Vec, Option>), + ExprStruct(Path, HirVec, Option>), /// A vector literal constructed from one repeated element. /// @@ -793,11 +811,11 @@ pub enum Expr_ { /// separately. `position` represents the index of the associated /// item qualified with this Self type. /// -/// as a::b::Trait>::AssociatedItem +/// as a::b::Trait>::AssociatedItem /// ^~~~~ ~~~~~~~~~~~~~~^ /// ty position = 3 /// -/// >::AssociatedItem +/// >::AssociatedItem /// ^~~~~ ^ /// ty position = 0 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -850,7 +868,7 @@ pub struct MethodSig { pub struct TraitItem { pub id: NodeId, pub name: Name, - pub attrs: Vec, + pub attrs: HirVec, pub node: TraitItem_, pub span: Span, } @@ -867,7 +885,7 @@ pub struct ImplItem { pub id: NodeId, pub name: Name, pub vis: Visibility, - pub attrs: Vec, + pub attrs: HirVec, pub node: ImplItemKind, pub span: Span, } @@ -918,7 +936,7 @@ pub enum PrimTy { pub struct BareFnTy { pub unsafety: Unsafety, pub abi: Abi, - pub lifetimes: Vec, + pub lifetimes: HirVec, pub decl: P, } @@ -935,9 +953,9 @@ pub enum Ty_ { /// A bare function (e.g. `fn(usize) -> bool`) TyBareFn(P), /// A tuple (`(A, B, C, D,...)`) - TyTup(Vec>), + TyTup(HirVec>), /// A path (`module::module::...::Type`), optionally - /// "qualified", e.g. ` as SomeTrait>::SomeType`. + /// "qualified", e.g. ` as SomeTrait>::SomeType`. /// /// Type parameters are stored in the Path itself TyPath(Option, Path), @@ -964,9 +982,9 @@ pub struct InlineAsmOutput { pub struct InlineAsm { pub asm: InternedString, pub asm_str_style: StrStyle, - pub outputs: Vec, - pub inputs: Vec<(InternedString, P)>, - pub clobbers: Vec, + pub outputs: HirVec, + pub inputs: HirVec<(InternedString, P)>, + pub clobbers: HirVec, pub volatile: bool, pub alignstack: bool, pub dialect: AsmDialect, @@ -1007,7 +1025,7 @@ impl Arg { /// Represents the header (not the body) of a function declaration #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct FnDecl { - pub inputs: Vec, + pub inputs: HirVec, pub output: FunctionRetTy, pub variadic: bool, } @@ -1098,24 +1116,24 @@ pub struct Mod { /// For `mod foo;`, the inner span ranges from the first token /// to the last token in the external file. pub inner: Span, - pub item_ids: Vec, + pub item_ids: HirVec, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ForeignMod { pub abi: Abi, - pub items: Vec, + pub items: HirVec, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct EnumDef { - pub variants: Vec, + pub variants: HirVec, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Variant_ { pub name: Name, - pub attrs: Vec, + pub attrs: HirVec, pub data: VariantData, /// Explicit discriminant, eg `Foo = 1` pub disr_expr: Option>, @@ -1176,7 +1194,7 @@ pub enum ViewPath_ { ViewPathGlob(Path), /// `foo::bar::{a,b,c}` - ViewPathList(Path, Vec), + ViewPathList(Path, HirVec), } /// TraitRef's appear in impls. @@ -1194,7 +1212,7 @@ pub struct TraitRef { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct PolyTraitRef { /// The `'a` in `<'a> Foo<&'a T>` - pub bound_lifetimes: Vec, + pub bound_lifetimes: HirVec, /// The `Foo<&'a T>` in `<'a> Foo<&'a T>` pub trait_ref: TraitRef, @@ -1222,7 +1240,7 @@ pub struct StructField_ { pub kind: StructFieldKind, pub id: NodeId, pub ty: P, - pub attrs: Vec, + pub attrs: HirVec, } impl StructField_ { @@ -1271,8 +1289,8 @@ impl StructFieldKind { /// Id of the whole struct lives in `Item`. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum VariantData { - Struct(Vec, NodeId), - Tuple(Vec, NodeId), + Struct(HirVec, NodeId), + Tuple(HirVec, NodeId), Unit(NodeId), } @@ -1327,7 +1345,7 @@ pub struct ItemId { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Item { pub name: Name, - pub attrs: Vec, + pub attrs: HirVec, pub id: NodeId, pub node: Item_, pub vis: Visibility, @@ -1360,7 +1378,7 @@ pub enum Item_ { /// A struct definition, e.g. `struct Foo {x: A}` ItemStruct(VariantData, Generics), /// Represents a Trait Declaration - ItemTrait(Unsafety, Generics, TyParamBounds, Vec), + ItemTrait(Unsafety, Generics, TyParamBounds, HirVec), // Default trait implementations /// @@ -1372,7 +1390,7 @@ pub enum Item_ { Generics, Option, // (optional) trait this impl implements P, // self - Vec), + HirVec), } impl Item_ { @@ -1398,7 +1416,7 @@ impl Item_ { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ForeignItem { pub name: Name, - pub attrs: Vec, + pub attrs: HirVec, pub node: ForeignItem_, pub id: NodeId, pub span: Span, diff --git a/src/librustc_front/lib.rs b/src/librustc_front/lib.rs index 3bfa645afc7d9..60080854a6f17 100644 --- a/src/librustc_front/lib.rs +++ b/src/librustc_front/lib.rs @@ -47,6 +47,7 @@ extern crate rustc_bitflags; extern crate serialize as rustc_serialize; // used by deriving +#[macro_use] pub mod hir; pub mod lowering; pub mod fold; diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 614f6f0bd36dd..db30ee9a5d2d3 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -147,6 +147,10 @@ pub fn lower_ident(_lctx: &LoweringContext, ident: Ident) -> hir::Ident { } } +pub fn lower_attrs(_lctx: &LoweringContext, attrs: &Vec) -> hir::HirVec { + attrs.clone().into() +} + pub fn lower_view_path(lctx: &LoweringContext, view_path: &ViewPath) -> P { P(Spanned { node: match view_path.node { @@ -186,7 +190,7 @@ pub fn lower_view_path(lctx: &LoweringContext, view_path: &ViewPath) -> P hir::Arm { hir::Arm { - attrs: arm.attrs.clone(), + attrs: lower_attrs(lctx, &arm.attrs), pats: arm.pats.iter().map(|x| lower_pat(lctx, x)).collect(), guard: arm.guard.as_ref().map(|ref x| lower_expr(lctx, x)), body: lower_expr(lctx, &arm.body), @@ -275,7 +279,7 @@ pub fn lower_variant(lctx: &LoweringContext, v: &Variant) -> hir::Variant { Spanned { node: hir::Variant_ { name: v.node.name.name, - attrs: v.node.attrs.clone(), + attrs: lower_attrs(lctx, &v.node.attrs), data: lower_variant_data(lctx, &v.node.data), disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(lctx, e)), }, @@ -449,13 +453,13 @@ pub fn lower_lifetime_def(lctx: &LoweringContext, l: &LifetimeDef) -> hir::Lifet } } -pub fn lower_lifetimes(lctx: &LoweringContext, lts: &Vec) -> Vec { +pub fn lower_lifetimes(lctx: &LoweringContext, lts: &Vec) -> hir::HirVec { lts.iter().map(|l| lower_lifetime(lctx, l)).collect() } pub fn lower_lifetime_defs(lctx: &LoweringContext, lts: &Vec) - -> Vec { + -> hir::HirVec { lts.iter().map(|l| lower_lifetime_def(lctx, l)).collect() } @@ -560,7 +564,7 @@ pub fn lower_struct_field(lctx: &LoweringContext, f: &StructField) -> hir::Struc id: f.node.id, kind: lower_struct_field_kind(lctx, &f.node.kind), ty: lower_ty(lctx, &f.node.ty), - attrs: f.node.attrs.clone(), + attrs: lower_attrs(lctx, &f.node.attrs), }, span: f.span, } @@ -673,7 +677,7 @@ pub fn lower_trait_item(lctx: &LoweringContext, i: &TraitItem) -> hir::TraitItem hir::TraitItem { id: i.id, name: i.ident.name, - attrs: i.attrs.clone(), + attrs: lower_attrs(lctx, &i.attrs), node: match i.node { ConstTraitItem(ref ty, ref default) => { hir::ConstTraitItem(lower_ty(lctx, ty), @@ -696,7 +700,7 @@ pub fn lower_impl_item(lctx: &LoweringContext, i: &ImplItem) -> hir::ImplItem { hir::ImplItem { id: i.id, name: i.ident.name, - attrs: i.attrs.clone(), + attrs: lower_attrs(lctx, &i.attrs), vis: lower_visibility(lctx, i.vis), node: match i.node { ImplItemKind::Const(ref ty, ref expr) => { @@ -740,25 +744,25 @@ pub fn lower_crate(lctx: &LoweringContext, c: &Crate) -> hir::Crate { hir::Crate { module: lower_mod(lctx, &c.module), - attrs: c.attrs.clone(), - config: c.config.clone(), + attrs: lower_attrs(lctx, &c.attrs), + config: c.config.clone().into(), span: c.span, exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(lctx, m)).collect(), items: items, } } -pub fn lower_macro_def(_lctx: &LoweringContext, m: &MacroDef) -> hir::MacroDef { +pub fn lower_macro_def(lctx: &LoweringContext, m: &MacroDef) -> hir::MacroDef { hir::MacroDef { name: m.ident.name, - attrs: m.attrs.clone(), + attrs: lower_attrs(lctx, &m.attrs), id: m.id, span: m.span, imported_from: m.imported_from.map(|x| x.name), export: m.export, use_locally: m.use_locally, allow_internal_unstable: m.allow_internal_unstable, - body: m.body.clone(), + body: m.body.clone().into(), } } @@ -772,7 +776,7 @@ pub fn lower_item(lctx: &LoweringContext, i: &Item) -> hir::Item { hir::Item { id: i.id, name: i.ident.name, - attrs: i.attrs.clone(), + attrs: lower_attrs(lctx, &i.attrs), node: node, vis: lower_visibility(lctx, i.vis), span: i.span, @@ -783,7 +787,7 @@ pub fn lower_foreign_item(lctx: &LoweringContext, i: &ForeignItem) -> hir::Forei hir::ForeignItem { id: i.id, name: i.ident.name, - attrs: i.attrs.clone(), + attrs: lower_attrs(lctx, &i.attrs), node: match i.node { ForeignItemFn(ref fdec, ref generics) => { hir::ForeignItemFn(lower_fn_decl(lctx, fdec), lower_generics(lctx, generics)) @@ -1020,7 +1024,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // let placer = ; let s1 = { let placer_expr = signal_block_expr(lctx, - vec![], + hir_vec![], placer_expr, e.span, hir::PopUnstableBlock, @@ -1031,14 +1035,14 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // let mut place = Placer::make_place(placer); let s2 = { let placer = expr_ident(lctx, e.span, placer_ident, None); - let call = make_call(lctx, &make_place, vec![placer]); + let call = make_call(lctx, &make_place, hir_vec![placer]); mk_stmt_let_mut(lctx, place_ident, call) }; // let p_ptr = Place::pointer(&mut place); let s3 = { let agent = expr_ident(lctx, e.span, place_ident, None); - let args = vec![expr_mut_addr_of(lctx, e.span, agent, None)]; + let args = hir_vec![expr_mut_addr_of(lctx, e.span, agent, None)]; let call = make_call(lctx, &place_pointer, args); mk_stmt_let(lctx, p_ptr_ident, call) }; @@ -1046,13 +1050,13 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // pop_unsafe!(EXPR)); let pop_unsafe_expr = { let value_expr = signal_block_expr(lctx, - vec![], + hir_vec![], value_expr, e.span, hir::PopUnstableBlock, None); signal_block_expr(lctx, - vec![], + hir_vec![], value_expr, e.span, hir::PopUnsafeBlock(hir::CompilerGenerated), None) @@ -1066,21 +1070,21 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let ptr = expr_ident(lctx, e.span, p_ptr_ident, None); let call_move_val_init = hir::StmtSemi( - make_call(lctx, &move_val_init, vec![ptr, pop_unsafe_expr]), + make_call(lctx, &move_val_init, hir_vec![ptr, pop_unsafe_expr]), lctx.next_id()); let call_move_val_init = respan(e.span, call_move_val_init); let place = expr_ident(lctx, e.span, place_ident, None); - let call = make_call(lctx, &inplace_finalize, vec![place]); + let call = make_call(lctx, &inplace_finalize, hir_vec![place]); signal_block_expr(lctx, - vec![call_move_val_init], + hir_vec![call_move_val_init], call, e.span, hir::PushUnsafeBlock(hir::CompilerGenerated), None) }; signal_block_expr(lctx, - vec![s1, s2, s3], + hir_vec![s1, s2, s3], expr, e.span, hir::PushUnstableBlock, @@ -1141,7 +1145,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let els = lower_expr(lctx, els); let id = lctx.next_id(); let blk = P(hir::Block { - stmts: vec![], + stmts: hir_vec![], expr: Some(els), id: id, rules: hir::DefaultBlock, @@ -1238,7 +1242,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { .collect(), asm: asm.clone(), asm_str_style: asm_str_style, - clobbers: clobbers.clone(), + clobbers: clobbers.clone().into(), volatile: volatile, alignstack: alignstack, dialect: dialect, @@ -1275,7 +1279,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let pat_arm = { let body = lower_block(lctx, body); let body_expr = expr_block(lctx, body, None); - arm(vec![lower_pat(lctx, pat)], body_expr) + arm(hir_vec![lower_pat(lctx, pat)], body_expr) }; // `[_ if => ,]` @@ -1290,8 +1294,8 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { hir::ExprIf(cond, then, else_opt) => { let pat_under = pat_wild(lctx, e.span); arms.push(hir::Arm { - attrs: vec![], - pats: vec![pat_under], + attrs: hir_vec![], + pats: hir_vec![pat_under], guard: Some(cond), body: expr_block(lctx, then, None), }); @@ -1325,8 +1329,8 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let pat_under = pat_wild(lctx, e.span); let else_expr = else_opt.unwrap_or_else( - || expr_tuple(lctx, e.span, vec![], None)); - arm(vec![pat_under], else_expr) + || expr_tuple(lctx, e.span, hir_vec![], None)); + arm(hir_vec![pat_under], else_expr) }; let mut arms = Vec::with_capacity(else_if_arms.len() + 2); @@ -1339,7 +1343,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { expr(lctx, e.span, hir::ExprMatch(sub_expr, - arms, + arms.into(), hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause, }), @@ -1364,18 +1368,18 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let pat_arm = { let body = lower_block(lctx, body); let body_expr = expr_block(lctx, body, None); - arm(vec![lower_pat(lctx, pat)], body_expr) + arm(hir_vec![lower_pat(lctx, pat)], body_expr) }; // `_ => break` let break_arm = { let pat_under = pat_wild(lctx, e.span); let break_expr = expr_break(lctx, e.span, None); - arm(vec![pat_under], break_expr) + arm(hir_vec![pat_under], break_expr) }; // `match { ... }` - let arms = vec![pat_arm, break_arm]; + let arms = hir_vec![pat_arm, break_arm]; let sub_expr = lower_expr(lctx, sub_expr); let match_expr = expr(lctx, e.span, @@ -1431,14 +1435,14 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let pat = lower_pat(lctx, pat); let some_pat = pat_some(lctx, e.span, pat); - arm(vec![some_pat], body_expr) + arm(hir_vec![some_pat], body_expr) }; // `::std::option::Option::None => break` let break_arm = { let break_expr = expr_break(lctx, e.span, None); - arm(vec![pat_none(lctx, e.span)], break_expr) + arm(hir_vec![pat_none(lctx, e.span)], break_expr) }; // `match ::std::iter::Iterator::next(&mut iter) { ... }` @@ -1454,9 +1458,9 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let next_expr = expr_call(lctx, e.span, next_path, - vec![ref_mut_iter], + hir_vec![ref_mut_iter], None); - let arms = vec![pat_arm, break_arm]; + let arms = hir_vec![pat_arm, break_arm]; expr(lctx, e.span, @@ -1476,7 +1480,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { e.span, iter, hir::BindByValue(hir::MutMutable)); - arm(vec![iter_pat], loop_expr) + arm(hir_vec![iter_pat], loop_expr) }; // `match ::std::iter::IntoIterator::into_iter() { ... }` @@ -1488,13 +1492,13 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { }; let into_iter = expr_path(lctx, into_iter_path, None); - expr_call(lctx, e.span, into_iter, vec![head], None) + expr_call(lctx, e.span, into_iter, hir_vec![head], None) }; let match_expr = expr_match(lctx, e.span, into_iter_expr, - vec![iter_arm], + hir_vec![iter_arm], hir::MatchSource::ForLoopDesugar, None); @@ -1502,7 +1506,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { let result_ident = lctx.str_to_ident("result"); let let_stmt = stmt_let(lctx, e.span, false, result_ident, match_expr, None); let result = expr_ident(lctx, e.span, result_ident, None); - let block = block_all(lctx, e.span, vec![let_stmt], Some(result)); + let block = block_all(lctx, e.span, hir_vec![let_stmt], Some(result)); // add the attributes to the outer returned expr node expr_block(lctx, block, e.attrs.clone()) }); @@ -1601,9 +1605,9 @@ pub fn lower_trait_bound_modifier(_lctx: &LoweringContext, // Helper methods for building HIR. -fn arm(pats: Vec>, expr: P) -> hir::Arm { +fn arm(pats: hir::HirVec>, expr: P) -> hir::Arm { hir::Arm { - attrs: vec![], + attrs: hir_vec![], pats: pats, guard: None, body: expr, @@ -1618,7 +1622,7 @@ fn expr_break(lctx: &LoweringContext, span: Span, fn expr_call(lctx: &LoweringContext, span: Span, e: P, - args: Vec>, + args: hir::HirVec>, attrs: ThinAttributes) -> P { expr(lctx, span, hir::ExprCall(e, args), attrs) @@ -1642,7 +1646,7 @@ fn expr_path(lctx: &LoweringContext, path: hir::Path, fn expr_match(lctx: &LoweringContext, span: Span, arg: P, - arms: Vec, + arms: hir::HirVec, source: hir::MatchSource, attrs: ThinAttributes) -> P { @@ -1654,7 +1658,7 @@ fn expr_block(lctx: &LoweringContext, b: P, expr(lctx, b.span, hir::ExprBlock(b), attrs) } -fn expr_tuple(lctx: &LoweringContext, sp: Span, exprs: Vec>, +fn expr_tuple(lctx: &LoweringContext, sp: Span, exprs: hir::HirVec>, attrs: ThinAttributes) -> P { expr(lctx, sp, hir::ExprTup(exprs), attrs) } @@ -1694,12 +1698,12 @@ fn stmt_let(lctx: &LoweringContext, } fn block_expr(lctx: &LoweringContext, expr: P) -> P { - block_all(lctx, expr.span, Vec::new(), Some(expr)) + block_all(lctx, expr.span, hir::HirVec::new(), Some(expr)) } fn block_all(lctx: &LoweringContext, span: Span, - stmts: Vec, + stmts: hir::HirVec, expr: Option>) -> P { P(hir::Block { @@ -1714,19 +1718,19 @@ fn block_all(lctx: &LoweringContext, fn pat_some(lctx: &LoweringContext, span: Span, pat: P) -> P { let some = std_path(lctx, &["option", "Option", "Some"]); let path = path_global(span, some); - pat_enum(lctx, span, path, vec![pat]) + pat_enum(lctx, span, path, hir_vec![pat]) } fn pat_none(lctx: &LoweringContext, span: Span) -> P { let none = std_path(lctx, &["option", "Option", "None"]); let path = path_global(span, none); - pat_enum(lctx, span, path, vec![]) + pat_enum(lctx, span, path, hir_vec![]) } fn pat_enum(lctx: &LoweringContext, span: Span, path: hir::Path, - subpats: Vec>) + subpats: hir::HirVec>) -> P { let pt = hir::PatEnum(path, Some(subpats)); pat(lctx, span, pt) @@ -1767,17 +1771,17 @@ fn path_ident(span: Span, id: hir::Ident) -> hir::Path { } fn path(span: Span, strs: Vec) -> hir::Path { - path_all(span, false, strs, Vec::new(), Vec::new(), Vec::new()) + path_all(span, false, strs, hir::HirVec::new(), Vec::new(), Vec::new()) } fn path_global(span: Span, strs: Vec) -> hir::Path { - path_all(span, true, strs, Vec::new(), Vec::new(), Vec::new()) + path_all(span, true, strs, hir::HirVec::new(), Vec::new(), Vec::new()) } fn path_all(sp: Span, global: bool, mut idents: Vec, - lifetimes: Vec, + lifetimes: hir::HirVec, types: Vec>, bindings: Vec) -> hir::Path { @@ -1801,7 +1805,7 @@ fn path_all(sp: Span, hir::Path { span: sp, global: global, - segments: segments, + segments: segments.into(), } } @@ -1822,7 +1826,7 @@ fn core_path(lctx: &LoweringContext, span: Span, components: &[&str]) -> hir::Pa } fn signal_block_expr(lctx: &LoweringContext, - stmts: Vec, + stmts: hir::HirVec, expr: P, span: Span, rule: hir::BlockCheckMode, diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index a3bb005dfbdca..c4c5b9170f6bf 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -521,7 +521,7 @@ impl<'a> State<'a> { ty_params: P::empty(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, - predicates: Vec::new(), + predicates: hir::HirVec::new(), }, }; try!(self.print_ty_fn(f.abi, f.unsafety, &*f.decl, None, &generics, None)); @@ -2256,11 +2256,11 @@ impl<'a> State<'a> { try!(self.print_generics(generics)); } let generics = hir::Generics { - lifetimes: Vec::new(), + lifetimes: hir::HirVec::new(), ty_params: P::empty(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, - predicates: Vec::new(), + predicates: hir::HirVec::new(), }, }; try!(self.print_fn(decl, diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs index f85eb2bb4011e..298904d1e0d7a 100644 --- a/src/librustc_front/util.rs +++ b/src/librustc_front/util.rs @@ -334,11 +334,11 @@ pub fn is_path(e: P) -> bool { pub fn empty_generics() -> Generics { Generics { - lifetimes: Vec::new(), + lifetimes: HirVec::new(), ty_params: P::empty(), where_clause: WhereClause { id: DUMMY_NODE_ID, - predicates: Vec::new(), + predicates: HirVec::new(), }, } } @@ -349,13 +349,13 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path { hir::Path { span: s, global: false, - segments: vec!(hir::PathSegment { + segments: hir_vec![hir::PathSegment { identifier: ident, parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData { - lifetimes: Vec::new(), + lifetimes: HirVec::new(), types: P::empty(), bindings: P::empty(), }), - }), + }], } } diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs index 74fef68400656..64a86373ee1e5 100644 --- a/src/librustc_mir/hair/cx/pattern.rs +++ b/src/librustc_mir/hair/cx/pattern.rs @@ -252,7 +252,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> { } } - fn to_pats(&mut self, pats: &'tcx Vec>) -> Vec> { + fn to_pats(&mut self, pats: &'tcx [P]) -> Vec> { pats.iter().map(|p| self.to_pat(p)).collect() } @@ -263,9 +263,9 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> { fn slice_or_array_pattern(&mut self, pat: &'tcx hir::Pat, ty: Ty<'tcx>, - prefix: &'tcx Vec>, + prefix: &'tcx [P], slice: &'tcx Option>, - suffix: &'tcx Vec>) + suffix: &'tcx [P]) -> PatternKind<'tcx> { match ty.sty { ty::TySlice(..) => { diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 77664f19aac2a..2a9b675d8767d 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -1038,7 +1038,7 @@ pub fn trans_static(ccx: &CrateContext, m: hir::Mutability, expr: &hir::Expr, id: ast::NodeId, - attrs: &Vec) + attrs: &[ast::Attribute]) -> Result { unsafe { let _icx = push_ctxt("trans_static"); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e217e7afad737..675eef637b10b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1584,8 +1584,13 @@ impl Clean for hir::Ty { resolve_type(cx, p.clean(cx), self.id) } TyPath(Some(ref qself), ref p) => { - let mut trait_path = p.clone(); - trait_path.segments.pop(); + let mut segments: Vec<_> = p.segments.clone().into(); + segments.pop(); + let trait_path = hir::Path { + span: p.span, + global: p.global, + segments: segments.into(), + }; Type::QPath { name: p.segments.last().unwrap().identifier.name.clean(cx), self_type: box qself.ty.clean(cx), diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index d1030a6fcb07c..fc0422b3a3f03 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -24,7 +24,7 @@ use rustc_front::hir; pub struct Module { pub name: Option, - pub attrs: Vec, + pub attrs: hir::HirVec, pub where_outer: Span, pub where_inner: Span, pub extern_crates: Vec, @@ -58,7 +58,7 @@ impl Module { depr: None, where_outer: syntax::codemap::DUMMY_SP, where_inner: syntax::codemap::DUMMY_SP, - attrs : Vec::new(), + attrs : hir::HirVec::new(), extern_crates: Vec::new(), imports : Vec::new(), structs : Vec::new(), @@ -103,8 +103,8 @@ pub struct Struct { pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, - pub attrs: Vec, - pub fields: Vec, + pub attrs: hir::HirVec, + pub fields: hir::HirVec, pub whence: Span, } @@ -112,9 +112,9 @@ pub struct Enum { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub variants: Vec, + pub variants: hir::HirVec, pub generics: hir::Generics, - pub attrs: Vec, + pub attrs: hir::HirVec, pub id: NodeId, pub whence: Span, pub name: Name, @@ -122,7 +122,7 @@ pub struct Enum { pub struct Variant { pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub def: hir::VariantData, pub stab: Option, pub depr: Option, @@ -131,7 +131,7 @@ pub struct Variant { pub struct Function { pub decl: hir::FnDecl, - pub attrs: Vec, + pub attrs: hir::HirVec, pub id: NodeId, pub name: Name, pub vis: hir::Visibility, @@ -149,7 +149,7 @@ pub struct Typedef { pub gen: hir::Generics, pub name: Name, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, @@ -162,7 +162,7 @@ pub struct Static { pub mutability: hir::Mutability, pub expr: P, pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, @@ -174,7 +174,7 @@ pub struct Constant { pub type_: P, pub expr: P, pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, @@ -185,10 +185,10 @@ pub struct Constant { pub struct Trait { pub unsafety: hir::Unsafety, pub name: Name, - pub items: Vec, + pub items: hir::HirVec, pub generics: hir::Generics, - pub bounds: Vec, - pub attrs: Vec, + pub bounds: hir::HirVec, + pub attrs: hir::HirVec, pub id: ast::NodeId, pub whence: Span, pub vis: hir::Visibility, @@ -202,8 +202,8 @@ pub struct Impl { pub generics: hir::Generics, pub trait_: Option, pub for_: P, - pub items: Vec, - pub attrs: Vec, + pub items: hir::HirVec, + pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, @@ -215,16 +215,16 @@ pub struct DefaultImpl { pub unsafety: hir::Unsafety, pub trait_: hir::TraitRef, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, } pub struct Macro { pub name: Name, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, - pub matchers: Vec, + pub matchers: hir::HirVec, pub stab: Option, pub depr: Option, pub imported_from: Option, @@ -234,14 +234,14 @@ pub struct ExternCrate { pub name: Name, pub path: Option, pub vis: hir::Visibility, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, } pub struct Import { pub id: NodeId, pub vis: hir::Visibility, - pub attrs: Vec, + pub attrs: hir::HirVec, pub node: hir::ViewPath_, pub whence: Span, } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d95a4553bf1f5..ba389bc42b78c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -38,7 +38,7 @@ use doctree::*; pub struct RustdocVisitor<'a, 'tcx: 'a> { pub module: Module, - pub attrs: Vec, + pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx>, pub analysis: Option<&'a core::CrateAnalysis>, view_item_stack: HashSet, @@ -53,7 +53,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { stack.insert(ast::CRATE_NODE_ID); RustdocVisitor { module: Module::new(None), - attrs: Vec::new(), + attrs: hir::HirVec::new(), cx: cx, analysis: analysis, view_item_stack: stack, @@ -157,7 +157,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec , + pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec, vis: hir::Visibility, id: ast::NodeId, m: &hir::Mod, name: Option) -> Module { @@ -192,7 +192,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let mine = paths.into_iter().filter(|path| { !self.resolve_id(path.node.id(), None, false, om, please_inline) - }).collect::>(); + }).collect::>(); if mine.is_empty() { None