From cc8a5a0db7183fe3c233053bdadc6226f3dbd6e4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 27 Feb 2015 20:58:26 -0500 Subject: [PATCH 1/2] obsolete `|&:|` syntax closes #22881 --- src/libsyntax/parse/parser.rs | 1 - src/test/parse-fail/obsolete-closure-kind.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/parse-fail/obsolete-closure-kind.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f171e8279f4..9de7b0ede78 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1163,7 +1163,6 @@ impl<'a> Parser<'a> { { self.bump(); self.bump(); - return; } else if self.eat(&token::Colon) { diff --git a/src/test/parse-fail/obsolete-closure-kind.rs b/src/test/parse-fail/obsolete-closure-kind.rs new file mode 100644 index 00000000000..89134e806a7 --- /dev/null +++ b/src/test/parse-fail/obsolete-closure-kind.rs @@ -0,0 +1,18 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we generate obsolete syntax errors around usages of closure kinds: `|:|`, `|&:|` and +// `|&mut:|`. + +fn main() { + let a = |:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:` + let a = |&:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:` + let a = |&mut:| {}; //~ ERROR obsolete syntax: `:`, `&mut:`, or `&:` +} From 7ad2e22e4ee1cfc5c6c4a53a6d19f2b853de1c6e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 27 Feb 2015 21:21:09 -0500 Subject: [PATCH 2/2] remove leftover annotations --- src/doc/reference.md | 4 ++-- src/librustc/middle/const_eval.rs | 2 +- src/librustc_typeck/check/dropck.rs | 2 +- src/libstd/sys/unix/process2.rs | 2 +- src/libstd/sys/windows/process2.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 781b40be768..b5ad7cc22f3 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3752,9 +3752,9 @@ An example of creating and calling a closure: ```rust let captured_var = 10; -let closure_no_args = |&:| println!("captured_var={}", captured_var); +let closure_no_args = || println!("captured_var={}", captured_var); -let closure_args = |&: arg: i32| -> i32 { +let closure_args = |arg: i32| -> i32 { println!("captured_var={}, arg={}", captured_var, arg); arg // Note lack of semicolon after 'arg' }; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f793d3ce2fb..0c9f9d2a530 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -257,7 +257,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>, } } (Ok(const_int(a)), Ok(const_int(b))) => { - let is_a_min_value = |&:| { + let is_a_min_value = || { let int_ty = match ty::expr_ty_opt(tcx, e).map(|ty| &ty.sty) { Some(&ty::ty_int(int_ty)) => int_ty, _ => return false diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index ce67369ca9d..083523f7ba9 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -45,7 +45,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>( scope: region::CodeExtent, depth: uint) { - let origin = |&:| infer::SubregionOrigin::SafeDestructor(span); + let origin = || infer::SubregionOrigin::SafeDestructor(span); let mut walker = ty_root.walk(); let opt_phantom_data_def_id = rcx.tcx().lang_items.phantom_data(); diff --git a/src/libstd/sys/unix/process2.rs b/src/libstd/sys/unix/process2.rs index b7a1b002f55..1b77b4fe75c 100644 --- a/src/libstd/sys/unix/process2.rs +++ b/src/libstd/sys/unix/process2.rs @@ -274,7 +274,7 @@ impl Process { // file descriptor. Otherwise, the first file descriptor opened // up in the child would be numbered as one of the stdio file // descriptors, which is likely to wreak havoc. - let setup = |&: src: Option, dst: c_int| { + let setup = |src: Option, dst: c_int| { let src = match src { None => { let flags = if dst == libc::STDIN_FILENO { diff --git a/src/libstd/sys/windows/process2.rs b/src/libstd/sys/windows/process2.rs index d4c6e85489f..8a6a485cbbe 100644 --- a/src/libstd/sys/windows/process2.rs +++ b/src/libstd/sys/windows/process2.rs @@ -160,7 +160,7 @@ impl Process { // Similarly to unix, we don't actually leave holes for the stdio file // descriptors, but rather open up /dev/null equivalents. These // equivalents are drawn from libuv's windows process spawning. - let set_fd = |&: fd: &Option, slot: &mut HANDLE, + let set_fd = |fd: &Option, slot: &mut HANDLE, is_stdin: bool| { match *fd { None => {