diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 165982abc051458ecb6d3465b7f0fa2fc6bc16d7..de2da35f85631a7893360494588a48e3e60c6276 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -408,17 +408,17 @@ pub fn lower_local(lctx: &LoweringContext, l: &Local) -> P { } pub fn lower_explicit_self_underscore(lctx: &LoweringContext, - es: &ExplicitSelf_) + es: &SelfKind) -> hir::ExplicitSelf_ { match *es { - SelfStatic => hir::SelfStatic, - SelfValue(v) => hir::SelfValue(v.name), - SelfRegion(ref lifetime, m, ident) => { + SelfKind::Static => hir::SelfStatic, + SelfKind::Value(v) => hir::SelfValue(v.name), + SelfKind::Region(ref lifetime, m, ident) => { hir::SelfRegion(lower_opt_lifetime(lctx, lifetime), lower_mutability(lctx, m), ident.name) } - SelfExplicit(ref typ, ident) => { + SelfKind::Explicit(ref typ, ident) => { hir::SelfExplicit(lower_ty(lctx, typ), ident.name) } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9f013ad5ae7c4d27b311e9955f9ad8ef2af902cc..979c856871259cf7487a879f8cfb9294feaf095e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::ExplicitSelf_::*; pub use self::Expr_::*; pub use self::FloatTy::*; pub use self::ForeignItem_::*; @@ -1747,18 +1746,18 @@ pub fn span(&self) -> Span { /// Represents the kind of 'self' associated with a method #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ExplicitSelf_ { +pub enum SelfKind { /// No self - SelfStatic, + Static, /// `self` - SelfValue(Ident), + Value(Ident), /// `&'lt self`, `&'lt mut self` - SelfRegion(Option, Mutability, Ident), + Region(Option, Mutability, Ident), /// `self: TYPE` - SelfExplicit(P, Ident), + Explicit(P, Ident), } -pub type ExplicitSelf = Spanned; +pub type ExplicitSelf = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Mod { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 233bcbf46501d060dfb7e9f6842c64ca9412e185..3332941d0add17f881f6d8374f9120169bb4c3d9 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -184,8 +184,8 @@ fn fold_explicit_self(&mut self, es: ExplicitSelf) -> ExplicitSelf { noop_fold_explicit_self(es, self) } - fn fold_explicit_self_underscore(&mut self, es: ExplicitSelf_) -> ExplicitSelf_ { - noop_fold_explicit_self_underscore(es, self) + fn fold_explicit_self_kind(&mut self, es: SelfKind) -> SelfKind { + noop_fold_explicit_self_kind(es, self) } fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime { @@ -520,15 +520,15 @@ pub fn noop_fold_attribute(at: Attribute, fld: &mut T) -> Option(es: ExplicitSelf_, fld: &mut T) - -> ExplicitSelf_ { +pub fn noop_fold_explicit_self_kind(es: SelfKind, fld: &mut T) + -> SelfKind { match es { - SelfStatic | SelfValue(_) => es, - SelfRegion(lifetime, m, ident) => { - SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident) + SelfKind::Static | SelfKind::Value(_) => es, + SelfKind::Region(lifetime, m, ident) => { + SelfKind::Region(fld.fold_opt_lifetime(lifetime), m, ident) } - SelfExplicit(typ, ident) => { - SelfExplicit(fld.fold_ty(typ), ident) + SelfKind::Explicit(typ, ident) => { + SelfKind::Explicit(fld.fold_ty(typ), ident) } } } @@ -536,7 +536,7 @@ pub fn noop_fold_explicit_self_underscore(es: ExplicitSelf_, fld: &mu pub fn noop_fold_explicit_self(Spanned {span, node}: ExplicitSelf, fld: &mut T) -> ExplicitSelf { Spanned { - node: fld.fold_explicit_self_underscore(node), + node: fld.fold_explicit_self_kind(node), span: fld.new_span(span) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8bdd9a8f539f3cb87eab68030deafbeb0ca3304e..98b1cc21ef8df4354c1267cb582ae2840f058b45 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -46,7 +46,7 @@ use ast::{Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; use ast::StrStyle; -use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; +use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; @@ -4411,7 +4411,7 @@ fn parse_fn_decl_with_self(&mut self, F: FnMut(&mut Parser<'a>) -> PResult<'a, Arg>, { fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) - -> PResult<'b, ast::ExplicitSelf_> { + -> PResult<'b, ast::SelfKind> { // The following things are possible to see here: // // fn(&mut self) @@ -4423,26 +4423,26 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) if this.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - Ok(SelfRegion(None, MutImmutable, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, MutImmutable, try!(this.expect_self_ident()))) } else if this.look_ahead(1, |t| t.is_mutability()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let mutability = try!(this.parse_mutability()); - Ok(SelfRegion(None, mutability, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, mutability, try!(this.expect_self_ident()))) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let lifetime = try!(this.parse_lifetime()); - Ok(SelfRegion(Some(lifetime), MutImmutable, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(Some(lifetime), MutImmutable, try!(this.expect_self_ident()))) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_mutability()) && this.look_ahead(3, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let lifetime = try!(this.parse_lifetime()); let mutability = try!(this.parse_mutability()); - Ok(SelfRegion(Some(lifetime), mutability, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(Some(lifetime), mutability, try!(this.expect_self_ident()))) } else { - Ok(SelfStatic) + Ok(SelfKind::Static) } } @@ -4477,7 +4477,7 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) self.bump(); } // error case, making bogus self ident: - SelfValue(special_idents::self_) + SelfKind::Value(special_idents::self_) } token::Ident(..) => { if self.is_self_ident() { @@ -4486,9 +4486,9 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) // Determine whether this is the fully explicit form, `self: // TYPE`. if self.eat(&token::Colon) { - SelfExplicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) } else { - SelfValue(self_ident) + SelfKind::Value(self_ident) } } else if self.token.is_mutability() && self.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { @@ -4498,15 +4498,15 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) // Determine whether this is the fully explicit form, // `self: TYPE`. if self.eat(&token::Colon) { - SelfExplicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) } else { - SelfValue(self_ident) + SelfKind::Value(self_ident) } } else { - SelfStatic + SelfKind::Static } } - _ => SelfStatic, + _ => SelfKind::Static, }; let explicit_self_sp = mk_sp(self_ident_lo, self_ident_hi); @@ -4542,14 +4542,14 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) } let fn_inputs = match explicit_self { - SelfStatic => { + SelfKind::Static => { let sep = seq_sep_trailing_allowed(token::Comma); try!(self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn)) } - SelfValue(id) => parse_remaining_arguments!(id), - SelfRegion(_,_,id) => parse_remaining_arguments!(id), - SelfExplicit(_,id) => parse_remaining_arguments!(id), + SelfKind::Value(id) => parse_remaining_arguments!(id), + SelfKind::Region(_,_,id) => parse_remaining_arguments!(id), + SelfKind::Explicit(_,id) => parse_remaining_arguments!(id), }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 421225f279df9e25217a59ae04ae2e1efdeaeed7..68e9266a2b0c93ad3be9bc4fa987a98a1a09765b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -382,7 +382,7 @@ pub fn fun_to_string(decl: &ast::FnDecl, unsafety: ast::Unsafety, constness: ast::Constness, name: ast::Ident, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, generics: &ast::Generics) -> String { to_string(|s| { @@ -416,7 +416,7 @@ pub fn lit_to_string(l: &ast::Lit) -> String { to_string(|s| s.print_literal(l)) } -pub fn explicit_self_to_string(explicit_self: &ast::ExplicitSelf_) -> String { +pub fn explicit_self_to_string(explicit_self: &ast::SelfKind) -> String { to_string(|s| s.print_explicit_self(explicit_self, ast::MutImmutable).map(|_| {})) } @@ -2625,21 +2625,21 @@ fn print_arm(&mut self, arm: &ast::Arm) -> io::Result<()> { // Returns whether it printed anything fn print_explicit_self(&mut self, - explicit_self: &ast::ExplicitSelf_, + explicit_self: &ast::SelfKind, mutbl: ast::Mutability) -> io::Result { try!(self.print_mutability(mutbl)); match *explicit_self { - ast::SelfStatic => { return Ok(false); } - ast::SelfValue(_) => { + ast::SelfKind::Static => { return Ok(false); } + ast::SelfKind::Value(_) => { try!(word(&mut self.s, "self")); } - ast::SelfRegion(ref lt, m, _) => { + ast::SelfKind::Region(ref lt, m, _) => { try!(word(&mut self.s, "&")); try!(self.print_opt_lifetime(lt)); try!(self.print_mutability(m)); try!(word(&mut self.s, "self")); } - ast::SelfExplicit(ref typ, _) => { + ast::SelfKind::Explicit(ref typ, _) => { try!(word(&mut self.s, "self")); try!(self.word_space(":")); try!(self.print_type(&**typ)); @@ -2655,7 +2655,7 @@ pub fn print_fn(&mut self, abi: abi::Abi, name: Option, generics: &ast::Generics, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, vis: ast::Visibility) -> io::Result<()> { try!(self.print_fn_header_info(unsafety, constness, abi, vis)); @@ -2669,7 +2669,7 @@ pub fn print_fn(&mut self, } pub fn print_fn_args(&mut self, decl: &ast::FnDecl, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, is_closure: bool) -> io::Result<()> { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. @@ -2677,7 +2677,7 @@ pub fn print_fn_args(&mut self, decl: &ast::FnDecl, let mut first = true; if let Some(explicit_self) = opt_explicit_self { let m = match *explicit_self { - ast::SelfStatic => ast::MutImmutable, + ast::SelfKind::Static => ast::MutImmutable, _ => match decl.inputs[0].pat.node { ast::PatIdent(ast::BindingMode::ByValue(m), _, _) => m, _ => ast::MutImmutable @@ -2702,7 +2702,7 @@ pub fn print_fn_args(&mut self, decl: &ast::FnDecl, } pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl, - opt_explicit_self: Option<&ast::ExplicitSelf_>) + opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { try!(self.popen()); try!(self.print_fn_args(decl, opt_explicit_self, false)); @@ -3016,7 +3016,7 @@ pub fn print_ty_fn(&mut self, decl: &ast::FnDecl, name: Option, generics: &ast::Generics, - opt_explicit_self: Option<&ast::ExplicitSelf_>) + opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { try!(self.ibox(INDENT_UNIT)); if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index d12a5f353e7a688820945f1ea8bca4e176e0cd52..e38997931aaa5b71cb1824311591aa537ce1c256 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -196,15 +196,15 @@ pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V, explicit_self: &'v ExplicitSelf) { match explicit_self.node { - SelfStatic => {}, - SelfValue(ident) => { + SelfKind::Static => {}, + SelfKind::Value(ident) => { visitor.visit_ident(explicit_self.span, ident) } - SelfRegion(ref opt_lifetime, _, ident) => { + SelfKind::Region(ref opt_lifetime, _, ident) => { visitor.visit_ident(explicit_self.span, ident); walk_list!(visitor, visit_lifetime, opt_lifetime); } - SelfExplicit(ref typ, ident) => { + SelfKind::Explicit(ref typ, ident) => { visitor.visit_ident(explicit_self.span, ident); visitor.visit_ty(typ) } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 1faada13e2f349dea8423aefce5adb6298cd821d..3903f6a8085ec518fad2a94d87bda0208112f4e3 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -821,7 +821,7 @@ fn split_self_nonself_args(&self, explicit_self } - None => codemap::respan(trait_.span, ast::SelfStatic), + None => codemap::respan(trait_.span, ast::SelfKind::Static), }; for (i, ty) in self.args.iter().enumerate() { @@ -862,7 +862,7 @@ fn create_method(&self, let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics); let self_arg = match explicit_self.node { - ast::SelfStatic => None, + ast::SelfKind::Static => None, // creating fresh self id _ => Some(ast::Arg::new_self(trait_.span, ast::MutImmutable, special_idents::self_)) }; diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 10564b5f6985b7c407b2c05a9b4b9b758ed288f5..543beeb5da0c57de818e805e164d93ebe634b20c 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -264,7 +264,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option) let self_path = cx.expr_self(span); match *self_ptr { None => { - (self_path, respan(span, ast::SelfValue(special_idents::self_))) + (self_path, respan(span, ast::SelfKind::Value(special_idents::self_))) } Some(ref ptr) => { let self_ty = respan( @@ -272,7 +272,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option) match *ptr { Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); - ast::SelfRegion(lt, mutbl, special_idents::self_) + ast::SelfKind::Region(lt, mutbl, special_idents::self_) } Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition") });