Skip to content

Commit 6ba2602

Browse files
committed
Use OwnedSlice in HIR and update other crates using HIR
1 parent 901faef commit 6ba2602

File tree

12 files changed

+44
-30
lines changed

12 files changed

+44
-30
lines changed

src/librustc/front/map/collector.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use rustc_front::util;
1616
use rustc_front::intravisit::{self, Visitor};
1717
use middle::def_id::{CRATE_DEF_INDEX, DefIndex};
1818
use std::iter::repeat;
19+
use std::vec;
1920
use syntax::ast::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
2021
use syntax::codemap::Span;
2122

2223
/// A Visitor that walks over an AST and collects Node's into an AST
2324
/// Map.
2425
pub struct NodeCollector<'ast> {
2526
pub krate: &'ast Crate,
26-
pub map: Vec<MapEntry<'ast>>,
27+
pub map: vec::Vec<MapEntry<'ast>>,
2728
pub definitions: Definitions,
2829
pub parent_node: NodeId,
2930
}
@@ -50,7 +51,7 @@ impl<'ast> NodeCollector<'ast> {
5051
parent: &'ast InlinedParent,
5152
parent_node: NodeId,
5253
parent_def_path: DefPath,
53-
map: Vec<MapEntry<'ast>>,
54+
map: vec::Vec<MapEntry<'ast>>,
5455
definitions: Definitions)
5556
-> NodeCollector<'ast> {
5657
let mut collector = NodeCollector {

src/librustc/front/map/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::io;
3535
use std::iter;
3636
use std::mem;
3737
use std::slice;
38+
use std::vec;
3839

3940
pub mod blocks;
4041
mod collector;
@@ -164,7 +165,7 @@ impl<'ast> Clone for MapEntry<'ast> {
164165

165166
#[derive(Debug)]
166167
pub struct InlinedParent {
167-
path: Vec<PathElem>,
168+
path: vec::Vec<PathElem>,
168169
ii: InlinedItem
169170
}
170171

@@ -261,7 +262,7 @@ pub struct Map<'ast> {
261262
///
262263
/// Also, indexing is pretty quick when you've got a vector and
263264
/// plain old integers.
264-
map: RefCell<Vec<MapEntry<'ast>>>,
265+
map: RefCell<vec::Vec<MapEntry<'ast>>>,
265266

266267
definitions: RefCell<Definitions>,
267268
}
@@ -842,7 +843,7 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> {
842843
/// crate. The `path` should be the path to the item but should not include
843844
/// the item itself.
844845
pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
845-
path: Vec<PathElem>,
846+
path: vec::Vec<PathElem>,
846847
def_path: DefPath,
847848
ii: InlinedItem,
848849
fold_ops: F)

src/librustc/middle/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
516516
ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => {
517517
let v = adt.variant_of_ctor(ctor);
518518
if let VariantKind::Struct = v.kind() {
519-
let field_pats: Vec<_> = v.fields.iter()
519+
let field_pats: hir::Vec<_> = v.fields.iter()
520520
.zip(pats)
521521
.filter(|&(_, ref pat)| pat.node != hir::PatWild)
522522
.map(|(field, pat)| Spanned {
@@ -539,14 +539,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
539539
ty::TyArray(_, n) => match ctor {
540540
&Single => {
541541
assert_eq!(pats_len, n);
542-
hir::PatVec(pats.collect(), None, vec!())
542+
hir::PatVec(pats.collect(), None, hir::Vec::new())
543543
},
544544
_ => unreachable!()
545545
},
546546
ty::TySlice(_) => match ctor {
547547
&Slice(n) => {
548548
assert_eq!(pats_len, n);
549-
hir::PatVec(pats.collect(), None, vec!())
549+
hir::PatVec(pats.collect(), None, hir::Vec::new())
550550
},
551551
_ => unreachable!()
552552
},
@@ -561,7 +561,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
561561

562562
ty::TyArray(_, len) => {
563563
assert_eq!(pats_len, len);
564-
hir::PatVec(pats.collect(), None, vec![])
564+
hir::PatVec(pats.collect(), None, hir::Vec::new())
565565
}
566566

567567
_ => {

src/librustc/middle/const_eval.rs

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

353353
hir::ExprVec(ref exprs) => {
354354
let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect();
355-
hir::PatVec(pats, None, vec![])
355+
hir::PatVec(pats, None, hir::Vec::new())
356356
}
357357

358358
hir::ExprPath(_, ref path) => {
359359
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
360360
match opt_def {
361361
Some(def::DefStruct(..)) =>
362-
hir::PatStruct(path.clone(), vec![], false),
362+
hir::PatStruct(path.clone(), hir::Vec::new(), false),
363363
Some(def::DefVariant(..)) =>
364364
hir::PatEnum(path.clone(), None),
365365
_ => {

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
}
@@ -647,7 +647,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
647647

648648
fn walk_struct_expr(&mut self,
649649
_expr: &hir::Expr,
650-
fields: &Vec<hir::Field>,
650+
fields: &[hir::Field],
651651
opt_with: &Option<P<hir::Expr>>) {
652652
// Consume the expressions supplying values for each field.
653653
for field in fields {
@@ -693,7 +693,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
693693
self.walk_expr(with_expr);
694694

695695
fn contains_field_named(field: ty::FieldDef,
696-
fields: &Vec<hir::Field>)
696+
fields: &[hir::Field])
697697
-> bool
698698
{
699699
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::Vec::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::Vec<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
}).collect();
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

+4-4
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
/// lifetimes introduced by items within a code block are scoped
8787
/// to that block.
8888
BlockScope(region::DestructionScopeData, Scope<'a>),
@@ -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
@@ -80,7 +80,7 @@ struct Annotator<'a, 'tcx: 'a> {
8080
impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
8181
// Determine the stability for a node based on its attributes and inherited
8282
// stability. The stability is recorded in the index and used as the parent.
83-
fn annotate<F>(&mut self, id: NodeId, attrs: &Vec<Attribute>,
83+
fn annotate<F>(&mut self, id: NodeId, attrs: &[Attribute],
8484
item_sp: Span, kind: AnnotationKind, visit_children: F)
8585
where F: FnOnce(&mut Annotator)
8686
{

src/librustc_front/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use util;
5252
use std::fmt;
5353
use serialize::{Encodable, Encoder, Decoder};
5454

55-
pub type Vec<T> = ::std::vec::Vec<T>;
55+
pub type Vec<T> = OwnedSlice<T>;
5656

5757
macro_rules! hir_vec {
5858
($elem:expr; $n:expr) => (

src/librustc_mir/hair/cx/pattern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
253253
}
254254
}
255255

256-
fn to_pats(&mut self, pats: &'tcx Vec<P<hir::Pat>>) -> Vec<Pattern<'tcx>> {
256+
fn to_pats(&mut self, pats: &'tcx [P<hir::Pat>]) -> Vec<Pattern<'tcx>> {
257257
pats.iter().map(|p| self.to_pat(p)).collect()
258258
}
259259

@@ -264,9 +264,9 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
264264
fn slice_or_array_pattern(&mut self,
265265
pat: &'tcx hir::Pat,
266266
ty: Ty<'tcx>,
267-
prefix: &'tcx Vec<P<hir::Pat>>,
267+
prefix: &'tcx [P<hir::Pat>],
268268
slice: &'tcx Option<P<hir::Pat>>,
269-
suffix: &'tcx Vec<P<hir::Pat>>)
269+
suffix: &'tcx [P<hir::Pat>])
270270
-> PatternKind<'tcx> {
271271
match ty.sty {
272272
ty::TySlice(..) => {

src/librustc_mir/hair/cx/to_ref.rs

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use hair::*;
1212

1313
use rustc_front::hir;
14+
use syntax::owned_slice::OwnedSlice;
1415
use syntax::ptr::P;
1516

1617
pub trait ToRef {
@@ -61,3 +62,14 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
6162
self.iter().map(|expr| expr.to_ref()).collect()
6263
}
6364
}
65+
66+
67+
impl<'a,'tcx:'a,T,U> ToRef for &'tcx OwnedSlice<T>
68+
where &'tcx T: ToRef<Output=U>
69+
{
70+
type Output = Vec<U>;
71+
72+
fn to_ref(self) -> Vec<U> {
73+
self.iter().map(|expr| expr.to_ref()).collect()
74+
}
75+
}

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ pub fn trans_static(ccx: &CrateContext,
10101010
m: hir::Mutability,
10111011
expr: &hir::Expr,
10121012
id: ast::NodeId,
1013-
attrs: &Vec<ast::Attribute>)
1013+
attrs: &[ast::Attribute])
10141014
-> Result<ValueRef, ConstEvalErr> {
10151015
unsafe {
10161016
let _icx = push_ctxt("trans_static");

0 commit comments

Comments
 (0)