about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-23 14:30:40 +0000
committerbors <bors@rust-lang.org>2014-09-23 14:30:40 +0000
commitd80cd3d9bc46c326b67fe48497c9ae7b322179ba (patch)
tree314bf4a82ed0e632d631c8c44e7e3cb9f1d502de /src/libsyntax
parent2f9669c7489cc383bc6616c5f9ed217ae37e3d56 (diff)
parent5376b1c79870c80d0081540c72ae060d3ed5d1f5 (diff)
downloadrust-d80cd3d9bc46c326b67fe48497c9ae7b322179ba.tar.gz
rust-d80cd3d9bc46c326b67fe48497c9ae7b322179ba.zip
auto merge of #17028 : pcwalton/rust/higher-rank-trait-lifetimes, r=pnkfelix
They will ICE during typechecking if used, because they depend on trait
reform.

This is part of unboxed closures.

r? @nikomatsakis 
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs2
-rw-r--r--src/libsyntax/ext/build.rs3
-rw-r--r--src/libsyntax/fold.rs15
-rw-r--r--src/libsyntax/parse/parser.rs26
-rw-r--r--src/libsyntax/print/pprust.rs10
-rw-r--r--src/libsyntax/visit.rs5
6 files changed, 53 insertions, 8 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 5c84745c20c..74c69762be1 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -223,6 +223,7 @@ pub type TyParamBounds = OwnedSlice<TyParamBound>;
 pub struct UnboxedFnBound {
     pub path: Path,
     pub decl: P<FnDecl>,
+    pub lifetimes: Vec<LifetimeDef>,
     pub ref_id: NodeId,
 }
 
@@ -1219,6 +1220,7 @@ pub struct Attribute_ {
 pub struct TraitRef {
     pub path: Path,
     pub ref_id: NodeId,
+    pub lifetimes: Vec<LifetimeDef>,
 }
 
 #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 16ecd83180e..0586868eb45 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -435,7 +435,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
         ast::TraitRef {
             path: path,
-            ref_id: ast::DUMMY_NODE_ID
+            ref_id: ast::DUMMY_NODE_ID,
+            lifetimes: Vec::new(),
         }
     }
 
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 7ebb11c148b..91a339a73f7 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -668,11 +668,13 @@ pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
                 UnboxedFnBound {
                     ref path,
                     ref decl,
+                    ref lifetimes,
                     ref_id
                 } => {
                     UnboxedFnTyParamBound(P(UnboxedFnBound {
                         path: fld.fold_path(path.clone()),
                         decl: fld.fold_fn_decl(decl.clone()),
+                        lifetimes: fld.fold_lifetime_defs(lifetimes.clone()),
                         ref_id: fld.new_id(ref_id),
                     }))
                 }
@@ -808,10 +810,17 @@ pub fn noop_fold_struct_def<T: Folder>(struct_def: P<StructDef>, fld: &mut T) ->
     })
 }
 
-pub fn noop_fold_trait_ref<T: Folder>(TraitRef {ref_id, path}: TraitRef, fld: &mut T) -> TraitRef {
-    TraitRef {
-        ref_id: fld.new_id(ref_id),
+pub fn noop_fold_trait_ref<T: Folder>(p: TraitRef, fld: &mut T) -> TraitRef {
+    let id = fld.new_id(p.ref_id);
+    let TraitRef {
+        path,
+        lifetimes,
+        ..
+    } = p;
+    ast::TraitRef {
         path: fld.fold_path(path),
+        ref_id: id,
+        lifetimes: fld.fold_lifetime_defs(lifetimes),
     }
 }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 1ff6c3f9418..cbc710821f9 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -34,7 +34,8 @@ use ast::{FnOnceUnboxedClosureKind};
 use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod};
 use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic};
 use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl};
-use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_};
+use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
+use ast::{LifetimeDef, Lit, Lit_};
 use ast::{LitBool, LitChar, LitByte, LitBinary};
 use ast::{LitNil, LitStr, LitInt, Local, LocalLet};
 use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal};
@@ -3791,8 +3792,21 @@ impl<'a> Parser<'a> {
     {
         let mut result = vec!();
         loop {
+            let lifetime_defs = if self.eat(&token::LT) {
+                let lifetime_defs = self.parse_lifetime_defs();
+                self.expect_gt();
+                lifetime_defs
+            } else {
+                Vec::new()
+            };
             match self.token {
                 token::LIFETIME(lifetime) => {
+                    if lifetime_defs.len() > 0 {
+                        let span = self.last_span;
+                        self.span_err(span, "lifetime declarations are not \
+                                             allowed here")
+                    }
+
                     result.push(RegionTyParamBound(ast::Lifetime {
                         id: ast::DUMMY_NODE_ID,
                         span: self.span,
@@ -3818,12 +3832,14 @@ impl<'a> Parser<'a> {
                                 cf: return_style,
                                 variadic: false,
                             }),
+                            lifetimes: lifetime_defs,
                             ref_id: ast::DUMMY_NODE_ID,
                         })));
                     } else {
                         result.push(TraitTyParamBound(ast::TraitRef {
                             path: path,
                             ref_id: ast::DUMMY_NODE_ID,
+                            lifetimes: lifetime_defs,
                         }))
                     }
                 }
@@ -3852,6 +3868,7 @@ impl<'a> Parser<'a> {
         ast::TraitRef {
             path: path,
             ref_id: ast::DUMMY_NODE_ID,
+            lifetimes: Vec::new(),
         }
     }
 
@@ -4482,8 +4499,11 @@ impl<'a> Parser<'a> {
             // New-style trait. Reinterpret the type as a trait.
             let opt_trait_ref = match ty.node {
                 TyPath(ref path, None, node_id) => {
-                    Some(TraitRef { path: (*path).clone(),
-                                    ref_id: node_id })
+                    Some(TraitRef {
+                        path: (*path).clone(),
+                        ref_id: node_id,
+                        lifetimes: Vec::new(),
+                    })
                 }
                 TyPath(_, Some(_), _) => {
                     self.span_err(ty.span,
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 473179a037a..1fbd4af8627 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -900,6 +900,16 @@ impl<'a> State<'a> {
     }
 
     fn print_trait_ref(&mut self, t: &ast::TraitRef) -> IoResult<()> {
+        if t.lifetimes.len() > 0 {
+            try!(self.print_generics(&ast::Generics {
+                lifetimes: t.lifetimes.clone(),
+                ty_params: OwnedSlice::empty(),
+                where_clause: ast::WhereClause {
+                    id: ast::DUMMY_NODE_ID,
+                    predicates: Vec::new(),
+                },
+            }));
+        }
         self.print_path(&t.path, false)
     }
 
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 32084856817..3b2ed30b76d 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -202,7 +202,9 @@ pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
 
 /// Like with walk_method_helper this doesn't correspond to a method
 /// in Visitor, and so it gets a _helper suffix.
-pub fn walk_trait_ref_helper<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef) {
+pub fn walk_trait_ref_helper<'v,V>(visitor: &mut V, trait_ref: &'v TraitRef)
+                                   where V: Visitor<'v> {
+    walk_lifetime_decls(visitor, &trait_ref.lifetimes);
     visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
 }
 
@@ -495,6 +497,7 @@ pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V,
                     visitor.visit_ty(&*argument.ty)
                 }
                 visitor.visit_ty(&*function_declaration.decl.output);
+                walk_lifetime_decls(visitor, &function_declaration.lifetimes);
             }
             RegionTyParamBound(ref lifetime) => {
                 visitor.visit_lifetime_ref(lifetime);