]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #30470 - petrochenkov:owned5, r=nrc
authorbors <bors@rust-lang.org>
Sun, 20 Dec 2015 22:50:34 +0000 (22:50 +0000)
committerbors <bors@rust-lang.org>
Sun, 20 Dec 2015 22:50:34 +0000 (22:50 +0000)
cc https://github.com/rust-lang/rust/pull/30095

r? @nrc

src/librustc/middle/infer/error_reporting.rs
src/librustc_front/fold.rs
src/librustc_front/hir.rs
src/librustc_front/lowering.rs
src/librustc_front/print/pprust.rs
src/librustc_front/util.rs
src/librustc_mir/hair/cx/to_ref.rs
src/librustc_typeck/check/mod.rs
src/libsyntax/ptr.rs

index 7bb66d6317abdc52b515d928827db543a4920480..181e0c0fbc86b895e521de0b8d3633d2d41993c8 100644 (file)
@@ -1137,11 +1137,11 @@ fn track_anon(&self, anon: u32) {
     }
 
     fn rebuild_ty_params(&self,
-                         ty_params: P<[hir::TyParam]>,
+                         ty_params: hir::HirVec<hir::TyParam>,
                          lifetime: hir::Lifetime,
                          region_names: &HashSet<ast::Name>)
-                         -> P<[hir::TyParam]> {
-        ty_params.map(|ty_param| {
+                         -> hir::HirVec<hir::TyParam> {
+        ty_params.iter().map(|ty_param| {
             let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
                                                       lifetime,
                                                       region_names);
@@ -1152,7 +1152,7 @@ fn rebuild_ty_params(&self,
                 default: ty_param.default.clone(),
                 span: ty_param.span,
             }
-        })
+        }).collect()
     }
 
     fn rebuild_ty_param_bounds(&self,
@@ -1160,7 +1160,7 @@ fn rebuild_ty_param_bounds(&self,
                                lifetime: hir::Lifetime,
                                region_names: &HashSet<ast::Name>)
                                -> hir::TyParamBounds {
-        ty_param_bounds.map(|tpb| {
+        ty_param_bounds.iter().map(|tpb| {
             match tpb {
                 &hir::RegionTyParamBound(lt) => {
                     // FIXME -- it's unclear whether I'm supposed to
@@ -1196,7 +1196,7 @@ fn rebuild_ty_param_bounds(&self,
                     }, modifier)
                 }
             }
-        })
+        }).collect()
     }
 
     fn rebuild_expl_self(&self,
@@ -1232,7 +1232,7 @@ fn rebuild_generics(&self,
                         add: &Vec<hir::Lifetime>,
                         keep: &HashSet<ast::Name>,
                         remove: &HashSet<ast::Name>,
-                        ty_params: P<[hir::TyParam]>,
+                        ty_params: hir::HirVec<hir::TyParam>,
                         where_clause: hir::WhereClause)
                         -> hir::Generics {
         let mut lifetimes = Vec::new();
@@ -1482,10 +1482,10 @@ fn rebuild_path(&self,
                         }
                     }
                 }
-                let new_types = data.types.map(|t| {
+                let new_types = data.types.iter().map(|t| {
                     self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
-                });
-                let new_bindings = data.bindings.map(|b| {
+                }).collect();
+                let new_bindings = data.bindings.iter().map(|b| {
                     hir::TypeBinding {
                         id: b.id,
                         name: b.name,
@@ -1495,7 +1495,7 @@ fn rebuild_path(&self,
                                                           region_names),
                         span: b.span
                     }
-                });
+                }).collect();
                 hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
                     lifetimes: new_lts.into(),
                     types: new_types,
index 5da679c3495c5539406d291f636f2fe3d2f85b79..e456b1eadf5d7460dc2d18c5d97a15a5f8493e85 100644 (file)
@@ -210,7 +210,7 @@ fn fold_ty_param(&mut self, tp: TyParam) -> TyParam {
         noop_fold_ty_param(tp, self)
     }
 
-    fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
+    fn fold_ty_params(&mut self, tps: HirVec<TyParam>) -> HirVec<TyParam> {
         noop_fold_ty_params(tps, self)
     }
 
@@ -575,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: P<[TyParam]>,
+pub fn noop_fold_ty_params<T: Folder>(tps: HirVec<TyParam>,
                                       fld: &mut T)
-                                      -> P<[TyParam]> {
+                                      -> HirVec<TyParam> {
     tps.move_map(|tp| fld.fold_ty_param(tp))
 }
 
index d079024bc96c4221b451490dccd587c12668604a..2625e34c820e40f339e3bf47d878f05a9b3afb29 100644 (file)
@@ -56,7 +56,7 @@
 /// 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<T> = Vec<T>;
+pub type HirVec<T> = P<[T]>;
 
 macro_rules! hir_vec {
     ($elem:expr; $n:expr) => (
@@ -208,8 +208,8 @@ impl PathParameters {
     pub fn none() -> PathParameters {
         AngleBracketedParameters(AngleBracketedParameterData {
             lifetimes: HirVec::new(),
-            types: P::empty(),
-            bindings: P::empty(),
+            types: HirVec::new(),
+            bindings: HirVec::new(),
         })
     }
 
@@ -282,10 +282,10 @@ pub struct AngleBracketedParameterData {
     /// The lifetime parameters for this path segment.
     pub lifetimes: HirVec<Lifetime>,
     /// The type parameters for this path segment, if present.
-    pub types: P<[P<Ty>]>,
+    pub types: HirVec<P<Ty>>,
     /// Bindings (equality constraints) on associated types, if present.
     /// E.g., `Foo<A=Bar>`.
-    pub bindings: P<[TypeBinding]>,
+    pub bindings: HirVec<TypeBinding>,
 }
 
 impl AngleBracketedParameterData {
@@ -325,7 +325,7 @@ pub enum TraitBoundModifier {
     Maybe,
 }
 
-pub type TyParamBounds = P<[TyParamBound]>;
+pub type TyParamBounds = HirVec<TyParamBound>;
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct TyParam {
@@ -341,7 +341,7 @@ pub struct TyParam {
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct Generics {
     pub lifetimes: HirVec<LifetimeDef>,
-    pub ty_params: P<[TyParam]>,
+    pub ty_params: HirVec<TyParam>,
     pub where_clause: WhereClause,
 }
 
index 52e771bd5c37c02826f5533295d3bcd147f1308b..afd834a61d6cebcec7c4695f23d1f69528aafa5a 100644 (file)
@@ -434,7 +434,7 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam {
 
 pub fn lower_ty_params(lctx: &LoweringContext,
                        tps: &P<[TyParam]>)
-                       -> P<[hir::TyParam]> {
+                       -> hir::HirVec<hir::TyParam> {
     tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect()
 }
 
@@ -1776,19 +1776,19 @@ fn path_ident(span: Span, id: hir::Ident) -> hir::Path {
 }
 
 fn path(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
-    path_all(span, false, strs, hir::HirVec::new(), Vec::new(), Vec::new())
+    path_all(span, false, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new())
 }
 
 fn path_global(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
-    path_all(span, true, strs, hir::HirVec::new(), Vec::new(), Vec::new())
+    path_all(span, true, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new())
 }
 
 fn path_all(sp: Span,
             global: bool,
             mut idents: Vec<hir::Ident>,
             lifetimes: hir::HirVec<hir::Lifetime>,
-            types: Vec<P<hir::Ty>>,
-            bindings: Vec<hir::TypeBinding>)
+            types: hir::HirVec<P<hir::Ty>>,
+            bindings: hir::HirVec<hir::TypeBinding>)
             -> hir::Path {
     let last_identifier = idents.pop().unwrap();
     let mut segments: Vec<hir::PathSegment> = idents.into_iter()
@@ -1803,8 +1803,8 @@ fn path_all(sp: Span,
         identifier: last_identifier,
         parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
             lifetimes: lifetimes,
-            types: P::from_vec(types),
-            bindings: P::from_vec(bindings),
+            types: types,
+            bindings: bindings,
         }),
     });
     hir::Path {
index f1b963bf11ddbeedb66f1fa96c88ca3576d9c317..c5ce76c1b6e69c20d055f82fed7a67dbbc7204b0 100644 (file)
@@ -519,7 +519,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
             hir::TyBareFn(ref f) => {
                 let generics = hir::Generics {
                     lifetimes: f.lifetimes.clone(),
-                    ty_params: P::empty(),
+                    ty_params: hir::HirVec::new(),
                     where_clause: hir::WhereClause {
                         id: ast::DUMMY_NODE_ID,
                         predicates: hir::HirVec::new(),
@@ -2263,7 +2263,7 @@ pub fn print_ty_fn(&mut self,
         }
         let generics = hir::Generics {
             lifetimes: hir::HirVec::new(),
-            ty_params: P::empty(),
+            ty_params: hir::HirVec::new(),
             where_clause: hir::WhereClause {
                 id: ast::DUMMY_NODE_ID,
                 predicates: hir::HirVec::new(),
index 298904d1e0d7abdcf82df68c090b3a5cceca64eb..57ffefd3be4354134a4e46f8e58a52771d41bb52 100644 (file)
@@ -335,7 +335,7 @@ pub fn is_path(e: P<Expr>) -> bool {
 pub fn empty_generics() -> Generics {
     Generics {
         lifetimes: HirVec::new(),
-        ty_params: P::empty(),
+        ty_params: HirVec::new(),
         where_clause: WhereClause {
             id: DUMMY_NODE_ID,
             predicates: HirVec::new(),
@@ -353,8 +353,8 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path {
             identifier: ident,
             parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
                 lifetimes: HirVec::new(),
-                types: P::empty(),
-                bindings: P::empty(),
+                types: HirVec::new(),
+                bindings: HirVec::new(),
             }),
         }],
     }
index da200a8a33f083616333f42641c4a77c9b96fe88..24fcc2f4fcd56a6eac016b554ff81be6dc5d7914 100644 (file)
@@ -61,3 +61,13 @@ fn to_ref(self) -> Vec<U> {
         self.iter().map(|expr| expr.to_ref()).collect()
     }
 }
+
+impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
+    where &'tcx T: ToRef<Output=U>
+{
+    type Output = Vec<U>;
+
+    fn to_ref(self) -> Vec<U> {
+        self.iter().map(|expr| expr.to_ref()).collect()
+    }
+}
index c91f65814186415aff56d75cf376d4cf973d0c9d..e8eb479a1c36fd618ae90cada3b07bf61dfd5378 100644 (file)
@@ -4903,7 +4903,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &hir::Block) -> bool {
 }
 
 pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
-                                       tps: &P<[hir::TyParam]>,
+                                       tps: &[hir::TyParam],
                                        ty: Ty<'tcx>) {
     debug!("check_bounds_are_used(n_tps={}, ty={:?})",
            tps.len(),  ty);
index 1be0b08086d9ce830028441184dc1ee43a285ce7..0504c313c91d66f019f4334fcde74979482db1a7 100644 (file)
@@ -130,6 +130,10 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl<T> P<[T]> {
+    pub fn new() -> P<[T]> {
+        P::empty()
+    }
+
     pub fn empty() -> P<[T]> {
         P { ptr: Default::default() }
     }
@@ -177,12 +181,33 @@ fn clone(&self) -> P<[T]> {
     }
 }
 
+impl<T> From<Vec<T>> for P<[T]> {
+    fn from(v: Vec<T>) -> Self {
+        P::from_vec(v)
+    }
+}
+
+impl<T> Into<Vec<T>> for P<[T]> {
+    fn into(self) -> Vec<T> {
+        self.into_vec()
+    }
+}
+
 impl<T> FromIterator<T> for P<[T]> {
     fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> P<[T]> {
         P::from_vec(iter.into_iter().collect())
     }
 }
 
+impl<T> IntoIterator for P<[T]> {
+    type Item = T;
+    type IntoIter = vec::IntoIter<T>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.into_vec().into_iter()
+    }
+}
+
 impl<'a, T> IntoIterator for &'a P<[T]> {
     type Item = &'a T;
     type IntoIter = slice::Iter<'a, T>;