Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsyntax: Merge OwnedSlice into ptr::P #30420

Merged
merged 3 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 11 additions & 12 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use std::cell::{Cell, RefCell};
use std::char::from_u32;
use std::fmt;
use syntax::ast;
use syntax::owned_slice::OwnedSlice;
use syntax::codemap::{self, Pos, Span};
use syntax::parse::token;
use syntax::ptr::P;
Expand Down Expand Up @@ -1154,10 +1153,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}

fn rebuild_ty_params(&self,
ty_params: OwnedSlice<hir::TyParam>,
ty_params: P<[hir::TyParam]>,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> OwnedSlice<hir::TyParam> {
-> P<[hir::TyParam]> {
ty_params.map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
lifetime,
Expand All @@ -1173,10 +1172,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}

fn rebuild_ty_param_bounds(&self,
ty_param_bounds: OwnedSlice<hir::TyParamBound>,
ty_param_bounds: hir::TyParamBounds,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> OwnedSlice<hir::TyParamBound> {
-> hir::TyParamBounds {
ty_param_bounds.map(|tpb| {
match tpb {
&hir::RegionTyParamBound(lt) => {
Expand Down Expand Up @@ -1249,13 +1248,13 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
add: &Vec<hir::Lifetime>,
keep: &HashSet<ast::Name>,
remove: &HashSet<ast::Name>,
ty_params: OwnedSlice<hir::TyParam>,
ty_params: P<[hir::TyParam]>,
where_clause: hir::WhereClause)
-> hir::Generics {
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 @@ -1264,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 @@ -1275,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 @@ -1287,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 @@ -1514,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 @@ -1530,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
6 changes: 3 additions & 3 deletions src/librustc/middle/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use middle::ty::fold::{TypeFoldable, TypeFolder};

use std::rc::Rc;
use syntax::abi;
use syntax::owned_slice::OwnedSlice;
use syntax::ptr::P;

use rustc_front::hir;

Expand Down Expand Up @@ -555,8 +555,8 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
}
}

impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for OwnedSlice<T> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> OwnedSlice<T> {
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> P<[T]> {
self.iter().map(|t| t.fold_with(folder)).collect()
}
}
Expand Down
39 changes: 20 additions & 19 deletions src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use syntax::ast::{MetaWord, MetaList, MetaNameValue};
use syntax::attr::ThinAttributesExt;
use hir;
use syntax::codemap::{respan, Span, Spanned};
use syntax::owned_slice::OwnedSlice;
use syntax::ptr::P;
use syntax::parse::token;
use syntax::util::move_map::MoveMap;
Expand All @@ -35,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 @@ -199,19 +198,19 @@ 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)
}

fn fold_ty_param(&mut self, tp: TyParam) -> TyParam {
noop_fold_ty_param(tp, self)
}

fn fold_ty_params(&mut self, tps: OwnedSlice<TyParam>) -> OwnedSlice<TyParam> {
fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
noop_fold_ty_params(tps, self)
}

Expand All @@ -220,12 +219,12 @@ pub trait Folder : Sized {
}

fn fold_opt_bounds(&mut self,
b: Option<OwnedSlice<TyParamBound>>)
-> Option<OwnedSlice<TyParamBound>> {
b: Option<TyParamBounds>)
-> Option<TyParamBounds> {
noop_fold_opt_bounds(b, self)
}

fn fold_bounds(&mut self, b: OwnedSlice<TyParamBound>) -> OwnedSlice<TyParamBound> {
fn fold_bounds(&mut self, b: TyParamBounds) -> TyParamBounds {
noop_fold_bounds(b, self)
}

Expand Down Expand Up @@ -264,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 @@ -305,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 @@ -478,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 @@ -576,9 +575,9 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
}
}

pub fn noop_fold_ty_params<T: Folder>(tps: OwnedSlice<TyParam>,
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>,
fld: &mut T)
-> OwnedSlice<TyParam> {
-> P<[TyParam]> {
tps.move_map(|tp| fld.fold_ty_param(tp))
}

Expand All @@ -597,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 @@ -726,9 +727,9 @@ pub fn noop_fold_mt<T: Folder>(MutTy { ty, mutbl }: MutTy, folder: &mut T) -> Mu
}
}

pub fn noop_fold_opt_bounds<T: Folder>(b: Option<OwnedSlice<TyParamBound>>,
pub fn noop_fold_opt_bounds<T: Folder>(b: Option<TyParamBounds>,
folder: &mut T)
-> Option<OwnedSlice<TyParamBound>> {
-> Option<TyParamBounds> {
b.map(|bounds| folder.fold_bounds(bounds))
}

Expand Down Expand Up @@ -1140,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