1
Fork 0

libsyntax: Remove the old-style borrowed closure type syntax from the

language.
This commit is contained in:
Patrick Walton 2013-11-19 18:15:10 -08:00
parent 9e610573ba
commit 6801bc8f55
15 changed files with 32 additions and 23 deletions

View file

@ -301,8 +301,8 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
return valid; return valid;
} }
pub fn make_test(config: &config, testfile: &Path, pub fn make_test(config: &config, testfile: &Path, f: || -> test::TestFn)
f: &fn()->test::TestFn) -> test::TestDescAndFn { -> test::TestDescAndFn {
test::TestDescAndFn { test::TestDescAndFn {
desc: test::TestDesc { desc: test::TestDesc {
name: make_test_name(config, testfile), name: make_test_name(config, testfile),

View file

@ -102,7 +102,7 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
!val !val
} }
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool { fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
use std::io::buffered::BufferedReader; use std::io::buffered::BufferedReader;
use std::io::File; use std::io::File;

View file

@ -730,9 +730,12 @@ fn compose_and_run(config: &config, testfile: &Path,
prog, args, procenv, input); prog, args, procenv, input);
} }
fn make_compile_args(config: &config, props: &TestProps, extras: ~[~str], fn make_compile_args(config: &config,
xform: &fn(&config, (&Path)) -> Path, props: &TestProps,
testfile: &Path) -> ProcArgs { extras: ~[~str],
xform: |&config, &Path| -> Path,
testfile: &Path)
-> ProcArgs {
let xform_file = xform(config, testfile); let xform_file = xform(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths // FIXME (#9639): This needs to handle non-utf8 paths
let mut args = ~[testfile.as_str().unwrap().to_owned(), let mut args = ~[testfile.as_str().unwrap().to_owned(),

View file

@ -120,7 +120,7 @@ impl Drop for Addrinfo {
} }
} }
fn each_ai_flag(_f: &fn(c_int, ai::Flag)) { fn each_ai_flag(_f: |c_int, ai::Flag|) {
/* XXX: do we really want to support these? /* XXX: do we really want to support these?
unsafe { unsafe {
f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig); f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig);

View file

@ -294,7 +294,7 @@ impl Drop for FsRequest {
} }
} }
fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int) fn execute(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int)
-> Result<FsRequest, UvError> -> Result<FsRequest, UvError>
{ {
let mut req = FsRequest { let mut req = FsRequest {
@ -326,9 +326,8 @@ fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int)
} }
} }
fn execute_nop(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int) fn execute_nop(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int)
-> Result<(), UvError> -> Result<(), UvError> {
{
execute(f).map(|_| {}) execute(f).map(|_| {})
} }

View file

@ -196,7 +196,7 @@ impl Drop for ForbidUnwind {
} }
} }
fn wait_until_woken_after(slot: *mut Option<BlockedTask>, f: &fn()) { fn wait_until_woken_after(slot: *mut Option<BlockedTask>, f: ||) {
let _f = ForbidUnwind::new("wait_until_woken_after"); let _f = ForbidUnwind::new("wait_until_woken_after");
unsafe { unsafe {
assert!((*slot).is_none()); assert!((*slot).is_none());

View file

@ -34,7 +34,7 @@ use uvll::sockaddr;
/// Generic functions related to dealing with sockaddr things /// Generic functions related to dealing with sockaddr things
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
fn socket_addr_as_sockaddr<T>(addr: SocketAddr, f: &fn(*sockaddr) -> T) -> T { fn socket_addr_as_sockaddr<T>(addr: SocketAddr, f: |*sockaddr| -> T) -> T {
let malloc = match addr.ip { let malloc = match addr.ip {
Ipv4Addr(*) => uvll::rust_malloc_ip4_addr, Ipv4Addr(*) => uvll::rust_malloc_ip4_addr,
Ipv6Addr(*) => uvll::rust_malloc_ip6_addr, Ipv6Addr(*) => uvll::rust_malloc_ip6_addr,

View file

@ -148,7 +148,7 @@ unsafe fn set_stdio(dst: *uvll::uv_stdio_container_t,
} }
/// Converts the program and arguments to the argv array expected by libuv /// Converts the program and arguments to the argv array expected by libuv
fn with_argv<T>(prog: &str, args: &[~str], f: &fn(**libc::c_char) -> T) -> T { fn with_argv<T>(prog: &str, args: &[~str], f: |**libc::c_char| -> T) -> T {
// First, allocation space to put all the C-strings (we need to have // First, allocation space to put all the C-strings (we need to have
// ownership of them somewhere // ownership of them somewhere
let mut c_strs = vec::with_capacity(args.len() + 1); let mut c_strs = vec::with_capacity(args.len() + 1);
@ -167,7 +167,7 @@ fn with_argv<T>(prog: &str, args: &[~str], f: &fn(**libc::c_char) -> T) -> T {
} }
/// Converts the environment to the env array expected by libuv /// Converts the environment to the env array expected by libuv
fn with_env<T>(env: Option<&[(~str, ~str)]>, f: &fn(**libc::c_char) -> T) -> T { fn with_env<T>(env: Option<&[(~str, ~str)]>, f: |**libc::c_char| -> T) -> T {
let env = match env { let env = match env {
Some(s) => s, Some(s) => s,
None => { return f(ptr::null()); } None => { return f(ptr::null()); }

View file

@ -161,7 +161,7 @@ impl EventLoop for UvEventLoop {
~AsyncWatcher::new(self.uvio.uv_loop(), f) as ~RemoteCallback ~AsyncWatcher::new(self.uvio.uv_loop(), f) as ~RemoteCallback
} }
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) { fn io<'a>(&'a mut self, f: |&'a mut IoFactory|) {
f(&mut self.uvio as &mut IoFactory) f(&mut self.uvio as &mut IoFactory)
} }
} }

View file

@ -43,6 +43,7 @@ pub enum ObsoleteSyntax {
ObsoleteStructWildcard, ObsoleteStructWildcard,
ObsoleteVecDotDotWildcard, ObsoleteVecDotDotWildcard,
ObsoleteBoxedClosure, ObsoleteBoxedClosure,
ObsoleteClosureType,
} }
impl to_bytes::IterBytes for ObsoleteSyntax { impl to_bytes::IterBytes for ObsoleteSyntax {
@ -134,6 +135,11 @@ impl ParserObsoleteMethods for Parser {
"managed closures have been removed and owned closures are \ "managed closures have been removed and owned closures are \
now written `proc()`" now written `proc()`"
), ),
ObsoleteClosureType => (
"closure type",
"closures are now written `|A| -> B` rather than `&fn(A) -> \
B`."
),
}; };
self.report(sp, kind, kind_str, desc); self.report(sp, kind, kind_str, desc);

View file

@ -1286,7 +1286,7 @@ impl Parser {
return self.parse_ty_closure(Some(sigil), Some(lifetime)); return self.parse_ty_closure(Some(sigil), Some(lifetime));
} }
token::IDENT(*) if sigil == ast::BorrowedSigil => { token::IDENT(*) => {
if self.token_is_old_style_closure_keyword() { if self.token_is_old_style_closure_keyword() {
self.obsolete(*self.last_span, ObsoleteBoxedClosure); self.obsolete(*self.last_span, ObsoleteBoxedClosure);
return self.parse_ty_closure(Some(sigil), None); return self.parse_ty_closure(Some(sigil), None);
@ -1311,6 +1311,7 @@ impl Parser {
let opt_lifetime = self.parse_opt_lifetime(); let opt_lifetime = self.parse_opt_lifetime();
if self.token_is_old_style_closure_keyword() { if self.token_is_old_style_closure_keyword() {
self.obsolete(*self.last_span, ObsoleteClosureType);
return self.parse_ty_closure(Some(BorrowedSigil), opt_lifetime); return self.parse_ty_closure(Some(BorrowedSigil), opt_lifetime);
} }

View file

@ -9,10 +9,10 @@
// except according to those terms. // except according to those terms.
struct X { struct X {
field: &'static fn:Send(), field: 'static ||:Send,
} }
fn foo(blk: &'static fn:()) -> X { fn foo(blk: 'static ||:) -> X {
return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
} }

View file

@ -16,7 +16,7 @@ extern mod extra;
use extra::arc; use extra::arc;
use std::util; use std::util;
fn foo(blk: &once fn()) { fn foo(blk: once ||) {
blk(); blk();
blk(); //~ ERROR use of moved value blk(); //~ ERROR use of moved value
} }

View file

@ -10,8 +10,8 @@
#[feature(once_fns)]; #[feature(once_fns)];
fn main() { fn main() {
let f: &once fn() = ||(); let f: once || = ||();
let g: || = f; //~ ERROR mismatched types let g: || = f; //~ ERROR mismatched types
let h: || = ||(); let h: || = ||();
let i: &once fn() = h; // ok let i: once || = h; // ok
} }

View file

@ -17,7 +17,7 @@ extern mod extra;
use extra::arc; use extra::arc;
use std::util; use std::util;
fn foo(blk: &once fn()) { fn foo(blk: once ||) {
blk(); blk();
} }