提交 1c4d4371 编写于 作者: O Oliver Schneider

[breaking-change] don't glob export ast::ExplicitSelf_ variants

上级 79fa657a
......@@ -408,17 +408,17 @@ pub fn lower_local(lctx: &LoweringContext, l: &Local) -> P<hir::Local> {
}
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)
}
}
......
......@@ -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<Lifetime>, Mutability, Ident),
Region(Option<Lifetime>, Mutability, Ident),
/// `self: TYPE`
SelfExplicit(P<Ty>, Ident),
Explicit(P<Ty>, Ident),
}
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
pub type ExplicitSelf = Spanned<SelfKind>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Mod {
......
......@@ -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<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr
})
}
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mut T)
-> ExplicitSelf_ {
pub fn noop_fold_explicit_self_kind<T: Folder>(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<T: Folder>(es: ExplicitSelf_, fld: &mu
pub fn noop_fold_explicit_self<T: Folder>(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)
}
}
......
......@@ -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<F>(&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),
};
......
......@@ -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<bool> {
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<ast::Ident>,
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<ast::Ident>,
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() {
......
......@@ -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)
}
......
......@@ -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_))
};
......
......@@ -264,7 +264,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
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<PtrTy>)
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")
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册