]> git.lizzy.rs Git - rust.git/commitdiff
Allow *-pointers in PtrTy (fixes #16781)
authorManish Goregaokar <manishsmail@gmail.com>
Wed, 27 Aug 2014 13:19:17 +0000 (18:49 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Wed, 27 Aug 2014 13:19:17 +0000 (18:49 +0530)
src/libsyntax/ext/build.rs
src/libsyntax/ext/deriving/generic/ty.rs

index 909f8f1e78ce42e9768cff7c5aa4fe9234b42e97..64ab0e5cb191f442b448cabd015443baacff3fb6 100644 (file)
@@ -52,6 +52,9 @@ fn ty_rptr(&self, span: Span,
                ty: P<ast::Ty>,
                lifetime: Option<ast::Lifetime>,
                mutbl: ast::Mutability) -> P<ast::Ty>;
+    fn ty_ptr(&self, span: Span,
+              ty: P<ast::Ty>,
+              mutbl: ast::Mutability) -> P<ast::Ty>;
     fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>;
 
     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
@@ -369,6 +372,14 @@ fn ty_rptr(&self,
                 ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
     }
 
+    fn ty_ptr(&self,
+              span: Span,
+              ty: P<ast::Ty>,
+              mutbl: ast::Mutability)
+        -> P<ast::Ty> {
+        self.ty(span,
+                ast::TyPtr(self.ty_mt(ty, mutbl)))
+    }
     fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
         self.ty(span, ast::TyUniq(ty))
     }
index f4a9b85f75d23d62fff86fb8bbc53d72bc7c5e6e..8b4a9c51cf09dbc07d8691205844a61220895fe4 100644 (file)
@@ -28,6 +28,8 @@
 pub enum PtrTy<'a> {
     /// &'lifetime mut
     Borrowed(Option<&'a str>, ast::Mutability),
+    /// *mut
+    Raw(ast::Mutability),
 }
 
 /// A path, e.g. `::std::option::Option::<int>` (global). Has support
@@ -82,7 +84,7 @@ pub fn to_path(&self,
     }
 }
 
-/// A type. Supports pointers (except for *), Self, and literals
+/// A type. Supports pointers, Self, and literals
 #[deriving(Clone)]
 pub enum Ty<'a> {
     Self,
@@ -143,6 +145,7 @@ pub fn to_ty(&self,
                         let lt = mk_lifetime(cx, span, lt);
                         cx.ty_rptr(span, raw_ty, lt, mutbl)
                     }
+                    Raw(mutbl) => cx.ty_ptr(span, raw_ty, mutbl)
                 }
             }
             Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) }
@@ -273,6 +276,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
                         let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name));
                         ast::SelfRegion(lt, mutbl, special_idents::self_)
                     }
+                    Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition")
                 });
             let self_expr = cx.expr_deref(span, self_path);
             (self_expr, self_ty)