From 27db6e1e5152a2c12bff9861b132aca09e607f0e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Aug 2015 18:14:37 +0530 Subject: [PATCH 1/2] Impl Eq/PartialEq on FnKind, improve docs --- src/libsyntax/visit.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 259564337a2..c92934de756 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -32,7 +32,7 @@ use codemap::Span; use ptr::P; use owned_slice::OwnedSlice; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq)] pub enum FnKind<'a> { /// fn foo() or extern "Abi" fn foo() FkItemFn(Ident, &'a Generics, Unsafety, Constness, Abi, Visibility), @@ -40,8 +40,7 @@ pub enum FnKind<'a> { /// fn foo(&self) FkMethod(Ident, &'a MethodSig, Option), - /// |x, y| ... - /// proc(x, y) ... + /// Closures (|x, y| {}) FkFnBlock, } From c03bf18b84bb47b1b86a26c49db7d4e5f1acc30d Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 16 Aug 2015 18:23:58 +0530 Subject: [PATCH 2/2] FnFnBlock -> FkClosure --- src/librustc/ast_map/blocks.rs | 2 +- src/librustc/middle/check_match.rs | 2 +- src/librustc/middle/intrinsicck.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 4 ++-- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_typeck/check/wf.rs | 2 +- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/visit.rs | 8 ++++---- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc/ast_map/blocks.rs b/src/librustc/ast_map/blocks.rs index 6c9ed29768f..59eba6880a6 100644 --- a/src/librustc/ast_map/blocks.rs +++ b/src/librustc/ast_map/blocks.rs @@ -191,7 +191,7 @@ impl<'a> FnLikeNode<'a> { visit::FkItemFn(p.ident, p.generics, p.unsafety, p.constness, p.abi, p.vis) }; let closure = |_: ClosureParts| { - visit::FkFnBlock + visit::FkClosure }; let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| { visit::FkMethod(ident, sig, vis) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index b9d8e4b842d..ad7cf1a239a 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -1006,7 +1006,7 @@ fn check_fn(cx: &mut MatchCheckCtxt, sp: Span, fn_id: NodeId) { match kind { - visit::FkFnBlock => {} + visit::FkClosure => {} _ => cx.param_env = ParameterEnvironment::for_item(cx.tcx, fn_id), } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 93899a5cf80..34da5c7062d 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -241,7 +241,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> { visit::walk_fn(self, fk, fd, b, s); self.param_envs.pop(); } - visit::FkFnBlock(..) => { + visit::FkClosure(..) => { visit::walk_fn(self, fk, fd, b, s); } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 95b8161ac34..fee24f61d4c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -186,7 +186,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> { this.walk_fn(fk, fd, b, s) }) } - visit::FkFnBlock(..) => { + visit::FkClosure(..) => { self.walk_fn(fk, fd, b, s) } } @@ -484,7 +484,7 @@ impl<'a> LifetimeContext<'a> { self.visit_generics(&sig.generics); self.visit_explicit_self(&sig.explicit_self); } - visit::FkFnBlock(..) => { + visit::FkClosure(..) => { visit::walk_fn_decl(self, fd); } } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index e050276fc76..0c1abd011fa 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -67,7 +67,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> { self.free_region_map = old_free_region_map; } - visit::FkFnBlock => { + visit::FkClosure => { borrowck_fn(self, fk, fd, b, s, id); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f5819316477..79539fc7a6e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2133,7 +2133,7 @@ impl LintPass for UnconditionalRecursion { cx.tcx.impl_or_trait_item(local_def(id)).as_opt_method() } // closures can't recur, so they don't matter. - visit::FkFnBlock => return + visit::FkClosure => return }; // Walk through this function (say `f`) looking to see if diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 8127c2dee2c..b3a266e4014 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -524,7 +524,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> { self.visit_explicit_self(&sig.explicit_self); MethodRibKind } - visit::FkFnBlock(..) => ClosureRibKind(node_id) + visit::FkClosure(..) => ClosureRibKind(node_id) }; self.resolve_function(rib_kind, declaration, block); } diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 47eb1f472c3..48cedd8c82e 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -428,7 +428,7 @@ impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> { fk: visit::FnKind<'v>, fd: &'v ast::FnDecl, b: &'v ast::Block, span: Span, id: ast::NodeId) { match fk { - visit::FkFnBlock | visit::FkItemFn(..) => {} + visit::FkClosure | visit::FkItemFn(..) => {} visit::FkMethod(..) => { match self.tcx().impl_or_trait_item(local_def(id)) { ty::ImplOrTraitItem::MethodTraitItem(ty_method) => { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 7aff92ecb70..d2f54ac6d82 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -444,7 +444,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { visit::FkMethod(_, sig, _) => { self.visit_generics_helper(&sig.generics) } - visit::FkFnBlock => {} + visit::FkClosure => {} } for argument in &function_declaration.inputs { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index c92934de756..824aee74ce5 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -40,8 +40,8 @@ pub enum FnKind<'a> { /// fn foo(&self) FkMethod(Ident, &'a MethodSig, Option), - /// Closures (|x, y| {}) - FkFnBlock, + /// |x, y| {} + FkClosure, } /// Each method of the Visitor trait is a hook to be potentially @@ -615,7 +615,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, visitor.visit_generics(&sig.generics); visitor.visit_explicit_self(&sig.explicit_self); } - FkFnBlock(..) => {} + FkClosure(..) => {} } visitor.visit_block(function_body) @@ -816,7 +816,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } } ExprClosure(_, ref function_declaration, ref body) => { - visitor.visit_fn(FkFnBlock, + visitor.visit_fn(FkClosure, &**function_declaration, &**body, expression.span,