diff options
| author | bors <bors@rust-lang.org> | 2014-07-17 06:21:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-17 06:21:21 +0000 |
| commit | 32cb44bfff3facbded5fd9cc74af3f02e81565a8 (patch) | |
| tree | 162e3b98fc57b10079f3ed04ff2144bafbfabae4 /src/libsyntax | |
| parent | 459ffc2adc74f5e8b64a76f5670edb419b9f65da (diff) | |
| parent | 00c70d1a803e62ccbe2545d5c5522f4dcd6953b9 (diff) | |
| download | rust-32cb44bfff3facbded5fd9cc74af3f02e81565a8.tar.gz rust-32cb44bfff3facbded5fd9cc74af3f02e81565a8.zip | |
auto merge of #14022 : pcwalton/rust/explicit-self, r=pnkfelix
r? @nikomatsakis
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/ty.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 1 |
6 files changed, 35 insertions, 14 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 857cb4c0162..d9f14bfa156 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -949,12 +949,14 @@ pub enum RetStyle { pub enum ExplicitSelf_ { /// No self SelfStatic, - /// `self + /// `self` SelfValue(Ident), /// `&'lt self`, `&'lt mut self` SelfRegion(Option<Lifetime>, Mutability, Ident), /// `~self` - SelfUniq(Ident) + SelfUniq(Ident), + /// `self: TYPE` + SelfExplicit(P<Ty>, Ident), } pub type ExplicitSelf = Spanned<ExplicitSelf_>; diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax/ext/deriving/generic/ty.rs index f6a39d7b2e6..06eb92e1b27 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax/ext/deriving/generic/ty.rs @@ -25,8 +25,6 @@ use std::gc::Gc; /// The types of pointers pub enum PtrTy<'a> { - /// ~ - Send, /// &'lifetime mut Borrowed(Option<&'a str>, ast::Mutability), } @@ -138,9 +136,6 @@ impl<'a> Ty<'a> { Ptr(ref ty, ref ptr) => { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); match *ptr { - Send => { - cx.ty_uniq(span, raw_ty) - } Borrowed(ref lt, mutbl) => { let lt = mk_lifetime(cx, span, lt); cx.ty_rptr(span, raw_ty, lt, mutbl) @@ -260,7 +255,6 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>) let self_ty = respan( span, match *ptr { - Send => ast::SelfUniq(special_idents::self_), Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); ast::SelfRegion(lt, mutbl, special_idents::self_) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index fd786192cb4..87c762af2e5 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -344,6 +344,7 @@ pub trait Folder { SelfRegion(ref lifetime, m, id) => { SelfRegion(fold_opt_lifetime(lifetime, self), m, id) } + SelfExplicit(ref typ, id) => SelfExplicit(self.fold_ty(*typ), id), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e0c94dffb5c..bdfd928cfbc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -45,7 +45,7 @@ use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField}; use ast::{StructVariantKind, BiSub}; use ast::StrStyle; -use ast::{SelfRegion, SelfStatic, SelfUniq, SelfValue}; +use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfUniq, SelfValue}; use ast::{TokenTree, TraitMethod, TraitRef, TTDelim, TTSeq, TTTok}; use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox}; use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn}; @@ -3843,7 +3843,15 @@ impl<'a> Parser<'a> { } } token::IDENT(..) if self.is_self_ident() => { - SelfValue(self.expect_self_ident()) + let self_ident = self.expect_self_ident(); + + // Determine whether this is the fully explicit form, `self: + // TYPE`. + if self.eat(&token::COLON) { + SelfExplicit(self.parse_ty(false), self_ident) + } else { + SelfValue(self_ident) + } } token::BINOP(token::STAR) => { // Possibly "*self" or "*mut self" -- not supported. Try to avoid @@ -3851,7 +3859,9 @@ impl<'a> Parser<'a> { self.bump(); let _mutability = if Parser::token_is_mutability(&self.token) { self.parse_mutability() - } else { MutImmutable }; + } else { + MutImmutable + }; if self.is_self_ident() { let span = self.span; self.span_err(span, "cannot pass self by unsafe pointer"); @@ -3863,7 +3873,15 @@ impl<'a> Parser<'a> { _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => { mutbl_self = self.parse_mutability(); - SelfValue(self.expect_self_ident()) + let self_ident = self.expect_self_ident(); + + // Determine whether this is the fully explicit form, `self: + // TYPE`. + if self.eat(&token::COLON) { + SelfExplicit(self.parse_ty(false), self_ident) + } else { + SelfValue(self_ident) + } } _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| *t == token::TILDE) && @@ -3914,8 +3932,8 @@ impl<'a> Parser<'a> { } SelfValue(id) => parse_remaining_arguments!(id), SelfRegion(_,_,id) => parse_remaining_arguments!(id), - SelfUniq(id) => parse_remaining_arguments!(id) - + SelfUniq(id) => parse_remaining_arguments!(id), + SelfExplicit(_,id) => parse_remaining_arguments!(id), }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d524622f8ec..428a15cb8cf 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1859,6 +1859,11 @@ impl<'a> State<'a> { try!(self.print_mutability(m)); try!(word(&mut self.s, "self")); } + ast::SelfExplicit(ref typ, _) => { + try!(word(&mut self.s, "self")); + try!(self.word_space(":")); + try!(self.print_type(*typ)); + } } return Ok(true); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 795f19d0cfb..6760d7a3932 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -215,6 +215,7 @@ pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V, SelfRegion(ref lifetime, _, _) => { visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env) } + SelfExplicit(ref typ, _) => visitor.visit_ty(*typ, env.clone()), } } |
