Skip to content

Commit 2b312ec

Browse files
committed
Allow *-pointers in PtrTy (fixes #16781)
1 parent 80b45dd commit 2b312ec

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/libsyntax/ext/build.rs

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub trait AstBuilder {
5252
ty: P<ast::Ty>,
5353
lifetime: Option<ast::Lifetime>,
5454
mutbl: ast::Mutability) -> P<ast::Ty>;
55+
fn ty_ptr(&self, span: Span,
56+
ty: P<ast::Ty>,
57+
mutbl: ast::Mutability) -> P<ast::Ty>;
5558
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>;
5659

5760
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
@@ -369,6 +372,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
369372
ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
370373
}
371374

375+
fn ty_ptr(&self,
376+
span: Span,
377+
ty: P<ast::Ty>,
378+
mutbl: ast::Mutability)
379+
-> P<ast::Ty> {
380+
self.ty(span,
381+
ast::TyPtr(self.ty_mt(ty, mutbl)))
382+
}
372383
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
373384
self.ty(span, ast::TyUniq(ty))
374385
}

src/libsyntax/ext/deriving/generic/ty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use std::gc::Gc;
2828
pub enum PtrTy<'a> {
2929
/// &'lifetime mut
3030
Borrowed(Option<&'a str>, ast::Mutability),
31+
/// *mut
32+
Raw(ast::Mutability),
3133
}
3234

3335
/// A path, e.g. `::std::option::Option::<int>` (global). Has support
@@ -82,7 +84,7 @@ impl<'a> Path<'a> {
8284
}
8385
}
8486

85-
/// A type. Supports pointers (except for *), Self, and literals
87+
/// A type. Supports pointers, Self, and literals
8688
#[deriving(Clone)]
8789
pub enum Ty<'a> {
8890
Self,
@@ -143,6 +145,7 @@ impl<'a> Ty<'a> {
143145
let lt = mk_lifetime(cx, span, lt);
144146
cx.ty_rptr(span, raw_ty, lt, mutbl)
145147
}
148+
Raw(mutbl) => cx.ty_ptr(span, raw_ty, mutbl)
146149
}
147150
}
148151
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>)
273276
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name));
274277
ast::SelfRegion(lt, mutbl, special_idents::self_)
275278
}
279+
Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition")
276280
});
277281
let self_expr = cx.expr_deref(span, self_path);
278282
(self_expr, self_ty)

0 commit comments

Comments
 (0)