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

Allow *-pointers in PtrTy (fixes #16781) #16788

Merged
merged 1 commit into from
Aug 31, 2014
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
11 changes: 11 additions & 0 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub trait AstBuilder {
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>;
Expand Down Expand Up @@ -369,6 +372,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
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))
}
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/ext/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use std::gc::Gc;
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
Expand Down Expand Up @@ -82,7 +84,7 @@ impl<'a> Path<'a> {
}
}

/// A type. Supports pointers (except for *), Self, and literals
/// A type. Supports pointers, Self, and literals
#[deriving(Clone)]
pub enum Ty<'a> {
Self,
Expand Down Expand Up @@ -143,6 +145,7 @@ impl<'a> Ty<'a> {
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) }
Expand Down Expand Up @@ -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)
Expand Down