From d258d68db6ae5ad81e4b8b4f5fcc1e4d89624f97 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 26 Nov 2014 10:07:22 -0500 Subject: Remove `proc` types/expressions from the parser, compiler, and language. Recommend `move||` instead. --- src/libsyntax/ast.rs | 3 --- src/libsyntax/ast_map/blocks.rs | 6 ++--- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/ext/expand.rs | 18 --------------- src/libsyntax/feature_gate.rs | 6 ----- src/libsyntax/fold.rs | 15 ------------ src/libsyntax/parse/obsolete.rs | 10 ++++++++ src/libsyntax/parse/parser.rs | 51 +++++++++++++++-------------------------- src/libsyntax/print/pprust.rs | 49 ++------------------------------------- src/libsyntax/visit.rs | 15 ------------ 10 files changed, 34 insertions(+), 141 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ea8de458ce2..ae7a2127e9f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -719,7 +719,6 @@ pub enum Expr_ { ExprLoop(P, Option), ExprMatch(P, Vec, MatchSource), ExprClosure(CaptureClause, Option, P, P), - ExprProc(P, P), ExprBlock(P), ExprAssign(P, P), @@ -1225,8 +1224,6 @@ pub enum Ty_ { TyRptr(Option, MutTy), /// A closure (e.g. `|uint| -> bool`) TyClosure(P), - /// A procedure (e.g `proc(uint) -> bool`) - TyProc(P), /// A bare function (e.g. `fn(uint) -> bool`) TyBareFn(P), /// A tuple (`(A, B, C, D,...)`) diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs index 75f69f2f6d0..5462918b662 100644 --- a/src/libsyntax/ast_map/blocks.rs +++ b/src/libsyntax/ast_map/blocks.rs @@ -37,7 +37,7 @@ use visit; /// /// More specifically, it is one of either: /// - A function item, -/// - A closure expr (i.e. an ExprClosure or ExprProc), or +/// - A closure expr (i.e. an ExprClosure), or /// - The default implementation for a trait method. /// /// To construct one, use the `Code::from_node` function. @@ -73,7 +73,7 @@ impl MaybeFnLike for ast::TraitItem { impl MaybeFnLike for ast::Expr { fn is_fn_like(&self) -> bool { match self.node { - ast::ExprClosure(..) | ast::ExprProc(..) => true, + ast::ExprClosure(..) => true, _ => false, } } @@ -222,8 +222,6 @@ impl<'a> FnLikeNode<'a> { ast_map::NodeExpr(e) => match e.node { ast::ExprClosure(_, _, ref decl, ref block) => closure(ClosureParts::new(&**decl, &**block, e.id, e.span)), - ast::ExprProc(ref decl, ref block) => - closure(ClosureParts::new(&**decl, &**block, e.id, e.span)), _ => panic!("expr FnLikeNode that is not fn-like"), }, _ => panic!("other FnLikeNode that is not fn-like"), diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 907ac6b19fc..6f1d2d39b30 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -859,7 +859,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { fn visit_ty(&mut self, ty: &'ast Ty) { match ty.node { - TyClosure(ref fd) | TyProc(ref fd) => { + TyClosure(ref fd) => { self.visit_fn_decl(&*fd.decl); } TyBareFn(ref fd) => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9c4e85f16ff..1a004ca7c44 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -217,13 +217,6 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { P(ast::Expr{id:id, node: new_node, span: fld.new_span(span)}) } - ast::ExprProc(fn_decl, block) => { - let (rewritten_fn_decl, rewritten_block) - = expand_and_rename_fn_decl_and_block(fn_decl, block, fld); - let new_node = ast::ExprProc(rewritten_fn_decl, rewritten_block); - P(ast::Expr{id:id, node: new_node, span: fld.new_span(span)}) - } - _ => { P(noop_fold_expr(ast::Expr { id: id, @@ -1576,17 +1569,6 @@ mod test { 0) } - // closure arg hygiene (ExprProc) - // expands to fn f(){(proc(x_1 : int) {(x_2 + x_1)})(3);} - #[test] fn closure_arg_hygiene_2(){ - run_renaming_test( - &("macro_rules! inject_x (()=>(x)) - fn f(){ (proc(x : int){(inject_x!() + x)})(3); }", - vec!(vec!(1)), - true), - 0) - } - // macro_rules in method position. Sadly, unimplemented. #[test] fn macro_in_method_posn(){ expand_crate_str( diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2ee4957ec0f..66fe672c3e5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -306,12 +306,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { - ast::ExprClosure(_, Some(_), _, _) => { - self.gate_feature("unboxed_closures", - e.span, - "unboxed closures are a work-in-progress \ - feature with known bugs"); - } ast::ExprSlice(..) => { self.gate_feature("slicing_syntax", e.span, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0318dd5b0cd..611faa2c2c9 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -425,17 +425,6 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { } })) } - TyProc(f) => { - TyProc(f.map(|ClosureTy {fn_style, onceness, bounds, decl, lifetimes}| { - ClosureTy { - fn_style: fn_style, - onceness: onceness, - bounds: fld.fold_bounds(bounds), - decl: fld.fold_fn_decl(decl), - lifetimes: fld.fold_lifetime_defs(lifetimes) - } - })) - } TyBareFn(f) => { TyBareFn(f.map(|BareFnTy {lifetimes, fn_style, abi, decl}| BareFnTy { lifetimes: fld.fold_lifetime_defs(lifetimes), @@ -1360,10 +1349,6 @@ pub fn noop_fold_expr(Expr {id, node, span}: Expr, folder: &mut T) -> arms.move_map(|x| folder.fold_arm(x)), source) } - ExprProc(decl, body) => { - ExprProc(folder.fold_fn_decl(decl), - folder.fold_block(body)) - } ExprClosure(capture_clause, opt_kind, decl, body) => { ExprClosure(capture_clause, opt_kind, diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 2a2bb42cef0..3a7cc77515d 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -32,6 +32,8 @@ pub enum ObsoleteSyntax { ObsoleteImportRenaming, ObsoleteSubsliceMatch, ObsoleteExternCrateRenaming, + ObsoleteProcType, + ObsoleteProcExpr, } impl Copy for ObsoleteSyntax {} @@ -55,6 +57,14 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> { /// Reports an obsolete syntax non-fatal error. fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) { let (kind_str, desc) = match kind { + ObsoleteProcType => ( + "the `proc` type", + "use unboxed closures instead", + ), + ObsoleteProcExpr => ( + "`proc` expression", + "use a `move ||` expression instead", + ), ObsoleteOwnedType => ( "`~` notation for owned pointers", "use `Box` in `std::owned` instead" diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e9cc91d9415..381942a3e62 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,10 +27,10 @@ use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; use ast::{ExprBreak, ExprCall, ExprCast}; use ast::{ExprField, ExprTupField, ExprClosure, ExprIf, ExprIfLet, ExprIndex, ExprSlice}; use ast::{ExprLit, ExprLoop, ExprMac}; -use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc}; +use ast::{ExprMethodCall, ExprParen, ExprPath}; use ast::{ExprRepeat, ExprRet, ExprStruct, ExprTup, ExprUnary}; use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl}; -use ast::{Once, Many}; +use ast::{Many}; use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind}; use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy}; @@ -54,7 +54,7 @@ use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{TtDelimited, TtSequence, TtToken}; use ast::{TupleVariantKind, Ty, Ty_, TypeBinding}; -use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn}; +use ast::{TypeField, TyFixedLengthVec, TyClosure, TyBareFn}; use ast::{TyTypeof, TyInfer, TypeMethod}; use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath}; use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq}; @@ -1064,7 +1064,6 @@ impl<'a> Parser<'a> { Deprecated: - for <'lt> |S| -> T - - for <'lt> proc(S) -> T Eventually: @@ -1158,26 +1157,21 @@ impl<'a> Parser<'a> { | | | Bounds | | Argument types | Legacy lifetimes - the `proc` keyword + the `proc` keyword (already consumed) */ - let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs); - let (inputs, variadic) = self.parse_fn_args(false, false); - let bounds = self.parse_colon_then_ty_param_bounds(); - let ret_ty = self.parse_ret_ty(); - let decl = P(FnDecl { - inputs: inputs, - output: ret_ty, - variadic: variadic - }); - TyProc(P(ClosureTy { - fn_style: NormalFn, - onceness: Once, - bounds: bounds, - decl: decl, - lifetimes: lifetime_defs, - })) + let proc_span = self.last_span; + + // To be helpful, parse the proc as ever + let _ = self.parse_legacy_lifetime_defs(lifetime_defs); + let _ = self.parse_fn_args(false, false); + let _ = self.parse_colon_then_ty_param_bounds(); + let _ = self.parse_ret_ty(); + + self.obsolete(proc_span, ObsoleteProcType); + + TyInfer } /// Parses an optional unboxed closure kind (`&:`, `&mut:`, or `:`). @@ -2294,17 +2288,10 @@ impl<'a> Parser<'a> { return self.parse_lambda_expr(CaptureByValue); } if self.eat_keyword(keywords::Proc) { - let decl = self.parse_proc_decl(); - let body = self.parse_expr(); - let fakeblock = P(ast::Block { - id: ast::DUMMY_NODE_ID, - view_items: Vec::new(), - stmts: Vec::new(), - rules: DefaultBlock, - span: body.span, - expr: Some(body), - }); - return self.mk_expr(lo, fakeblock.span.hi, ExprProc(decl, fakeblock)); + let span = self.last_span; + let _ = self.parse_proc_decl(); + let _ = self.parse_expr(); + return self.obsolete_expr(span, ObsoleteProcExpr); } if self.eat_keyword(keywords::If) { return self.parse_if_expr(); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6d8b8dcb8ba..87905db22f3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -450,7 +450,7 @@ pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String { fn needs_parentheses(expr: &ast::Expr) -> bool { match expr.node { ast::ExprAssign(..) | ast::ExprBinary(..) | - ast::ExprClosure(..) | ast::ExprProc(..) | + ast::ExprClosure(..) | ast::ExprAssignOp(..) | ast::ExprCast(..) => true, _ => false, } @@ -734,25 +734,6 @@ impl<'a> State<'a> { Some(&generics), None)); } - ast::TyProc(ref f) => { - let generics = ast::Generics { - lifetimes: f.lifetimes.clone(), - ty_params: OwnedSlice::empty(), - where_clause: ast::WhereClause { - id: ast::DUMMY_NODE_ID, - predicates: Vec::new(), - }, - }; - try!(self.print_ty_fn(None, - Some('~'), - f.fn_style, - f.onceness, - &*f.decl, - None, - &f.bounds, - Some(&generics), - None)); - } ast::TyPath(ref path, _) => { try!(self.print_path(path, false)); } @@ -1696,33 +1677,6 @@ impl<'a> State<'a> { // empty box to satisfy the close. try!(self.ibox(0)); } - ast::ExprProc(ref decl, ref body) => { - // in do/for blocks we don't want to show an empty - // argument list, but at this point we don't know which - // we are inside. - // - // if !decl.inputs.is_empty() { - try!(self.print_proc_args(&**decl)); - try!(space(&mut self.s)); - // } - assert!(body.stmts.is_empty()); - assert!(body.expr.is_some()); - // we extract the block, so as not to create another set of boxes - match body.expr.as_ref().unwrap().node { - ast::ExprBlock(ref blk) => { - try!(self.print_block_unclosed(&**blk)); - } - _ => { - // this is a bare expression - try!(self.print_expr(body.expr.as_ref().map(|e| &**e).unwrap())); - try!(self.end()); // need to close a box - } - } - // a box will be closed by print_expr, but we didn't want an overall - // wrapper so we closed the corresponding opening. so create an - // empty box to satisfy the close. - try!(self.ibox(0)); - } ast::ExprBlock(ref blk) => { // containing cbox, will be closed by print-block at } try!(self.cbox(indent_unit)); @@ -2010,6 +1964,7 @@ impl<'a> State<'a> { match data.output { None => { } Some(ref ty) => { + try!(self.space_if_not_bol()); try!(self.word_space("->")); try!(self.print_type(&**ty)); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a36f8b23ca3..eca99df8e55 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -389,14 +389,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { walk_ty_param_bounds_helper(visitor, &function_declaration.bounds); walk_lifetime_decls_helper(visitor, &function_declaration.lifetimes); } - TyProc(ref function_declaration) => { - for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty) - } - walk_fn_ret_ty(visitor, &function_declaration.decl.output); - walk_ty_param_bounds_helper(visitor, &function_declaration.bounds); - walk_lifetime_decls_helper(visitor, &function_declaration.lifetimes); - } TyBareFn(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(&*argument.ty) @@ -831,13 +823,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { expression.span, expression.id) } - ExprProc(ref function_declaration, ref body) => { - visitor.visit_fn(FkFnBlock, - &**function_declaration, - &**body, - expression.span, - expression.id) - } ExprBlock(ref block) => visitor.visit_block(&**block), ExprAssign(ref left_hand_expression, ref right_hand_expression) => { visitor.visit_expr(&**right_hand_expression); -- cgit 1.4.1-3-g733a5