[breaking-change] don't glob import ast::FunctionRetTy variants

This commit is contained in:
Oliver Schneider 2016-02-08 15:04:11 +01:00
parent 05e25de4f0
commit 3b57d40fe5
10 changed files with 40 additions and 41 deletions

View file

@ -450,9 +450,9 @@ pub fn lower_fn_decl(lctx: &LoweringContext, decl: &FnDecl) -> P<hir::FnDecl> {
P(hir::FnDecl { P(hir::FnDecl {
inputs: decl.inputs.iter().map(|x| lower_arg(lctx, x)).collect(), inputs: decl.inputs.iter().map(|x| lower_arg(lctx, x)).collect(),
output: match decl.output { output: match decl.output {
Return(ref ty) => hir::Return(lower_ty(lctx, ty)), FunctionRetTy::Ty(ref ty) => hir::Return(lower_ty(lctx, ty)),
DefaultReturn(span) => hir::DefaultReturn(span), FunctionRetTy::Default(span) => hir::DefaultReturn(span),
NoReturn(span) => hir::NoReturn(span), FunctionRetTy::None(span) => hir::NoReturn(span),
}, },
variadic: decl.variadic, variadic: decl.variadic,
}) })

View file

@ -350,7 +350,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
self.visit_ty(&arg.ty); self.visit_ty(&arg.ty);
} }
if let ast::Return(ref ret_ty) = sig.decl.output { if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output {
self.visit_ty(ret_ty); self.visit_ty(ret_ty);
} }
@ -429,7 +429,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
self.visit_ty(&arg.ty); self.visit_ty(&arg.ty);
} }
if let ast::Return(ref ret_ty) = decl.output { if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
self.visit_ty(&ret_ty); self.visit_ty(&ret_ty);
} }
@ -1141,7 +1141,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
self.visit_ty(&*arg.ty); self.visit_ty(&*arg.ty);
} }
if let ast::Return(ref ret_ty) = decl.output { if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
self.visit_ty(&**ret_ty); self.visit_ty(&**ret_ty);
} }

View file

@ -16,7 +16,6 @@ pub use self::Decl_::*;
pub use self::ExplicitSelf_::*; pub use self::ExplicitSelf_::*;
pub use self::Expr_::*; pub use self::Expr_::*;
pub use self::FloatTy::*; pub use self::FloatTy::*;
pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*; pub use self::ForeignItem_::*;
pub use self::IntTy::*; pub use self::IntTy::*;
pub use self::Item_::*; pub use self::Item_::*;
@ -1727,23 +1726,23 @@ impl fmt::Debug for ImplPolarity {
pub enum FunctionRetTy { pub enum FunctionRetTy {
/// Functions with return type `!`that always /// Functions with return type `!`that always
/// raise an error or exit (i.e. never return to the caller) /// raise an error or exit (i.e. never return to the caller)
NoReturn(Span), None(Span),
/// Return type is not specified. /// Return type is not specified.
/// ///
/// Functions default to `()` and /// Functions default to `()` and
/// closures default to inference. Span points to where return /// closures default to inference. Span points to where return
/// type would be inserted. /// type would be inserted.
DefaultReturn(Span), Default(Span),
/// Everything else /// Everything else
Return(P<Ty>), Ty(P<Ty>),
} }
impl FunctionRetTy { impl FunctionRetTy {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match *self {
NoReturn(span) => span, FunctionRetTy::None(span) => span,
DefaultReturn(span) => span, FunctionRetTy::Default(span) => span,
Return(ref ty) => ty.span FunctionRetTy::Ty(ref ty) => ty.span,
} }
} }
} }

View file

@ -941,7 +941,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> { fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> {
P(ast::FnDecl { P(ast::FnDecl {
inputs: inputs, inputs: inputs,
output: ast::Return(output), output: ast::FunctionRetTy::Ty(output),
variadic: false variadic: false
}) })
} }

View file

@ -685,9 +685,9 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
decl.map(|FnDecl {inputs, output, variadic}| FnDecl { decl.map(|FnDecl {inputs, output, variadic}| FnDecl {
inputs: inputs.move_map(|x| fld.fold_arg(x)), inputs: inputs.move_map(|x| fld.fold_arg(x)),
output: match output { output: match output {
Return(ty) => Return(fld.fold_ty(ty)), FunctionRetTy::Ty(ty) => FunctionRetTy::Ty(fld.fold_ty(ty)),
DefaultReturn(span) => DefaultReturn(span), FunctionRetTy::Default(span) => FunctionRetTy::Default(span),
NoReturn(span) => NoReturn(span) FunctionRetTy::None(span) => FunctionRetTy::None(span),
}, },
variadic: variadic variadic: variadic
}) })

View file

@ -950,7 +950,7 @@ mod tests {
}), }),
id: ast::DUMMY_NODE_ID id: ast::DUMMY_NODE_ID
}), }),
output: ast::DefaultReturn(sp(15, 15)), output: ast::FunctionRetTy::Default(sp(15, 15)),
variadic: false variadic: false
}), }),
ast::Unsafety::Normal, ast::Unsafety::Normal,

View file

@ -18,7 +18,7 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode};
use ast::Block; use ast::Block;
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause};
use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig};
use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn}; use ast::{Decl, DeclItem, DeclLocal, DefaultBlock};
use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf};
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
@ -39,11 +39,11 @@ use ast::{LitStr, LitInt, Local};
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
use ast::{MutImmutable, MutMutable, Mac_}; use ast::{MutImmutable, MutMutable, Mac_};
use ast::{MutTy, Mutability}; use ast::{MutTy, Mutability};
use ast::{NamedField, NoReturn}; use ast::NamedField;
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange};
use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild};
use ast::{PolyTraitRef, QSelf}; use ast::{PolyTraitRef, QSelf};
use ast::{Return, Stmt, StmtDecl}; use ast::{Stmt, StmtDecl};
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField};
use ast::StrStyle; use ast::StrStyle;
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
@ -1283,13 +1283,13 @@ impl<'a> Parser<'a> {
pub fn parse_ret_ty(&mut self) -> PResult<'a, FunctionRetTy> { pub fn parse_ret_ty(&mut self) -> PResult<'a, FunctionRetTy> {
if self.eat(&token::RArrow) { if self.eat(&token::RArrow) {
if self.eat(&token::Not) { if self.eat(&token::Not) {
Ok(NoReturn(self.last_span)) Ok(FunctionRetTy::None(self.last_span))
} else { } else {
Ok(Return(try!(self.parse_ty()))) Ok(FunctionRetTy::Ty(try!(self.parse_ty())))
} }
} else { } else {
let pos = self.span.lo; let pos = self.span.lo;
Ok(DefaultReturn(mk_sp(pos, pos))) Ok(FunctionRetTy::Default(mk_sp(pos, pos)))
} }
} }
@ -3053,7 +3053,7 @@ impl<'a> Parser<'a> {
{ {
let decl = try!(self.parse_fn_block_decl()); let decl = try!(self.parse_fn_block_decl());
let body = match decl.output { let body = match decl.output {
DefaultReturn(_) => { FunctionRetTy::Default(_) => {
// If no explicit return type is given, parse any // If no explicit return type is given, parse any
// expr and wrap it up in a dummy block: // expr and wrap it up in a dummy block:
let body_expr = try!(self.parse_expr()); let body_expr = try!(self.parse_expr());

View file

@ -2108,7 +2108,7 @@ impl<'a> State<'a> {
try!(space(&mut self.s)); try!(space(&mut self.s));
let default_return = match decl.output { let default_return = match decl.output {
ast::DefaultReturn(..) => true, ast::FunctionRetTy::Default(..) => true,
_ => false _ => false
}; };
@ -2722,19 +2722,19 @@ impl<'a> State<'a> {
try!(self.print_fn_args(decl, None, true)); try!(self.print_fn_args(decl, None, true));
try!(word(&mut self.s, "|")); try!(word(&mut self.s, "|"));
if let ast::DefaultReturn(..) = decl.output { if let ast::FunctionRetTy::Default(..) = decl.output {
return Ok(()); return Ok(());
} }
try!(self.space_if_not_bol()); try!(self.space_if_not_bol());
try!(self.word_space("->")); try!(self.word_space("->"));
match decl.output { match decl.output {
ast::Return(ref ty) => { ast::FunctionRetTy::Ty(ref ty) => {
try!(self.print_type(&**ty)); try!(self.print_type(&**ty));
self.maybe_print_comment(ty.span.lo) self.maybe_print_comment(ty.span.lo)
} }
ast::DefaultReturn(..) => unreachable!(), ast::FunctionRetTy::Default(..) => unreachable!(),
ast::NoReturn(span) => { ast::FunctionRetTy::None(span) => {
try!(self.word_nbsp("!")); try!(self.word_nbsp("!"));
self.maybe_print_comment(span.lo) self.maybe_print_comment(span.lo)
} }
@ -2988,7 +2988,7 @@ impl<'a> State<'a> {
} }
pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> io::Result<()> { pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> io::Result<()> {
if let ast::DefaultReturn(..) = decl.output { if let ast::FunctionRetTy::Default(..) = decl.output {
return Ok(()); return Ok(());
} }
@ -2996,16 +2996,16 @@ impl<'a> State<'a> {
try!(self.ibox(INDENT_UNIT)); try!(self.ibox(INDENT_UNIT));
try!(self.word_space("->")); try!(self.word_space("->"));
match decl.output { match decl.output {
ast::NoReturn(_) => ast::FunctionRetTy::None(_) =>
try!(self.word_nbsp("!")), try!(self.word_nbsp("!")),
ast::DefaultReturn(..) => unreachable!(), ast::FunctionRetTy::Default(..) => unreachable!(),
ast::Return(ref ty) => ast::FunctionRetTy::Ty(ref ty) =>
try!(self.print_type(&**ty)) try!(self.print_type(&**ty))
} }
try!(self.end()); try!(self.end());
match decl.output { match decl.output {
ast::Return(ref output) => self.maybe_print_comment(output.span.lo), ast::FunctionRetTy::Ty(ref output) => self.maybe_print_comment(output.span.lo),
_ => Ok(()) _ => Ok(())
} }
} }
@ -3155,7 +3155,7 @@ mod tests {
let decl = ast::FnDecl { let decl = ast::FnDecl {
inputs: Vec::new(), inputs: Vec::new(),
output: ast::DefaultReturn(codemap::DUMMY_SP), output: ast::FunctionRetTy::Default(codemap::DUMMY_SP),
variadic: false variadic: false
}; };
let generics = ast::Generics::default(); let generics = ast::Generics::default();

View file

@ -357,8 +357,8 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
match i.node { match i.node {
ast::ItemFn(ref decl, _, _, _, ref generics, _) => { ast::ItemFn(ref decl, _, _, _, ref generics, _) => {
let no_output = match decl.output { let no_output = match decl.output {
ast::DefaultReturn(..) => true, ast::FunctionRetTy::Default(..) => true,
ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true, ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyTup(vec![]) => true,
_ => false _ => false
}; };
if decl.inputs.is_empty() if decl.inputs.is_empty()
@ -394,8 +394,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
ast::ItemFn(ref decl, _, _, _, ref generics, _) => { ast::ItemFn(ref decl, _, _, _, ref generics, _) => {
let input_cnt = decl.inputs.len(); let input_cnt = decl.inputs.len();
let no_output = match decl.output { let no_output = match decl.output {
ast::DefaultReturn(..) => true, ast::FunctionRetTy::Default(..) => true,
ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true, ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyTup(vec![]) => true,
_ => false _ => false
}; };
let tparm_cnt = generics.ty_params.len(); let tparm_cnt = generics.ty_params.len();

View file

@ -524,7 +524,7 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics
} }
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) { pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) {
if let Return(ref output_ty) = *ret_ty { if let FunctionRetTy::Ty(ref output_ty) = *ret_ty {
visitor.visit_ty(output_ty) visitor.visit_ty(output_ty)
} }
} }