Skip to content

Commit

Permalink
Abstract away differences between Vec and ptr::P in HIR
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 17, 2015
1 parent 0d298f9 commit 6c87b19
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 184 deletions.
8 changes: 4 additions & 4 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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!()
},
Expand All @@ -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())
}

_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>

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),
_ => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P<hir::Expr>>) {
fn consume_exprs(&mut self, exprs: &[P<hir::Expr>]) {
for expr in exprs {
self.consume_expr(&**expr);
}
Expand Down Expand Up @@ -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<hir::Field>,
fields: &[hir::Field],
opt_with: &Option<P<hir::Expr>>) {
// Consume the expressions supplying values for each field.
for field in fields {
Expand Down Expand Up @@ -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<hir::Field>)
fields: &[hir::Field])
-> bool
{
fields.iter().any(
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&lt.lifetime.name) ||
Expand All @@ -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,
}
Expand All @@ -1274,7 +1274,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
lifetime: hir::Lifetime,
anon_nums: &HashSet<u32>,
region_names: &HashSet<ast::Name>)
-> Vec<hir::Arg> {
-> hir::HirVec<hir::Arg> {
let mut new_inputs = Vec::new();
for arg in inputs {
let new_ty = self.rebuild_arg_ty_or_output(&*arg.ty, lifetime,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
})
Expand All @@ -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()
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<hir::LifetimeDef>, 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<hir::LifetimeDef>, 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> },
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -661,7 +661,7 @@ impl<'a> LifetimeContext<'a> {
lifetime_ref.name);
}

fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &Vec<hir::LifetimeDef>) {
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDef]) {
for i in 0..lifetimes.len() {
let lifetime_i = &lifetimes[i];

Expand Down Expand Up @@ -753,7 +753,7 @@ impl<'a> LifetimeContext<'a> {
}
}

fn search_lifetimes<'a>(lifetimes: &'a Vec<hir::LifetimeDef>,
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() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(&mut self, id: NodeId, attrs: &Vec<Attribute>,
fn annotate<F>(&mut self, id: NodeId, attrs: &[Attribute],
item_sp: Span, kind: AnnotationKind, visit_children: F)
where F: FnOnce(&mut Annotator)
{
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait Folder : Sized {
noop_fold_crate(c, self)
}

fn fold_meta_items(&mut self, meta_items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> {
fn fold_meta_items(&mut self, meta_items: HirVec<P<MetaItem>>) -> HirVec<P<MetaItem>> {
noop_fold_meta_items(meta_items, self)
}

Expand Down Expand Up @@ -198,11 +198,11 @@ pub trait Folder : Sized {
noop_fold_variant_data(vdata, self)
}

fn fold_lifetimes(&mut self, lts: Vec<Lifetime>) -> Vec<Lifetime> {
fn fold_lifetimes(&mut self, lts: HirVec<Lifetime>) -> HirVec<Lifetime> {
noop_fold_lifetimes(lts, self)
}

fn fold_lifetime_defs(&mut self, lts: Vec<LifetimeDef>) -> Vec<LifetimeDef> {
fn fold_lifetime_defs(&mut self, lts: HirVec<LifetimeDef>) -> HirVec<LifetimeDef> {
noop_fold_lifetime_defs(lts, self)
}

Expand Down Expand Up @@ -263,9 +263,9 @@ pub trait Folder : Sized {
}
}

pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>,
pub fn noop_fold_meta_items<T: Folder>(meta_items: HirVec<P<MetaItem>>,
fld: &mut T)
-> Vec<P<MetaItem>> {
-> HirVec<P<MetaItem>> {
meta_items.move_map(|x| fld.fold_meta_item(x))
}

Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
})
}

pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T) -> Vec<Attribute> {
pub fn fold_attrs<T: Folder>(attrs: HirVec<Attribute>, fld: &mut T) -> HirVec<Attribute> {
attrs.move_flat_map(|x| fld.fold_attribute(x))
}

Expand Down Expand Up @@ -477,7 +477,7 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
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()),
}
})
}
Expand Down Expand Up @@ -596,11 +596,13 @@ pub fn noop_fold_lifetime_def<T: Folder>(l: LifetimeDef, fld: &mut T) -> Lifetim
}
}

pub fn noop_fold_lifetimes<T: Folder>(lts: Vec<Lifetime>, fld: &mut T) -> Vec<Lifetime> {
pub fn noop_fold_lifetimes<T: Folder>(lts: HirVec<Lifetime>, fld: &mut T) -> HirVec<Lifetime> {
lts.move_map(|l| fld.fold_lifetime(l))
}

pub fn noop_fold_lifetime_defs<T: Folder>(lts: Vec<LifetimeDef>, fld: &mut T) -> Vec<LifetimeDef> {
pub fn noop_fold_lifetime_defs<T: Folder>(lts: HirVec<LifetimeDef>,
fld: &mut T)
-> HirVec<LifetimeDef> {
lts.move_map(|l| fld.fold_lifetime_def(l))
}

Expand Down Expand Up @@ -1139,7 +1141,7 @@ pub fn noop_fold_expr<T: Folder>(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()),
}
}

Expand Down
Loading

0 comments on commit 6c87b19

Please sign in to comment.