Skip to content

Commit 6c87b19

Browse files
committed
Abstract away differences between Vec and ptr::P in HIR
1 parent 0d298f9 commit 6c87b19

File tree

17 files changed

+214
-184
lines changed

17 files changed

+214
-184
lines changed

src/librustc/middle/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
517517
ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => {
518518
let v = adt.variant_of_ctor(ctor);
519519
if let VariantKind::Struct = v.kind() {
520-
let field_pats: Vec<_> = v.fields.iter()
520+
let field_pats: hir::HirVec<_> = v.fields.iter()
521521
.zip(pats)
522522
.filter(|&(_, ref pat)| pat.node != hir::PatWild)
523523
.map(|(field, pat)| Spanned {
@@ -540,14 +540,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
540540
ty::TyArray(_, n) => match ctor {
541541
&Single => {
542542
assert_eq!(pats_len, n);
543-
hir::PatVec(pats.collect(), None, vec!())
543+
hir::PatVec(pats.collect(), None, hir::HirVec::new())
544544
},
545545
_ => unreachable!()
546546
},
547547
ty::TySlice(_) => match ctor {
548548
&Slice(n) => {
549549
assert_eq!(pats_len, n);
550-
hir::PatVec(pats.collect(), None, vec!())
550+
hir::PatVec(pats.collect(), None, hir::HirVec::new())
551551
},
552552
_ => unreachable!()
553553
},
@@ -562,7 +562,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
562562

563563
ty::TyArray(_, len) => {
564564
assert_eq!(pats_len, len);
565-
hir::PatVec(pats.collect(), None, vec![])
565+
hir::PatVec(pats.collect(), None, hir::HirVec::new())
566566
}
567567

568568
_ => {

src/librustc/middle/const_eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
357357

358358
hir::ExprVec(ref exprs) => {
359359
let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect();
360-
hir::PatVec(pats, None, vec![])
360+
hir::PatVec(pats, None, hir::HirVec::new())
361361
}
362362

363363
hir::ExprPath(_, ref path) => {
364364
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
365365
match opt_def {
366366
Some(def::DefStruct(..)) =>
367-
hir::PatStruct(path.clone(), vec![], false),
367+
hir::PatStruct(path.clone(), hir::HirVec::new(), false),
368368
Some(def::DefVariant(..)) =>
369369
hir::PatEnum(path.clone(), None),
370370
_ => {

src/librustc/middle/expr_use_visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
324324
self.delegate.consume(consume_id, consume_span, cmt, mode);
325325
}
326326

327-
fn consume_exprs(&mut self, exprs: &Vec<P<hir::Expr>>) {
327+
fn consume_exprs(&mut self, exprs: &[P<hir::Expr>]) {
328328
for expr in exprs {
329329
self.consume_expr(&**expr);
330330
}
@@ -651,7 +651,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
651651

652652
fn walk_struct_expr(&mut self,
653653
_expr: &hir::Expr,
654-
fields: &Vec<hir::Field>,
654+
fields: &[hir::Field],
655655
opt_with: &Option<P<hir::Expr>>) {
656656
// Consume the expressions supplying values for each field.
657657
for field in fields {
@@ -697,7 +697,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
697697
self.walk_expr(with_expr);
698698

699699
fn contains_field_named(field: ty::FieldDef,
700-
fields: &Vec<hir::Field>)
700+
fields: &[hir::Field])
701701
-> bool
702702
{
703703
fields.iter().any(

src/librustc/middle/infer/error_reporting.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12541254
let mut lifetimes = Vec::new();
12551255
for lt in add {
12561256
lifetimes.push(hir::LifetimeDef { lifetime: *lt,
1257-
bounds: Vec::new() });
1257+
bounds: hir::HirVec::new() });
12581258
}
12591259
for lt in &generics.lifetimes {
12601260
if keep.contains(&lt.lifetime.name) ||
@@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12631263
}
12641264
}
12651265
hir::Generics {
1266-
lifetimes: lifetimes,
1266+
lifetimes: lifetimes.into(),
12671267
ty_params: ty_params,
12681268
where_clause: where_clause,
12691269
}
@@ -1274,7 +1274,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12741274
lifetime: hir::Lifetime,
12751275
anon_nums: &HashSet<u32>,
12761276
region_names: &HashSet<ast::Name>)
1277-
-> Vec<hir::Arg> {
1277+
-> hir::HirVec<hir::Arg> {
12781278
let mut new_inputs = Vec::new();
12791279
for arg in inputs {
12801280
let new_ty = self.rebuild_arg_ty_or_output(&*arg.ty, lifetime,
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12861286
};
12871287
new_inputs.push(possibly_new_arg);
12881288
}
1289-
new_inputs
1289+
new_inputs.into()
12901290
}
12911291

12921292
fn rebuild_output(&self, ty: &hir::FunctionRetTy,
@@ -1513,7 +1513,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
15131513
}
15141514
});
15151515
hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
1516-
lifetimes: new_lts,
1516+
lifetimes: new_lts.into(),
15171517
types: new_types,
15181518
bindings: new_bindings,
15191519
})
@@ -1529,7 +1529,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
15291529
hir::Path {
15301530
span: path.span,
15311531
global: path.global,
1532-
segments: new_segs
1532+
segments: new_segs.into()
15331533
}
15341534
}
15351535
}

src/librustc/middle/resolve_lifetime.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ struct LifetimeContext<'a> {
7979
enum ScopeChain<'a> {
8080
/// EarlyScope(i, ['a, 'b, ...], s) extends s with early-bound
8181
/// lifetimes, assigning indexes 'a => i, 'b => i+1, ... etc.
82-
EarlyScope(subst::ParamSpace, &'a Vec<hir::LifetimeDef>, Scope<'a>),
82+
EarlyScope(subst::ParamSpace, &'a [hir::LifetimeDef], Scope<'a>),
8383
/// LateScope(['a, 'b, ...], s) extends s with late-bound
8484
/// lifetimes introduced by the declaration binder_id.
85-
LateScope(&'a Vec<hir::LifetimeDef>, Scope<'a>),
85+
LateScope(&'a [hir::LifetimeDef], Scope<'a>),
8686

8787
/// lifetimes introduced by a fn are scoped to the call-site for that fn.
8888
FnScope { fn_id: ast::NodeId, body_id: ast::NodeId, s: Scope<'a> },
@@ -206,7 +206,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
206206
// a trait ref, which introduces a binding scope.
207207
match self.def_map.get(&ty.id).map(|d| (d.base_def, d.depth)) {
208208
Some((def::DefTrait(..), 0)) => {
209-
self.with(LateScope(&Vec::new(), self.scope), |_, this| {
209+
self.with(LateScope(&[], self.scope), |_, this| {
210210
this.visit_path(path, ty.id);
211211
});
212212
}
@@ -661,7 +661,7 @@ impl<'a> LifetimeContext<'a> {
661661
lifetime_ref.name);
662662
}
663663

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

@@ -753,7 +753,7 @@ impl<'a> LifetimeContext<'a> {
753753
}
754754
}
755755

756-
fn search_lifetimes<'a>(lifetimes: &'a Vec<hir::LifetimeDef>,
756+
fn search_lifetimes<'a>(lifetimes: &'a [hir::LifetimeDef],
757757
lifetime_ref: &hir::Lifetime)
758758
-> Option<(u32, &'a hir::Lifetime)> {
759759
for (i, lifetime_decl) in lifetimes.iter().enumerate() {

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct Annotator<'a, 'tcx: 'a> {
8282
impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
8383
// Determine the stability for a node based on its attributes and inherited
8484
// stability. The stability is recorded in the index and used as the parent.
85-
fn annotate<F>(&mut self, id: NodeId, attrs: &Vec<Attribute>,
85+
fn annotate<F>(&mut self, id: NodeId, attrs: &[Attribute],
8686
item_sp: Span, kind: AnnotationKind, visit_children: F)
8787
where F: FnOnce(&mut Annotator)
8888
{

src/librustc_front/fold.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub trait Folder : Sized {
3434
noop_fold_crate(c, self)
3535
}
3636

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

@@ -198,11 +198,11 @@ pub trait Folder : Sized {
198198
noop_fold_variant_data(vdata, self)
199199
}
200200

201-
fn fold_lifetimes(&mut self, lts: Vec<Lifetime>) -> Vec<Lifetime> {
201+
fn fold_lifetimes(&mut self, lts: HirVec<Lifetime>) -> HirVec<Lifetime> {
202202
noop_fold_lifetimes(lts, self)
203203
}
204204

205-
fn fold_lifetime_defs(&mut self, lts: Vec<LifetimeDef>) -> Vec<LifetimeDef> {
205+
fn fold_lifetime_defs(&mut self, lts: HirVec<LifetimeDef>) -> HirVec<LifetimeDef> {
206206
noop_fold_lifetime_defs(lts, self)
207207
}
208208

@@ -263,9 +263,9 @@ pub trait Folder : Sized {
263263
}
264264
}
265265

266-
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>,
266+
pub fn noop_fold_meta_items<T: Folder>(meta_items: HirVec<P<MetaItem>>,
267267
fld: &mut T)
268-
-> Vec<P<MetaItem>> {
268+
-> HirVec<P<MetaItem>> {
269269
meta_items.move_map(|x| fld.fold_meta_item(x))
270270
}
271271

@@ -304,7 +304,7 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
304304
})
305305
}
306306

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

@@ -477,7 +477,7 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
477477
pat: fld.fold_pat(pat),
478478
init: init.map(|e| fld.fold_expr(e)),
479479
span: fld.new_span(span),
480-
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, fld)),
480+
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), fld).into()),
481481
}
482482
})
483483
}
@@ -596,11 +596,13 @@ pub fn noop_fold_lifetime_def<T: Folder>(l: LifetimeDef, fld: &mut T) -> Lifetim
596596
}
597597
}
598598

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

603-
pub fn noop_fold_lifetime_defs<T: Folder>(lts: Vec<LifetimeDef>, fld: &mut T) -> Vec<LifetimeDef> {
603+
pub fn noop_fold_lifetime_defs<T: Folder>(lts: HirVec<LifetimeDef>,
604+
fld: &mut T)
605+
-> HirVec<LifetimeDef> {
604606
lts.move_map(|l| fld.fold_lifetime_def(l))
605607
}
606608

@@ -1139,7 +1141,7 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
11391141
}
11401142
},
11411143
span: folder.new_span(span),
1142-
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs, folder)),
1144+
attrs: attrs.map_thin_attrs(|attrs| fold_attrs(attrs.into(), folder).into()),
11431145
}
11441146
}
11451147

0 commit comments

Comments
 (0)