From a291a80fbe1222fd708b1e5612b8056cf9311cae Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 08:34:44 -0500 Subject: [PATCH 01/37] register snapshot --- src/libcollections/bit.rs | 15 --------------- src/libcollections/btree/map.rs | 24 ------------------------ src/libcollections/ring_buf.rs | 22 ---------------------- src/libcollections/vec.rs | 21 --------------------- src/libcollections/vec_map.rs | 22 ---------------------- src/libcore/ops.rs | 20 -------------------- src/libcore/slice.rs | 22 ---------------------- src/libserialize/json.rs | 21 --------------------- src/libstd/collections/hash/map.rs | 26 -------------------------- src/snapshots.txt | 9 +++++++++ 10 files changed, 9 insertions(+), 193 deletions(-) diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 5e7089bb7aca2..c092e000215d3 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -164,21 +164,6 @@ pub struct Bitv { nbits: uint } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) -impl Index for Bitv { - #[inline] - fn index(&self, i: &uint) -> &bool { - if self.get(*i).expect("index out of bounds") { - &TRUE - } else { - &FALSE - } - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot // FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) impl Index for Bitv { type Output = bool; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index a9e09a584d687..ea504530c4b21 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -877,18 +877,6 @@ impl Show for BTreeMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl Index for BTreeMap - where Q: BorrowFrom + Ord -{ - fn index(&self, key: &Q) -> &V { - self.get(key).expect("no entry found for key") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl Index for BTreeMap where Q: BorrowFrom + Ord @@ -900,18 +888,6 @@ impl Index for BTreeMap } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl IndexMut for BTreeMap - where Q: BorrowFrom + Ord -{ - fn index_mut(&mut self, key: &Q) -> &mut V { - self.get_mut(key).expect("no entry found for key") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl IndexMut for BTreeMap where Q: BorrowFrom + Ord diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index e86c40bed212f..ce9643b3b4391 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1360,17 +1360,6 @@ impl> Hash for RingBuf { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl Index for RingBuf { - #[inline] - fn index<'a>(&'a self, i: &uint) -> &'a A { - self.get(*i).expect("Out of bounds access") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl Index for RingBuf { type Output = A; @@ -1381,17 +1370,6 @@ impl Index for RingBuf { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl IndexMut for RingBuf { - #[inline] - fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A { - self.get_mut(*i).expect("Out of bounds access") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl IndexMut for RingBuf { type Output = A; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b8f97799c9718..4e3fd44072784 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1190,17 +1190,6 @@ impl> Hash for Vec { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[experimental = "waiting on Index stability"] -impl Index for Vec { - #[inline] - fn index<'a>(&'a self, index: &uint) -> &'a T { - &self.as_slice()[*index] - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[experimental = "waiting on Index stability"] impl Index for Vec { type Output = T; @@ -1211,16 +1200,6 @@ impl Index for Vec { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IndexMut for Vec { - #[inline] - fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { - &mut self.as_mut_slice()[*index] - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl IndexMut for Vec { type Output = T; diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index ab6c6b7ca55bf..cc757b656238e 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -517,17 +517,6 @@ impl Extend<(uint, V)> for VecMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl Index for VecMap { - #[inline] - fn index<'a>(&'a self, i: &uint) -> &'a V { - self.get(i).expect("key not present") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl Index for VecMap { type Output = V; @@ -537,17 +526,6 @@ impl Index for VecMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl IndexMut for VecMap { - #[inline] - fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V { - self.get_mut(i).expect("key not present") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl IndexMut for VecMap { type Output = V; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index c9b71092f9072..17e4c5f8215a8 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -717,15 +717,6 @@ macro_rules! shr_impl { shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } -// NOTE(stage0) remove trait after a snapshot -#[cfg(stage0)] -#[allow(missing_docs)] -#[lang="index"] -pub trait Index for Sized? { - /// The method for the indexing (`Foo[Bar]`) operation - fn index<'a>(&'a self, index: &Index) -> &'a Result; -} - /// The `Index` trait is used to specify the functionality of indexing operations /// like `arr[idx]` when used in an immutable context. /// @@ -755,7 +746,6 @@ pub trait Index for Sized? { /// Foo[Foo]; /// } /// ``` -#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot #[lang="index"] pub trait Index for Sized? { type Sized? Output; @@ -764,15 +754,6 @@ pub trait Index for Sized? { fn index<'a>(&'a self, index: &Index) -> &'a Self::Output; } -// NOTE(stage0) remove trait after a snapshot -#[cfg(stage0)] -#[allow(missing_docs)] -#[lang="index_mut"] -pub trait IndexMut for Sized? { - /// The method for the indexing (`Foo[Bar]`) operation - fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; -} - /// The `IndexMut` trait is used to specify the functionality of indexing /// operations like `arr[idx]`, when used in a mutable context. /// @@ -802,7 +783,6 @@ pub trait IndexMut for Sized? { /// &mut Foo[Foo]; /// } /// ``` -#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot #[lang="index_mut"] pub trait IndexMut for Sized? { type Sized? Output; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index f17a775cf4240..7aed16173e988 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -531,17 +531,6 @@ impl SliceExt for [T] { } } -// NOTE(stage0) remove impl after a snapshot -#[cfg(stage0)] -impl ops::Index for [T] { - fn index(&self, &index: &uint) -> &T { - assert!(index < self.len()); - - unsafe { mem::transmute(self.repr().data.offset(index as int)) } - } -} - -#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot impl ops::Index for [T] { type Output = T; @@ -552,17 +541,6 @@ impl ops::Index for [T] { } } -// NOTE(stage0) remove impl after a snapshot -#[cfg(stage0)] -impl ops::IndexMut for [T] { - fn index_mut(&mut self, &index: &uint) -> &mut T { - assert!(index < self.len()); - - unsafe { mem::transmute(self.repr().data.offset(index as int)) } - } -} - -#[cfg(not(stage0))] // NOTE(stage0) remove cfg after a snapshot impl ops::IndexMut for [T] { type Output = T; diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index e8bd46815e6ac..bd4cb1884a69a 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1125,15 +1125,6 @@ impl Json { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a> ops::Index<&'a str, Json> for Json { - fn index(&self, idx: & &str) -> &Json { - self.find(*idx).unwrap() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a> ops::Index<&'a str> for Json { type Output = Json; @@ -1142,18 +1133,6 @@ impl<'a> ops::Index<&'a str> for Json { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl ops::Index for Json { - fn index<'a>(&'a self, idx: &uint) -> &'a Json { - match self { - &Json::Array(ref v) => v.index(idx), - _ => panic!("can only index Json with uint if it is an array") - } - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl ops::Index for Json { type Output = Json; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index a6532707f3e36..c35be86420de8 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1226,19 +1226,6 @@ impl, V, S, H: Hasher + Default> Default for HashMap } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -#[stable] -impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap - where Q: BorrowFrom + Hash + Eq -{ - #[inline] - fn index<'a>(&'a self, index: &Q) -> &'a V { - self.get(index).expect("no entry found for key") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap where Q: BorrowFrom + Hash + Eq @@ -1251,19 +1238,6 @@ impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap - where Q: BorrowFrom + Hash + Eq -{ - #[inline] - fn index_mut<'a>(&'a mut self, index: &Q) -> &'a mut V { - self.get_mut(index).expect("no entry found for key") - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable] impl + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap where Q: BorrowFrom + Hash + Eq diff --git a/src/snapshots.txt b/src/snapshots.txt index c72fd7978f885..5c21a8a8abfb0 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,12 @@ +S 2015-01-04 b2085d9 + freebsd-x86_64 50ccb6bf9c0645d0746a5167493a39b2be40c2d4 + linux-i386 b880b98d832c9a049b8ef6a50df50061e363de5a + linux-x86_64 82a09c162474b69d2d1e4e8399086f3f0f4e31c3 + macos-i386 569055bb10d96ab25f78ecf2c80ffbccd5e69b8d + macos-x86_64 cff1f9ebd63dae6890359b7d353bd9486d8ecdfc + winnt-i386 553790fe493413287a19d17a42bf7225d3e2272d + winnt-x86_64 bab0d13960afb7ccdd6bf11452de1b9c457cc3e9 + S 2015-01-02 c894171 freebsd-x86_64 ea8bcf75eada3539f5cbab51708eecf40d436b77 linux-i386 646ae265721e3cbe19404aae4fea4ffa1f1d90cf From 37f62ae1c0ee44cb6ca563c18da19b8d5be58c0e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 1 Jan 2015 18:07:31 -0500 Subject: [PATCH 02/37] std: remove remaining boxed closures --- src/libstd/io/fs.rs | 8 +++++--- src/libstd/io/net/ip.rs | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 5cb79d41db940..4691c06c1de16 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -518,14 +518,16 @@ pub fn rmdir(path: &Path) -> IoResult<()> { /// use std::io; /// /// // one possible implementation of fs::walk_dir only visiting files -/// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> { +/// fn visit_dirs(dir: &Path, cb: &mut F) -> io::IoResult<()> where +/// F: FnMut(&Path), +/// { /// if dir.is_dir() { /// let contents = try!(fs::readdir(dir)); /// for entry in contents.iter() { /// if entry.is_dir() { -/// try!(visit_dirs(entry, |p| cb(p))); +/// try!(visit_dirs(entry, cb)); /// } else { -/// cb(entry); +/// (*cb)(entry); /// } /// } /// Ok(()) diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 52b589b5f24a7..d398b61fe64cf 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -17,11 +17,12 @@ pub use self::IpAddr::*; +use boxed::Box; use fmt; use io::{self, IoResult, IoError}; use io::net; use iter::{Iterator, IteratorExt}; -use ops::FnOnce; +use ops::{FnOnce, FnMut}; use option::Option; use option::Option::{None, Some}; use result::Result::{Ok, Err}; @@ -120,10 +121,10 @@ impl<'a> Parser<'a> { } // Return result of first successful parser - fn read_or(&mut self, parsers: &mut [|&mut Parser| -> Option]) + fn read_or(&mut self, parsers: &mut [Box Option>]) -> Option { for pf in parsers.iter_mut() { - match self.read_atomically(|p: &mut Parser| (*pf)(p)) { + match self.read_atomically(|p: &mut Parser| pf.call_mut((p,))) { Some(r) => return Some(r), None => {} } @@ -320,22 +321,22 @@ impl<'a> Parser<'a> { } fn read_ip_addr(&mut self) -> Option { - let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr(); - let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr(); - self.read_or(&mut [ipv4_addr, ipv6_addr]) + let ipv4_addr = |&mut: p: &mut Parser| p.read_ipv4_addr(); + let ipv6_addr = |&mut: p: &mut Parser| p.read_ipv6_addr(); + self.read_or(&mut [box ipv4_addr, box ipv6_addr]) } fn read_socket_addr(&mut self) -> Option { let ip_addr = |&: p: &mut Parser| { - let ipv4_p = |p: &mut Parser| p.read_ip_addr(); - let ipv6_p = |p: &mut Parser| { + let ipv4_p = |&mut: p: &mut Parser| p.read_ip_addr(); + let ipv6_p = |&mut: p: &mut Parser| { let open_br = |&: p: &mut Parser| p.read_given_char('['); let ip_addr = |&: p: &mut Parser| p.read_ipv6_addr(); let clos_br = |&: p: &mut Parser| p.read_given_char(']'); p.read_seq_3::(open_br, ip_addr, clos_br) .map(|t| match t { (_, ip, _) => ip }) }; - p.read_or(&mut [ipv4_p, ipv6_p]) + p.read_or(&mut [box ipv4_p, box ipv6_p]) }; let colon = |&: p: &mut Parser| p.read_given_char(':'); let port = |&: p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16); From 07a8e7cfb5128a2b1697713a0ec84329e4e44f1a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 1 Jan 2015 18:32:49 -0500 Subject: [PATCH 03/37] syntax: remove remaining boxed closures --- src/libsyntax/ext/deriving/clone.rs | 2 +- src/libsyntax/ext/deriving/cmp/eq.rs | 6 +++--- src/libsyntax/ext/deriving/cmp/ord.rs | 8 ++++---- src/libsyntax/ext/deriving/cmp/totaleq.rs | 4 ++-- src/libsyntax/ext/deriving/cmp/totalord.rs | 4 ++-- src/libsyntax/ext/deriving/decodable.rs | 2 +- src/libsyntax/ext/deriving/default.rs | 2 +- src/libsyntax/ext/deriving/encodable.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 22 +++++++++------------- src/libsyntax/ext/deriving/hash.rs | 2 +- src/libsyntax/ext/deriving/primitive.rs | 4 ++-- src/libsyntax/ext/deriving/rand.rs | 2 +- src/libsyntax/ext/deriving/show.rs | 2 +- 13 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index eedec6f37c840..3c74a9f4431df 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -40,7 +40,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, args: Vec::new(), ret_ty: Self, attributes: attrs, - combine_substructure: combine_substructure(|c, s, sub| { + combine_substructure: combine_substructure(box |c, s, sub| { cs_clone("Clone", c, s, sub) }), } diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 7a67fab820de5..84d30a99004a4 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -40,7 +40,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, cx.expr_binary(span, ast::BiAnd, subexpr, eq) }, cx.expr_bool(span, true), - |cx, span, _, _| cx.expr_bool(span, false), + box |cx, span, _, _| cx.expr_bool(span, false), cx, span, substr) } fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { @@ -57,7 +57,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, cx.expr_binary(span, ast::BiOr, subexpr, eq) }, cx.expr_bool(span, false), - |cx, span, _, _| cx.expr_bool(span, true), + box |cx, span, _, _| cx.expr_bool(span, true), cx, span, substr) } @@ -72,7 +72,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("bool"))), attributes: attrs, - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { $f(a, b, c) }) } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index c02416bfbea3a..f9c8d95b30848 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -38,7 +38,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("bool"))), attributes: attrs, - combine_substructure: combine_substructure(|cx, span, substr| { + combine_substructure: combine_substructure(box |cx, span, substr| { cs_op($op, $equal, cx, span, substr) }) } @@ -61,7 +61,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, args: vec![borrowed_self()], ret_ty: ret_ty, attributes: attrs, - combine_substructure: combine_substructure(|cx, span, substr| { + combine_substructure: combine_substructure(box |cx, span, substr| { cs_partial_cmp(cx, span, substr) }) }; @@ -174,7 +174,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, cx.expr_block(cx.block(span, vec!(assign), Some(if_))) }, equals_expr.clone(), - |cx, span, (self_args, tag_tuple), _non_self_args| { + box |cx, span, (self_args, tag_tuple), _non_self_args| { if self_args.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`") } else { @@ -222,7 +222,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, cx.expr_binary(span, ast::BiOr, cmp, and) }, cx.expr_bool(span, equal), - |cx, span, (self_args, tag_tuple), _non_self_args| { + box |cx, span, (self_args, tag_tuple), _non_self_args| { if self_args.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`") } else { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 2b986bea1221e..cdb36ede65da9 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -32,7 +32,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, let block = cx.block(span, stmts, None); cx.expr_block(block) }, - |cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"), + box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"), cx, span, substr) @@ -57,7 +57,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, args: vec!(), ret_ty: nil_ty(), attributes: attrs, - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { cs_total_eq_assert(a, b, c) }) } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 65a4c569b44b6..10ecc86bda530 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -41,7 +41,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt, args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))), attributes: attrs, - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { cs_cmp(a, b, c) }), } @@ -130,7 +130,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, cx.expr_block(cx.block(span, vec!(assign), Some(if_))) }, cx.expr_path(equals_path.clone()), - |cx, span, (self_args, tag_tuple), _non_self_args| { + box |cx, span, (self_args, tag_tuple), _non_self_args| { if self_args.len() != 2 { cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`") } else { diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index c0631b8350b8c..8094f0d3de8cc 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -76,7 +76,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, true )), attributes: Vec::new(), - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { decodable_substructure(a, b, c, krate) }), }) diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index 49bcb26a4c283..047c4fef3c4f1 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -40,7 +40,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, args: Vec::new(), ret_ty: Self, attributes: attrs, - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { default_substructure(a, b, c) }) }) diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 4323d2979cc06..0fceb0fbfdac4 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -152,7 +152,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, true )), attributes: Vec::new(), - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { encodable_substructure(a, b, c) }), }) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 459abf15b33da..1fb8189c63c81 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -312,7 +312,7 @@ pub enum SubstructureFields<'a> { /// Combine the values of all the fields together. The last argument is /// all the fields of all the structures. pub type CombineSubstructureFunc<'a> = - |&mut ExtCtxt, Span, &Substructure|: 'a -> P; + Box P + 'a>; /// Deal with non-matching enum variants. The tuple is a list of /// identifiers (one for each `Self` argument, which could be any of the @@ -320,11 +320,7 @@ pub type CombineSubstructureFunc<'a> = /// holding the variant index value for each of the `Self` arguments. The /// last argument is all the non-`Self` args of the method being derived. pub type EnumNonMatchCollapsedFunc<'a> = - |&mut ExtCtxt, - Span, - (&[Ident], &[Ident]), - &[P]|: 'a - -> P; + Box]) -> P + 'a>; pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) -> RefCell> { @@ -606,7 +602,7 @@ impl<'a> MethodDef<'a> { }; let mut f = self.combine_substructure.borrow_mut(); let f: &mut CombineSubstructureFunc = &mut *f; - (*f)(cx, trait_.span, &substructure) + f.call_mut((cx, trait_.span, &substructure)) } fn get_ret_ty(&self, @@ -1341,7 +1337,7 @@ impl<'a> TraitDef<'a> { pub fn cs_fold(use_foldl: bool, mut f: F, base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, + mut enum_nonmatch_f: EnumNonMatchCollapsedFunc, cx: &mut ExtCtxt, trait_span: Span, substructure: &Substructure) @@ -1369,8 +1365,8 @@ pub fn cs_fold(use_foldl: bool, } }, EnumNonMatchingCollapsed(ref all_args, _, tuple) => - enum_nonmatch_f(cx, trait_span, (all_args[], tuple), - substructure.nonself_args), + enum_nonmatch_f.call_mut((cx, trait_span, (all_args[], tuple), + substructure.nonself_args)), StaticEnum(..) | StaticStruct(..) => { cx.span_bug(trait_span, "static function in `derive`") } @@ -1387,7 +1383,7 @@ pub fn cs_fold(use_foldl: bool, /// ``` #[inline] pub fn cs_same_method(f: F, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, + mut enum_nonmatch_f: EnumNonMatchCollapsedFunc, cx: &mut ExtCtxt, trait_span: Span, substructure: &Substructure) @@ -1409,8 +1405,8 @@ pub fn cs_same_method(f: F, f(cx, trait_span, called) }, EnumNonMatchingCollapsed(ref all_self_args, _, tuple) => - enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple), - substructure.nonself_args), + enum_nonmatch_f.call_mut((cx, trait_span, (all_self_args[], tuple), + substructure.nonself_args)), StaticEnum(..) | StaticStruct(..) => { cx.span_bug(trait_span, "static function in `derive`") } diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index 9ff42d85cfbb8..b9acde4bf6be9 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -55,7 +55,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, args: vec!(Ptr(box Literal(args), Borrowed(None, MutMutable))), ret_ty: nil_ty(), attributes: attrs, - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { hash_substructure(a, b, c) }) } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index 8abd846373ae1..d36bb2cd1c2aa 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -46,7 +46,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, true)), // #[inline] liable to cause code-bloat attributes: attrs.clone(), - combine_substructure: combine_substructure(|c, s, sub| { + combine_substructure: combine_substructure(box |c, s, sub| { cs_from("i64", c, s, sub) }), }, @@ -62,7 +62,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, true)), // #[inline] liable to cause code-bloat attributes: attrs, - combine_substructure: combine_substructure(|c, s, sub| { + combine_substructure: combine_substructure(box |c, s, sub| { cs_from("u64", c, s, sub) }), }) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 1ddf5b2a5c31e..5517019f804ce 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -45,7 +45,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, ), ret_ty: Self, attributes: Vec::new(), - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { rand_substructure(a, b, c) }) } diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 0513c75cf57da..eceac4e9a8368 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -46,7 +46,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt, args: vec!(fmtr), ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))), attributes: Vec::new(), - combine_substructure: combine_substructure(|a, b, c| { + combine_substructure: combine_substructure(box |a, b, c| { show_substructure(a, b, c) }) } From 98fda878d8d109c7b3337593d5396a3b893aa966 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Jan 2015 17:28:38 -0500 Subject: [PATCH 04/37] conv_did: convert to "unboxed" closure --- src/librustc/metadata/tydecode.rs | 381 ++++++++++++++++++++---------- 1 file changed, 254 insertions(+), 127 deletions(-) diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 80b13aac89fc8..825daa7ddb94c 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -61,8 +61,7 @@ pub enum DefIdSource { UnboxedClosureSource } -pub type conv_did<'a> = - |source: DefIdSource, ast::DefId|: 'a -> ast::DefId; +// type conv_did = impl FnMut(DefIdSource, ast::DefId) -> ast::DefId; pub struct PState<'a, 'tcx: 'a> { data: &'a [u8], @@ -145,70 +144,88 @@ fn data_log_string(data: &[u8], pos: uint) -> String { buf } -pub fn parse_ty_closure_data<'tcx>(data: &[u8], - crate_num: ast::CrateNum, - pos: uint, - tcx: &ty::ctxt<'tcx>, - conv: conv_did) - -> ty::ClosureTy<'tcx> { +pub fn parse_ty_closure_data<'tcx, F>(data: &[u8], + crate_num: ast::CrateNum, + pos: uint, + tcx: &ty::ctxt<'tcx>, + conv: F) + -> ty::ClosureTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_closure_ty(&mut st, conv) } -pub fn parse_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, - tcx: &ty::ctxt<'tcx>, conv: conv_did) -> Ty<'tcx> { +pub fn parse_ty_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: F) -> Ty<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ debug!("parse_ty_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_ty(&mut st, conv) } -pub fn parse_region_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, - conv: conv_did) -> ty::Region { +pub fn parse_region_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt, + conv: F) -> ty::Region where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ debug!("parse_region_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_region(&mut st, conv) } -pub fn parse_bare_fn_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, - tcx: &ty::ctxt<'tcx>, conv: conv_did) - -> ty::BareFnTy<'tcx> { +pub fn parse_bare_fn_ty_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: F) + -> ty::BareFnTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_bare_fn_ty(&mut st, conv) } -pub fn parse_trait_ref_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, - tcx: &ty::ctxt<'tcx>, conv: conv_did) - -> Rc> { +pub fn parse_trait_ref_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: F) + -> Rc> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ debug!("parse_trait_ref_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_trait_ref(&mut st, conv) } -pub fn parse_substs_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint, - tcx: &ty::ctxt<'tcx>, conv: conv_did) -> subst::Substs<'tcx> { +pub fn parse_substs_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: uint, + tcx: &ty::ctxt<'tcx>, conv: F) -> subst::Substs<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ debug!("parse_substs_data {}", data_log_string(data, pos)); let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_substs(&mut st, conv) } -pub fn parse_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, - pos: uint, tcx: &ty::ctxt<'tcx>, conv: conv_did) - -> ty::ParamBounds<'tcx> { +pub fn parse_bounds_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, + pos: uint, tcx: &ty::ctxt<'tcx>, conv: F) + -> ty::ParamBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_bounds(&mut st, conv) } -pub fn parse_existential_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, - pos: uint, tcx: &ty::ctxt<'tcx>, conv: conv_did) - -> ty::ExistentialBounds<'tcx> { +pub fn parse_existential_bounds_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, + pos: uint, tcx: &ty::ctxt<'tcx>, conv: F) + -> ty::ExistentialBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_existential_bounds(&mut st, conv) } -pub fn parse_builtin_bounds_data(data: &[u8], crate_num: ast::CrateNum, - pos: uint, tcx: &ty::ctxt, conv: conv_did) - -> ty::BuiltinBounds { +pub fn parse_builtin_bounds_data(data: &[u8], crate_num: ast::CrateNum, + pos: uint, tcx: &ty::ctxt, conv: F) + -> ty::BuiltinBounds where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let mut st = parse_state_from_data(data, crate_num, pos, tcx); parse_builtin_bounds(&mut st, conv) } @@ -226,10 +243,12 @@ fn parse_size(st: &mut PState) -> Option { } } -fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore { +fn parse_trait_store_(st: &mut PState, conv: &mut F) -> ty::TraitStore where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ match next(st) { '~' => ty::UniqTraitStore, - '&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)), + '&' => ty::RegionTraitStore(parse_region_(st, conv), parse_mutability(st)), c => { st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'", c)[]) @@ -253,31 +272,44 @@ fn parse_vec_per_param_space<'a, 'tcx, T, F>(st: &mut PState<'a, 'tcx>, r } -fn parse_substs<'a, 'tcx>(st: &mut PState<'a, 'tcx>, - conv: conv_did) -> subst::Substs<'tcx> { +fn parse_substs<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + mut conv: F) -> subst::Substs<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_substs_(st, &mut conv) +} + +fn parse_substs_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + conv: &mut F) -> subst::Substs<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let regions = - parse_region_substs(st, |x,y| conv(x,y)); + parse_region_substs_(st, conv); let types = - parse_vec_per_param_space(st, |st| parse_ty(st, |x,y| conv(x,y))); + parse_vec_per_param_space(st, |st| parse_ty_(st, conv)); subst::Substs { types: types, regions: regions } } -fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts { +fn parse_region_substs_(st: &mut PState, conv: &mut F) -> subst::RegionSubsts where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ match next(st) { 'e' => subst::ErasedRegions, 'n' => { subst::NonerasedRegions( parse_vec_per_param_space( - st, |st| parse_region(st, |x,y| conv(x,y)))) + st, |st| parse_region_(st, conv))) } _ => panic!("parse_bound_region: bad input") } } -fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion { +fn parse_bound_region_(st: &mut PState, conv: &mut F) -> ty::BoundRegion where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ match next(st) { 'a' => { let id = parse_u32(st); @@ -285,7 +317,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion { ty::BrAnon(id) } '[' => { - let def = parse_def(st, RegionParameter, |x,y| conv(x,y)); + let def = parse_def_(st, RegionParameter, conv); let ident = token::str_to_ident(parse_str(st, ']')[]); ty::BrNamed(def, ident.name) } @@ -299,13 +331,21 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion { } } -fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region { +fn parse_region(st: &mut PState, mut conv: F) -> ty::Region where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_region_(st, &mut conv) +} + +fn parse_region_(st: &mut PState, conv: &mut F) -> ty::Region where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ match next(st) { 'b' => { assert_eq!(next(st), '['); let id = ty::DebruijnIndex::new(parse_u32(st)); assert_eq!(next(st), '|'); - let br = parse_bound_region(st, |x,y| conv(x,y)); + let br = parse_bound_region_(st, conv); assert_eq!(next(st), ']'); ty::ReLateBound(id, br) } @@ -324,7 +364,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region { assert_eq!(next(st), '['); let scope = parse_scope(st); assert_eq!(next(st), '|'); - let br = parse_bound_region(st, |x,y| conv(x,y)); + let br = parse_bound_region_(st, conv); assert_eq!(next(st), ']'); ty::ReFree(ty::FreeRegion { scope: scope, bound_region: br}) @@ -375,14 +415,31 @@ fn parse_str(st: &mut PState, term: char) -> String { result } -fn parse_trait_ref<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) - -> Rc> { - let def = parse_def(st, NominalType, |x,y| conv(x,y)); - let substs = st.tcx.mk_substs(parse_substs(st, |x,y| conv(x,y))); +fn parse_trait_ref<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, mut conv: F) + -> Rc> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_trait_ref_(st, &mut conv) +} + +fn parse_trait_ref_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) + -> Rc> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + let def = parse_def_(st, NominalType, conv); + let substs = st.tcx.mk_substs(parse_substs_(st, conv)); Rc::new(ty::TraitRef {def_id: def, substs: substs}) } -fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { +fn parse_ty<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, mut conv: F) -> Ty<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_ty_(st, &mut conv) +} + +fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let tcx = st.tcx; match next(st) { 'b' => return tcx.types.bool, @@ -406,15 +463,15 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { 'c' => return tcx.types.char, 't' => { assert_eq!(next(st), '['); - let def = parse_def(st, NominalType, |x,y| conv(x,y)); - let substs = parse_substs(st, |x,y| conv(x,y)); + let def = parse_def_(st, NominalType, conv); + let substs = parse_substs_(st, conv); assert_eq!(next(st), ']'); return ty::mk_enum(tcx, def, st.tcx.mk_substs(substs)); } 'x' => { assert_eq!(next(st), '['); - let trait_ref = ty::Binder(parse_trait_ref(st, |x,y| conv(x,y))); - let bounds = parse_existential_bounds(st, |x,y| conv(x,y)); + let trait_ref = ty::Binder(parse_trait_ref_(st, conv)); + let bounds = parse_existential_bounds_(st, conv); assert_eq!(next(st), ']'); return ty::mk_trait(tcx, trait_ref, bounds); } @@ -427,15 +484,15 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { let name = token::intern(parse_str(st, ']')[]); return ty::mk_param(tcx, space, index, name); } - '~' => return ty::mk_uniq(tcx, parse_ty(st, |x,y| conv(x,y))), - '*' => return ty::mk_ptr(tcx, parse_mt(st, |x,y| conv(x,y))), + '~' => return ty::mk_uniq(tcx, parse_ty_(st, conv)), + '*' => return ty::mk_ptr(tcx, parse_mt_(st, conv)), '&' => { - let r = parse_region(st, |x,y| conv(x,y)); - let mt = parse_mt(st, |x,y| conv(x,y)); + let r = parse_region_(st, conv); + let mt = parse_mt_(st, conv); return ty::mk_rptr(tcx, tcx.mk_region(r), mt); } 'V' => { - let t = parse_ty(st, |x,y| conv(x,y)); + let t = parse_ty_(st, conv); let sz = parse_size(st); return ty::mk_vec(tcx, t, sz); } @@ -445,21 +502,21 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { 'T' => { assert_eq!(next(st), '['); let mut params = Vec::new(); - while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); } + while peek(st) != ']' { params.push(parse_ty_(st, conv)); } st.pos = st.pos + 1u; return ty::mk_tup(tcx, params); } 'f' => { - return ty::mk_closure(tcx, parse_closure_ty(st, |x,y| conv(x,y))); + return ty::mk_closure(tcx, parse_closure_ty_(st, conv)); } 'F' => { - let def_id = parse_def(st, NominalType, |x,y| conv(x,y)); + let def_id = parse_def_(st, NominalType, conv); return ty::mk_bare_fn(tcx, Some(def_id), - tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y)))); + tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv))); } 'G' => { return ty::mk_bare_fn(tcx, None, - tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y)))); + tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv))); } '#' => { let pos = parse_hex(st); @@ -478,34 +535,34 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> { pos: pos, .. *st }; - let tt = parse_ty(&mut ps, |x,y| conv(x,y)); + let tt = parse_ty_(&mut ps, conv); tcx.rcache.borrow_mut().insert(key, tt); return tt; } '\"' => { - let _ = parse_def(st, TypeWithId, |x,y| conv(x,y)); - let inner = parse_ty(st, |x,y| conv(x,y)); + let _ = parse_def_(st, TypeWithId, conv); + let inner = parse_ty_(st, conv); inner } 'a' => { assert_eq!(next(st), '['); - let did = parse_def(st, NominalType, |x,y| conv(x,y)); - let substs = parse_substs(st, |x,y| conv(x,y)); + let did = parse_def_(st, NominalType, conv); + let substs = parse_substs_(st, conv); assert_eq!(next(st), ']'); return ty::mk_struct(st.tcx, did, st.tcx.mk_substs(substs)); } 'k' => { assert_eq!(next(st), '['); - let did = parse_def(st, UnboxedClosureSource, |x,y| conv(x,y)); - let region = parse_region(st, |x,y| conv(x,y)); - let substs = parse_substs(st, |x,y| conv(x,y)); + let did = parse_def_(st, UnboxedClosureSource, conv); + let region = parse_region_(st, conv); + let substs = parse_substs_(st, conv); assert_eq!(next(st), ']'); return ty::mk_unboxed_closure(st.tcx, did, st.tcx.mk_region(region), st.tcx.mk_substs(substs)); } 'P' => { assert_eq!(next(st), '['); - let trait_ref = parse_trait_ref(st, |x,y| conv(x,y)); + let trait_ref = parse_trait_ref_(st, conv); let name = token::intern(parse_str(st, ']').as_slice()); return ty::mk_projection(tcx, trait_ref, name); } @@ -523,14 +580,17 @@ fn parse_mutability(st: &mut PState) -> ast::Mutability { } } -fn parse_mt<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::mt<'tcx> { +fn parse_mt_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> ty::mt<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let m = parse_mutability(st); - ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m } + ty::mt { ty: parse_ty_(st, conv), mutbl: m } } -fn parse_def(st: &mut PState, source: DefIdSource, - conv: conv_did) -> ast::DefId { - return conv(source, scan(st, |c| { c == '|' }, parse_def_id)); +fn parse_def_(st: &mut PState, source: DefIdSource, conv: &mut F) -> ast::DefId where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + return (*conv)(source, scan(st, |c| { c == '|' }, parse_def_id)); } fn parse_uint(st: &mut PState) -> uint { @@ -592,13 +652,22 @@ fn parse_onceness(c: char) -> ast::Onceness { } } -fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, - conv: conv_did) -> ty::ClosureTy<'tcx> { +fn parse_closure_ty<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + mut conv: F) -> ty::ClosureTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_closure_ty_(st, &mut conv) +} + +fn parse_closure_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + conv: &mut F) -> ty::ClosureTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let unsafety = parse_unsafety(next(st)); let onceness = parse_onceness(next(st)); - let store = parse_trait_store(st, |x,y| conv(x,y)); - let bounds = parse_existential_bounds(st, |x,y| conv(x,y)); - let sig = parse_sig(st, |x,y| conv(x,y)); + let store = parse_trait_store_(st, conv); + let bounds = parse_existential_bounds_(st, conv); + let sig = parse_sig_(st, conv); let abi = parse_abi_set(st); ty::ClosureTy { unsafety: unsafety, @@ -610,11 +679,20 @@ fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, } } -fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, - conv: conv_did) -> ty::BareFnTy<'tcx> { +fn parse_bare_fn_ty<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + mut conv: F) -> ty::BareFnTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_bare_fn_ty_(st, &mut conv) +} + +fn parse_bare_fn_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, + conv: &mut F) -> ty::BareFnTy<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let unsafety = parse_unsafety(next(st)); let abi = parse_abi_set(st); - let sig = parse_sig(st, |x,y| conv(x,y)); + let sig = parse_sig_(st, conv); ty::BareFnTy { unsafety: unsafety, abi: abi, @@ -622,11 +700,13 @@ fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, } } -fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::PolyFnSig<'tcx> { +fn parse_sig_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> ty::PolyFnSig<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ assert_eq!(next(st), '['); let mut inputs = Vec::new(); while peek(st) != ']' { - inputs.push(parse_ty(st, |x,y| conv(x,y))); + inputs.push(parse_ty_(st, conv)); } st.pos += 1u; // eat the ']' let variadic = match next(st) { @@ -639,7 +719,7 @@ fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::PolyFnS st.pos += 1u; ty::FnDiverging } - _ => ty::FnConverging(parse_ty(st, |x,y| conv(x,y))) + _ => ty::FnConverging(parse_ty_(st, conv)) }; ty::Binder(ty::FnSig {inputs: inputs, output: output, @@ -672,66 +752,87 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId { ast::DefId { krate: crate_num, node: def_num } } -pub fn parse_predicate_data<'tcx>(data: &[u8], - start: uint, - crate_num: ast::CrateNum, - tcx: &ty::ctxt<'tcx>, - conv: conv_did) - -> ty::Predicate<'tcx> +pub fn parse_predicate_data<'tcx, F>(data: &[u8], + start: uint, + crate_num: ast::CrateNum, + tcx: &ty::ctxt<'tcx>, + conv: F) + -> ty::Predicate<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, { let mut st = parse_state_from_data(data, crate_num, start, tcx); parse_predicate(&mut st, conv) } -pub fn parse_predicate<'a,'tcx>(st: &mut PState<'a, 'tcx>, - conv: conv_did) - -> ty::Predicate<'tcx> +pub fn parse_predicate<'a,'tcx, F>(st: &mut PState<'a, 'tcx>, + mut conv: F) + -> ty::Predicate<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_predicate_(st, &mut conv) +} + +fn parse_predicate_<'a,'tcx, F>(st: &mut PState<'a, 'tcx>, + conv: &mut F) + -> ty::Predicate<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, { match next(st) { - 't' => ty::Binder(parse_trait_ref(st, conv)).as_predicate(), - 'e' => ty::Binder(ty::EquatePredicate(parse_ty(st, |x,y| conv(x,y)), - parse_ty(st, |x,y| conv(x,y)))).as_predicate(), - 'r' => ty::Binder(ty::OutlivesPredicate(parse_region(st, |x,y| conv(x,y)), - parse_region(st, |x,y| conv(x,y)))).as_predicate(), - 'o' => ty::Binder(ty::OutlivesPredicate(parse_ty(st, |x,y| conv(x,y)), - parse_region(st, |x,y| conv(x,y)))).as_predicate(), - 'p' => ty::Binder(parse_projection_predicate(st, conv)).as_predicate(), + 't' => ty::Binder(parse_trait_ref_(st, conv)).as_predicate(), + 'e' => ty::Binder(ty::EquatePredicate(parse_ty_(st, conv), + parse_ty_(st, conv))).as_predicate(), + 'r' => ty::Binder(ty::OutlivesPredicate(parse_region_(st, conv), + parse_region_(st, conv))).as_predicate(), + 'o' => ty::Binder(ty::OutlivesPredicate(parse_ty_(st, conv), + parse_region_(st, conv))).as_predicate(), + 'p' => ty::Binder(parse_projection_predicate_(st, conv)).as_predicate(), c => panic!("Encountered invalid character in metadata: {}", c) } } -fn parse_projection_predicate<'a,'tcx>( +fn parse_projection_predicate_<'a,'tcx, F>( st: &mut PState<'a, 'tcx>, - conv: conv_did) - -> ty::ProjectionPredicate<'tcx> + conv: &mut F, +) -> ty::ProjectionPredicate<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, { ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { - trait_ref: parse_trait_ref(st, |x,y| conv(x,y)), + trait_ref: parse_trait_ref_(st, conv), item_name: token::str_to_ident(parse_str(st, '|').as_slice()).name, }, - ty: parse_ty(st, |x,y| conv(x,y)), + ty: parse_ty_(st, conv), } } -pub fn parse_type_param_def_data<'tcx>(data: &[u8], start: uint, - crate_num: ast::CrateNum, tcx: &ty::ctxt<'tcx>, - conv: conv_did) -> ty::TypeParameterDef<'tcx> +pub fn parse_type_param_def_data<'tcx, F>(data: &[u8], start: uint, + crate_num: ast::CrateNum, tcx: &ty::ctxt<'tcx>, + conv: F) -> ty::TypeParameterDef<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, { let mut st = parse_state_from_data(data, crate_num, start, tcx); parse_type_param_def(&mut st, conv) } -fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) - -> ty::TypeParameterDef<'tcx> { +fn parse_type_param_def<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, mut conv: F) + -> ty::TypeParameterDef<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_type_param_def_(st, &mut conv) +} + +fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) + -> ty::TypeParameterDef<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let name = parse_name(st, ':'); - let def_id = parse_def(st, NominalType, |x,y| conv(x,y)); + let def_id = parse_def_(st, NominalType, conv); let space = parse_param_space(st); assert_eq!(next(st), '|'); let index = parse_u32(st); assert_eq!(next(st), '|'); - let bounds = parse_bounds(st, |x,y| conv(x,y)); - let default = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y))); + let bounds = parse_bounds_(st, conv); + let default = parse_opt(st, |st| parse_ty_(st, conv)); ty::TypeParameterDef { name: name, @@ -743,12 +844,21 @@ fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) } } -fn parse_existential_bounds<'a,'tcx>(st: &mut PState<'a,'tcx>, - conv: conv_did) - -> ty::ExistentialBounds<'tcx> +fn parse_existential_bounds<'a,'tcx, F>(st: &mut PState<'a,'tcx>, + mut conv: F) + -> ty::ExistentialBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_existential_bounds_(st, &mut conv) +} + +fn parse_existential_bounds_<'a,'tcx, F>(st: &mut PState<'a,'tcx>, + conv: &mut F) + -> ty::ExistentialBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, { let ty::ParamBounds { trait_bounds, mut region_bounds, builtin_bounds, projection_bounds } = - parse_bounds(st, conv); + parse_bounds_(st, conv); assert_eq!(region_bounds.len(), 1); assert_eq!(trait_bounds.len(), 0); let region_bound = region_bounds.pop().unwrap(); @@ -757,7 +867,15 @@ fn parse_existential_bounds<'a,'tcx>(st: &mut PState<'a,'tcx>, projection_bounds: projection_bounds }; } -fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds { +fn parse_builtin_bounds(st: &mut PState, mut _conv: F) -> ty::BuiltinBounds where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_builtin_bounds_(st, &mut _conv) +} + +fn parse_builtin_bounds_(st: &mut PState, _conv: &mut F) -> ty::BuiltinBounds where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ let mut builtin_bounds = ty::empty_builtin_bounds(); loop { @@ -784,9 +902,18 @@ fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds { } } -fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) - -> ty::ParamBounds<'tcx> { - let builtin_bounds = parse_builtin_bounds(st, |x,y| conv(x,y)); +fn parse_bounds<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, mut conv: F) + -> ty::ParamBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + parse_bounds_(st, &mut conv) +} + +fn parse_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) + -> ty::ParamBounds<'tcx> where + F: FnMut(DefIdSource, ast::DefId) -> ast::DefId, +{ + let builtin_bounds = parse_builtin_bounds_(st, conv); let mut param_bounds = ty::ParamBounds { region_bounds: Vec::new(), @@ -798,15 +925,15 @@ fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) match next(st) { 'R' => { param_bounds.region_bounds.push( - parse_region(st, |x, y| conv (x, y))); + parse_region_(st, conv)); } 'I' => { param_bounds.trait_bounds.push( - ty::Binder(parse_trait_ref(st, |x,y| conv(x,y)))); + ty::Binder(parse_trait_ref_(st, conv))); } 'P' => { param_bounds.projection_bounds.push( - ty::Binder(parse_projection_predicate(st, |x,y| conv(x,y)))); + ty::Binder(parse_projection_predicate_(st, conv))); } '.' => { return param_bounds; From bd9eef7ac64b4263c9db25d74b7cc57958909ddc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:07:13 -0500 Subject: [PATCH 05/37] DecodeInlinedItem: convert to "unboxed" closures --- src/librustc/metadata/decoder.rs | 18 +++++++++--------- src/librustc/middle/const_eval.rs | 4 ++-- src/librustc_trans/trans/inline.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 97f5228f0330b..ac8dfc1675942 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -662,27 +662,27 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec { item_path(lookup_item(id, cdata.data())) } -pub type DecodeInlinedItem<'a> = for<'tcx> |cdata: Cmd, - tcx: &ty::ctxt<'tcx>, - path: Vec, - par_doc: rbml::Doc|: 'a - -> Result<&'tcx ast::InlinedItem, - Vec>; +pub type DecodeInlinedItem<'a> = + Box FnMut(Cmd, + &ty::ctxt<'tcx>, + Vec, + rbml::Doc) + -> Result<&'tcx ast::InlinedItem, Vec> + 'a>; pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeId, - decode_inlined_item: DecodeInlinedItem) + mut decode_inlined_item: DecodeInlinedItem) -> csearch::found_ast<'tcx> { debug!("Looking up item: {}", id); let item_doc = lookup_item(id, cdata.data()); let path = item_path(item_doc).init().to_vec(); - match decode_inlined_item(cdata, tcx, path, item_doc) { + match decode_inlined_item.call_mut((cdata, tcx, path, item_doc)) { Ok(ii) => csearch::found(ii), Err(path) => { match item_parent_item(item_doc) { Some(did) => { let did = translate_def_id(cdata, did); let parent_item = lookup_item(did.node, cdata.data()); - match decode_inlined_item(cdata, tcx, path, parent_item) { + match decode_inlined_item.call_mut((cdata, tcx, path, parent_item)) { Ok(ii) => csearch::found_parent(did, ii), Err(_) => csearch::not_found } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 6671f0f72f674..a95523f2e0600 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -132,7 +132,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt, None => {} } let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def, - |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { + box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { csearch::found(&ast::IIItem(ref item)) => match item.node { ast::ItemEnum(ast::EnumDef { ref variants }, _) => { // NOTE this doesn't do the right thing, it compares inlined @@ -172,7 +172,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) None => {} } let expr_id = match csearch::maybe_get_item_ast(tcx, def_id, - |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { + box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { csearch::found(&ast::IIItem(ref item)) => match item.node { ast::ItemConst(_, ref const_expr) => Some(const_expr.id), _ => None diff --git a/src/librustc_trans/trans/inline.rs b/src/librustc_trans/trans/inline.rs index bde9051ec74d6..dd1cfc5ad6d82 100644 --- a/src/librustc_trans/trans/inline.rs +++ b/src/librustc_trans/trans/inline.rs @@ -40,7 +40,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) let csearch_result = csearch::maybe_get_item_ast( ccx.tcx(), fn_id, - |a,b,c,d| astencode::decode_inlined_item(a, b, c, d)); + box |a,b,c,d| astencode::decode_inlined_item(a, b, c, d)); let inline_def = match csearch_result { csearch::not_found => { From 0cb34a3609a028ad0bcaa8e200f97b18bb17383e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:13:48 -0500 Subject: [PATCH 06/37] EncodeInlinedItem: convert to "unboxed" closures --- src/librustc/metadata/encoder.rs | 7 +++---- src/librustc_trans/trans/base.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 59679f0bc7cd0..14ab471a4b831 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -59,9 +59,8 @@ pub enum InlinedItemRef<'a> { pub type Encoder<'a> = writer::Encoder<'a, SeekableMemWriter>; -pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext, - rbml_w: &mut Encoder, - ii: InlinedItemRef|: 'a; +pub type EncodeInlinedItem<'a> = + Box; pub struct EncodeParams<'a, 'tcx: 'a> { pub diag: &'a SpanHandler, @@ -953,7 +952,7 @@ fn encode_inlined_item(ecx: &EncodeContext, ii: InlinedItemRef) { let mut eii = ecx.encode_inlined_item.borrow_mut(); let eii: &mut EncodeInlinedItem = &mut *eii; - (*eii)(ecx, rbml_w, ii) + eii.call_mut((ecx, rbml_w, ii)) } const FN_FAMILY: char = 'f'; diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 518042cf70889..29811ad6dd5f7 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -2978,7 +2978,7 @@ pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec { } let encode_inlined_item: encoder::EncodeInlinedItem = - |ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii); + box |ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii); let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item); let metadata = encoder::encode_metadata(encode_parms, krate); From 8570f0acc7f7002b745968d9df57daa49befcc3b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 16:10:27 -0500 Subject: [PATCH 07/37] rustc: remove remaining boxed closures --- src/librustc/middle/privacy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index ace0882a12c59..50e328ef0e3c3 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -750,7 +750,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { debug!("privacy - path {}", self.nodestr(path_id)); let orig_def = self.tcx.def_map.borrow()[path_id].clone(); let ck = |&: tyname: &str| { - let ck_public = |def: ast::DefId| { + let ck_public = |&: def: ast::DefId| { let name = token::get_ident(path.segments.last().unwrap().identifier); let origdid = orig_def.def_id(); self.ensure_public(span, From 977e151b9a74af6cdb92b7afb57a4dbacc799841 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 17:22:50 -0500 Subject: [PATCH 08/37] typeck: remove remaining boxed closures --- src/librustc_typeck/check/method/probe.rs | 14 +++++++++----- src/librustc_typeck/check/wf.rs | 13 +++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 8adb592633f5e..beb51590b4159 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -387,14 +387,18 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { // Do a search through a list of bounds, using a callback to actually // create the candidates. - fn elaborate_bounds( + fn elaborate_bounds( &mut self, bounds: &[ty::PolyTraitRef<'tcx>], num_includes_types: bool, - mk_cand: for<'b> |this: &mut ProbeContext<'b, 'tcx>, - tr: ty::PolyTraitRef<'tcx>, - m: Rc>, - method_num: uint|) + mut mk_cand: F, + ) where + F: for<'b> FnMut( + &mut ProbeContext<'b, 'tcx>, + ty::PolyTraitRef<'tcx>, + Rc>, + uint, + ), { debug!("elaborate_bounds(bounds={})", bounds.repr(self.tcx())); diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 42ac1af325f48..d4a5bda5f97f9 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -81,10 +81,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } } - fn with_fcx(&mut self, - item: &ast::Item, - f: for<'fcx> |&mut CheckTypeWellFormedVisitor<'ccx, 'tcx>, - &FnCtxt<'fcx, 'tcx>|) { + fn with_fcx(&mut self, item: &ast::Item, mut f: F) where + F: for<'fcx> FnMut(&mut CheckTypeWellFormedVisitor<'ccx, 'tcx>, &FnCtxt<'fcx, 'tcx>), + { let ccx = self.ccx; let item_def_id = local_def(item.id); let polytype = ty::lookup_item_type(ccx.tcx, item_def_id); @@ -100,10 +99,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { } /// In a type definition, we check that to ensure that the types of the fields are well-formed. - fn check_type_defn(&mut self, - item: &ast::Item, - lookup_fields: for<'fcx> |&FnCtxt<'fcx, 'tcx>| - -> Vec>) + fn check_type_defn(&mut self, item: &ast::Item, mut lookup_fields: F) where + F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>) -> Vec>, { self.with_fcx(item, |this, fcx| { let variants = lookup_fields(fcx); From bf52e262e20efaaadf3fec47f20880ffc171a34f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 17:23:01 -0500 Subject: [PATCH 09/37] trans: remove remaining boxed closures --- src/librustc_trans/trans/base.rs | 37 ++++++++++++++++---------------- src/librustc_trans/trans/glue.rs | 15 +++++++------ src/librustc_trans/trans/tvec.rs | 25 ++++++++++----------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 29811ad6dd5f7..9814a4ed183a8 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -669,30 +669,31 @@ pub fn compare_simd_types<'blk, 'tcx>( } } -pub type val_and_ty_fn<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; - // Iterates through the elements of a structural type. -pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, - av: ValueRef, - t: Ty<'tcx>, - f: val_and_ty_fn<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { +pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>, + av: ValueRef, + t: Ty<'tcx>, + mut f: F) + -> Block<'blk, 'tcx> where + F: FnMut(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("iter_structural_ty"); - fn iter_variant<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, - repr: &adt::Repr<'tcx>, - av: ValueRef, - variant: &ty::VariantInfo<'tcx>, - substs: &subst::Substs<'tcx>, - f: val_and_ty_fn<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { + fn iter_variant<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>, + repr: &adt::Repr<'tcx>, + av: ValueRef, + variant: &ty::VariantInfo<'tcx>, + substs: &subst::Substs<'tcx>, + f: &mut F) + -> Block<'blk, 'tcx> where + F: FnMut(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, + { let _icx = push_ctxt("iter_variant"); let tcx = cx.tcx(); let mut cx = cx; for (i, &arg) in variant.args.iter().enumerate() { - cx = f(cx, + cx = (*f)(cx, adt::trans_field_ptr(cx, repr, av, variant.disr_val, i), arg.subst(tcx, substs)); } @@ -764,7 +765,7 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, match adt::trans_switch(cx, &*repr, av) { (_match::Single, None) => { cx = iter_variant(cx, &*repr, av, &*(*variants)[0], - substs, f); + substs, &mut f); } (_match::Switch, Some(lldiscrim_a)) => { cx = f(cx, lldiscrim_a, cx.tcx().types.int); @@ -793,7 +794,7 @@ pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, data_ptr, &**variant, substs, - |x,y,z| f(x,y,z)); + &mut f); Br(variant_cx, next_cx.llbb); } cx = next_cx; diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index c049704181354..116ce2bf51dbe 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -531,13 +531,14 @@ fn declare_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, return (fn_nm, llfn); } -fn make_generic_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, - t: Ty<'tcx>, - llfn: ValueRef, - helper: for<'blk> |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>| - -> Block<'blk, 'tcx>, - name: &str) - -> ValueRef { +fn make_generic_glue<'a, 'tcx, F>(ccx: &CrateContext<'a, 'tcx>, + t: Ty<'tcx>, + llfn: ValueRef, + helper: F, + name: &str) + -> ValueRef where + F: for<'blk> FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("make_generic_glue"); let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx(), t)); let _s = StatRecorder::new(ccx, glue_name); diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index de71a1c2217ec..e3288466aa79c 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -416,15 +416,14 @@ pub fn get_base_and_len(bcx: Block, } } -pub type iter_vec_block<'a, 'blk, 'tcx> = - |Block<'blk, 'tcx>, ValueRef, Ty<'tcx>|: 'a -> Block<'blk, 'tcx>; - -pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, +pub fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, data_ptr: ValueRef, vt: &VecTypes<'tcx>, count: ValueRef, - f: iter_vec_block<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { + f: F) + -> Block<'blk, 'tcx> where + F: FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("tvec::iter_vec_loop"); let fcx = bcx.fcx; @@ -475,12 +474,14 @@ pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, next_bcx } -pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - data_ptr: ValueRef, - unit_ty: Ty<'tcx>, - len: ValueRef, - f: iter_vec_block<'a, 'blk, 'tcx>) - -> Block<'blk, 'tcx> { +pub fn iter_vec_raw<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, + data_ptr: ValueRef, + unit_ty: Ty<'tcx>, + len: ValueRef, + f: F) + -> Block<'blk, 'tcx> where + F: FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>, +{ let _icx = push_ctxt("tvec::iter_vec_raw"); let fcx = bcx.fcx; From b4ccc901660f08c7555ef8b1ce3e94fb12890a15 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 20:36:57 -0500 Subject: [PATCH 10/37] driver: remove unboxed closures --- src/librustc_driver/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 1455aa3c99bb3..9540c3fa3d7e8 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -638,7 +638,7 @@ fn write_out_deps(sess: &Session, _ => return, }; - let result = (|| -> io::IoResult<()> { + let result = (|&:| -> io::IoResult<()> { // Build a list of files used to compile the output and // write Makefile-compatible dependency rules let files: Vec = sess.codemap().files.borrow() From 37448506ea575d94389a60dce2aaebd57dba50a3 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 22:05:29 -0500 Subject: [PATCH 11/37] compiletest: remove boxed closures --- src/compiletest/compiletest.rs | 5 +++-- src/compiletest/header.rs | 4 +++- src/compiletest/runtest.rs | 14 ++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 350a10ce4832a..48610b6b526d2 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -339,8 +339,9 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool { return valid; } -pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn) - -> test::TestDescAndFn { +pub fn make_test(config: &Config, testfile: &Path, f: F) -> test::TestDescAndFn where + F: FnOnce() -> test::TestFn, +{ test::TestDescAndFn { desc: test::TestDesc { name: make_test_name(config, testfile), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 27be6c6d83568..2413a001ee805 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -220,7 +220,9 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool { !val } -fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool { +fn iter_header(testfile: &Path, mut it: F) -> bool where + F: FnMut(&str) -> bool, +{ use std::io::{BufferedReader, File}; let mut rdr = BufferedReader::new(File::open(testfile).unwrap()); diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index c513aec0b843a..875061e69b7a2 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1233,12 +1233,14 @@ enum TargetLocation { ThisDirectory(Path), } -fn make_compile_args(config: &Config, - props: &TestProps, - extras: Vec , - xform: |&Config, &Path| -> TargetLocation, - testfile: &Path) - -> ProcArgs { +fn make_compile_args(config: &Config, + props: &TestProps, + extras: Vec , + xform: F, + testfile: &Path) + -> ProcArgs where + F: FnOnce(&Config, &Path) -> TargetLocation, +{ let xform_file = xform(config, testfile); let target = if props.force_host { config.host.as_slice() From 18e2026ff8ae67cf8dea61c938d87f1f45734751 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 23:34:23 -0500 Subject: [PATCH 12/37] coretest: remove/ignore tests --- src/libcoretest/lib.rs | 1 - src/libcoretest/option.rs | 5 ++++- src/libcoretest/raw.rs | 35 ----------------------------------- src/libcoretest/result.rs | 5 ++++- 4 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 src/libcoretest/raw.rs diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index e6608eee3ddfa..b6fc6457fce4d 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -30,7 +30,6 @@ mod num; mod ops; mod option; mod ptr; -mod raw; mod result; mod slice; mod str; diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index 86fc25c9d918c..4a459992098a0 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -220,6 +220,7 @@ fn test_ord() { assert!(big > None); } +/* FIXME(#20575) #[test] fn test_collect() { let v: Option> = range(0i, 0).map(|_| Some(0i)).collect(); @@ -234,12 +235,14 @@ fn test_collect() { assert!(v == None); // test that it does not take more elements than it needs - let mut functions = [|| Some(()), || None, || panic!()]; + let mut functions: [Box Option<()>>; 3] = + [box || Some(()), box || None, box || panic!()]; let v: Option> = functions.iter_mut().map(|f| (*f)()).collect(); assert!(v == None); } +*/ #[test] fn test_cloned() { diff --git a/src/libcoretest/raw.rs b/src/libcoretest/raw.rs deleted file mode 100644 index f2c23c7c77327..0000000000000 --- a/src/libcoretest/raw.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 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. - -use core::raw::*; -use core::mem; - -#[test] -fn synthesize_closure() { - unsafe { - let x = 10; - let f: |int| -> int = |y| x + y; - - assert_eq!(f(20), 30); - - let original_closure: Closure = mem::transmute(f); - - let actual_function_pointer = original_closure.code; - let environment = original_closure.env; - - let new_closure = Closure { - code: actual_function_pointer, - env: environment - }; - - let new_f: |int| -> int = mem::transmute(new_closure); - assert_eq!(new_f(20), 30); - } -} diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 415cd4e7dcfb8..52ea14dd05dd9 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -67,6 +67,7 @@ pub fn test_impl_map_err() { assert!(Err::(1).map_err(|x| x + 1) == Err(2)); } +/* FIXME(#20575) #[test] fn test_collect() { let v: Result, ()> = range(0i, 0).map(|_| Ok::(0)).collect(); @@ -81,11 +82,13 @@ fn test_collect() { assert!(v == Err(2)); // test that it does not take more elements than it needs - let mut functions = [|| Ok(()), || Err(1i), || panic!()]; + let mut functions: [Box Result<(), int>>; 3] = + [box || Ok(()), box || Err(1i), box || panic!()]; let v: Result, int> = functions.iter_mut().map(|f| (*f)()).collect(); assert!(v == Err(1)); } +*/ #[test] pub fn test_fmt_default() { From 5f7f2c9a0592bc1627781767ec8228aaad3e5364 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:50:17 -0500 Subject: [PATCH 13/37] remove ty_closure --- src/librustc/lint/builtin.rs | 6 +- src/librustc/metadata/tyencode.rs | 4 -- src/librustc/middle/effect.rs | 1 - src/librustc/middle/expr_use_visitor.rs | 13 ---- src/librustc/middle/fast_reject.rs | 3 - src/librustc/middle/infer/coercion.rs | 24 -------- src/librustc/middle/infer/combine.rs | 6 -- src/librustc/middle/infer/freshen.rs | 1 - src/librustc/middle/mem_categorization.rs | 29 +-------- src/librustc/middle/traits/coherence.rs | 1 - src/librustc/middle/traits/select.rs | 56 ----------------- src/librustc/middle/ty.rs | 51 +--------------- src/librustc/middle/ty_fold.rs | 3 - src/librustc/middle/ty_walk.rs | 3 - src/librustc/util/ppaux.rs | 5 +- src/librustc_borrowck/borrowck/mod.rs | 7 --- src/librustc_trans/trans/adt.rs | 6 -- src/librustc_trans/trans/base.rs | 7 --- src/librustc_trans/trans/callee.rs | 9 --- src/librustc_trans/trans/closure.rs | 1 - src/librustc_trans/trans/debuginfo.rs | 68 --------------------- src/librustc_trans/trans/glue.rs | 12 ---- src/librustc_trans/trans/type_of.rs | 12 ---- src/librustc_typeck/check/callee.rs | 5 +- src/librustc_typeck/check/closure.rs | 1 - src/librustc_typeck/check/method/confirm.rs | 1 - src/librustc_typeck/check/regionck.rs | 48 --------------- src/librustc_typeck/check/regionmanip.rs | 4 -- src/librustc_typeck/check/upvar.rs | 1 - src/librustc_typeck/coherence/mod.rs | 4 +- src/librustc_typeck/variance.rs | 15 +---- src/librustdoc/clean/mod.rs | 13 ---- 32 files changed, 11 insertions(+), 409 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 269aa8fda1326..6666a21c31fee 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -494,11 +494,7 @@ impl BoxPointers { let mut n_uniq = 0i; ty::fold_ty(cx.tcx, ty, |t| { match t.sty { - ty::ty_uniq(_) | - ty::ty_closure(box ty::ClosureTy { - store: ty::UniqTraitStore, - .. - }) => { + ty::ty_uniq(_) => { n_uniq += 1; } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 5f0f51ce9033d..0042209aced6a 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -119,10 +119,6 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t ty::ty_str => { mywrite!(w, "v"); } - ty::ty_closure(ref f) => { - mywrite!(w, "f"); - enc_closure_ty(w, cx, &**f); - } ty::ty_bare_fn(Some(def_id), f) => { mywrite!(w, "F"); mywrite!(w, "{}|", (cx.ds)(def_id)); diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 1075263e7512d..f7eea6e5cb7c9 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -33,7 +33,6 @@ enum UnsafeContext { fn type_is_unsafe_function(ty: Ty) -> bool { match ty.sty { ty::ty_bare_fn(_, ref f) => f.unsafety == ast::Unsafety::Unsafe, - ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe, _ => false, } } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 5b786ec992247..ed5e8e31b7bb5 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -656,19 +656,6 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { ty::ty_bare_fn(..) => { self.consume_expr(callee); } - ty::ty_closure(ref f) => { - match f.onceness { - ast::Many => { - self.borrow_expr(callee, - ty::ReScope(call_scope), - ty::UniqueImmBorrow, - ClosureInvocation); - } - ast::Once => { - self.consume_expr(callee); - } - } - } ty::ty_err => { } _ => { let overloaded_call_type = diff --git a/src/librustc/middle/fast_reject.rs b/src/librustc/middle/fast_reject.rs index d42817bce9302..42bc70b5b561f 100644 --- a/src/librustc/middle/fast_reject.rs +++ b/src/librustc/middle/fast_reject.rs @@ -80,9 +80,6 @@ pub fn simplify_type(tcx: &ty::ctxt, ty::ty_tup(ref tys) => { Some(TupleSimplifiedType(tys.len())) } - ty::ty_closure(ref f) => { - Some(FunctionSimplifiedType(f.sig.0.inputs.len())) - } ty::ty_bare_fn(_, ref f) => { Some(FunctionSimplifiedType(f.sig.0.inputs.len())) } diff --git a/src/librustc/middle/infer/coercion.rs b/src/librustc/middle/infer/coercion.rs index f6f62e035900e..12f34a9ae54e6 100644 --- a/src/librustc/middle/infer/coercion.rs +++ b/src/librustc/middle/infer/coercion.rs @@ -160,15 +160,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { }; } - ty::ty_closure(box ty::ClosureTy { - store: ty::RegionTraitStore(..), - .. - }) => { - return self.unpack_actual_value(a, |a| { - self.coerce_borrowed_fn(a, b) - }); - } - _ => {} } @@ -511,21 +502,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { a.repr(self.tcx()), b.repr(self.tcx())); match b.sty { - ty::ty_closure(ref f) => { - if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal { - return self.subtype(a, b); - } - - let fn_ty_b = (*f).clone(); - let adj = ty::AdjustAddEnv(fn_def_id_a, fn_ty_b.store); - let a_closure = ty::mk_closure(self.tcx(), - ty::ClosureTy { - sig: fn_ty_a.sig.clone(), - .. *fn_ty_b - }); - try!(self.subtype(a_closure, b)); - Ok(Some(adj)) - } ty::ty_bare_fn(None, _) => { let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, fn_ty_a); try!(self.subtype(a_fn_pointer, b)); diff --git a/src/librustc/middle/infer/combine.rs b/src/librustc/middle/infer/combine.rs index 2950705876115..dd711fcbf022e 100644 --- a/src/librustc/middle/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -644,12 +644,6 @@ pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, Ok(ty::mk_bare_fn(tcx, a_opt_def_id, tcx.mk_bare_fn(fty))) } - (&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => { - this.closure_tys(&**a_fty, &**b_fty).and_then(|fty| { - Ok(ty::mk_closure(tcx, fty)) - }) - } - (&ty::ty_projection(ref a_data), &ty::ty_projection(ref b_data)) => { let projection_ty = try!(this.projection_tys(a_data, b_data)); Ok(ty::mk_projection(tcx, projection_ty.trait_ref, projection_ty.item_name)) diff --git a/src/librustc/middle/infer/freshen.rs b/src/librustc/middle/infer/freshen.rs index 7488a72b4e460..608ae31475327 100644 --- a/src/librustc/middle/infer/freshen.rs +++ b/src/librustc/middle/infer/freshen.rs @@ -152,7 +152,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { ty::ty_ptr(..) | ty::ty_rptr(..) | ty::ty_bare_fn(..) | - ty::ty_closure(..) | ty::ty_trait(..) | ty::ty_struct(..) | ty::ty_unboxed_closure(..) | diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 31c3ca4199feb..f5ab4e80945ad 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -197,8 +197,7 @@ pub enum deref_kind { // pointer adjustment). pub fn deref_kind(t: Ty) -> McResult { match t.sty { - ty::ty_uniq(_) | - ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => { + ty::ty_uniq(_) => { Ok(deref_ptr(Unique)) } @@ -207,13 +206,6 @@ pub fn deref_kind(t: Ty) -> McResult { Ok(deref_ptr(BorrowedPtr(kind, *r))) } - ty::ty_closure(box ty::ClosureTy { - store: ty::RegionTraitStore(r, _), - .. - }) => { - Ok(deref_ptr(BorrowedPtr(ty::ImmBorrow, r))) - } - ty::ty_ptr(ref mt) => { Ok(deref_ptr(UnsafePtr(mt.mutbl))) } @@ -592,25 +584,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { def::DefUpvar(var_id, fn_node_id, _) => { let ty = try!(self.node_ty(fn_node_id)); match ty.sty { - ty::ty_closure(ref closure_ty) => { - // Translate old closure type info into unboxed - // closure kind/capture mode - let (mode, kind) = match (closure_ty.store, closure_ty.onceness) { - // stack closure - (ty::RegionTraitStore(..), ast::Many) => { - (ast::CaptureByRef, ty::FnMutUnboxedClosureKind) - } - // proc or once closure - (_, ast::Once) => { - (ast::CaptureByValue, ty::FnOnceUnboxedClosureKind) - } - // There should be no such old closure type - (ty::UniqTraitStore, ast::Many) => { - self.tcx().sess.span_bug(span, "Impossible closure type"); - } - }; - self.cat_upvar(id, span, var_id, fn_node_id, kind, mode, false) - } ty::ty_unboxed_closure(closure_id, _, _) => { let kind = self.typer.unboxed_closure_kind(closure_id); let mode = self.typer.capture_mode(fn_node_id); diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index e6805cddae05a..55abe895183f1 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -118,7 +118,6 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { ty::ty_float(..) | ty::ty_str(..) | ty::ty_bare_fn(..) | - ty::ty_closure(..) | ty::ty_vec(..) | ty::ty_ptr(..) | ty::ty_rptr(..) | diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index f499cf61301aa..2393b7d733d00 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1273,62 +1273,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::ty_closure(ref c) => { - match c.store { - ty::UniqTraitStore => { - // proc: Equivalent to `Box` - match bound { - ty::BoundCopy => { - Err(Unimplemented) - } - - ty::BoundSized => { - Ok(If(Vec::new())) - } - - ty::BoundSync | - ty::BoundSend => { - if c.bounds.builtin_bounds.contains(&bound) { - Ok(If(Vec::new())) - } else { - Err(Unimplemented) - } - } - } - } - ty::RegionTraitStore(_, mutbl) => { - // ||: Equivalent to `&FnMut` or `&mut FnMut` or something like that. - match bound { - ty::BoundCopy => { - match mutbl { - ast::MutMutable => { - // &mut T is affine - Err(Unimplemented) - } - ast::MutImmutable => { - // &T is copyable, no matter what T is - Ok(If(Vec::new())) - } - } - } - - ty::BoundSized => { - Ok(If(Vec::new())) - } - - ty::BoundSync | - ty::BoundSend => { - if c.bounds.builtin_bounds.contains(&bound) { - Ok(If(Vec::new())) - } else { - Err(Unimplemented) - } - } - } - } - } - } - ty::ty_trait(ref data) => { match bound { ty::BoundSized => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 5834844382207..31916848f5dc8 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -916,7 +916,7 @@ impl<'tcx> ctxt<'tcx> { pub fn print_debug_stats(&self) { sty_debug_print!( self, - ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_closure, ty_trait, + ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_trait, ty_struct, ty_unboxed_closure, ty_tup, ty_param, ty_open, ty_infer, ty_projection); println!("Substs interner: #{}", self.substs_interner.borrow().len()); @@ -1353,7 +1353,6 @@ pub enum sty<'tcx> { // fn item. Otherwise, if None(_), it a fn pointer type. ty_bare_fn(Option, &'tcx BareFnTy<'tcx>), - ty_closure(Box>), ty_trait(Box>), ty_struct(DefId, &'tcx Substs<'tcx>), @@ -2594,14 +2593,6 @@ impl FlagComputation { &ty_bare_fn(_, ref f) => { self.add_fn_sig(&f.sig); } - - &ty_closure(ref f) => { - if let RegionTraitStore(r, _) = f.store { - self.add_region(r); - } - self.add_fn_sig(&f.sig); - self.add_bounds(&f.bounds); - } } } @@ -2749,7 +2740,7 @@ pub fn mk_nil<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> { } pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> { - mk_t(cx, ty_closure(box fty)) + panic!("stub"); } pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>, @@ -3028,7 +3019,7 @@ pub fn type_is_vec(ty: Ty) -> bool { pub fn type_is_structural(ty: Ty) -> bool { match ty.sty { - ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_closure(_) | + ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_vec(_, Some(_)) | ty_unboxed_closure(..) => true, _ => type_is_slice(ty) | type_is_trait(ty) } @@ -3345,10 +3336,6 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { TC::None } - ty_closure(ref c) => { - closure_contents(&**c) | TC::ReachesFfiUnsafe - } - ty_uniq(typ) => { TC::ReachesFfiUnsafe | match typ.sty { ty_str => TC::OwnsOwned, @@ -3649,7 +3636,6 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool { ty_float(_) | ty_str | ty_bare_fn(..) | - ty_closure(_) | ty_param(_) | ty_projection(_) | ty_vec(_, None) => { @@ -4153,7 +4139,6 @@ pub fn node_id_item_substs<'tcx>(cx: &ctxt<'tcx>, id: ast::NodeId) -> ItemSubsts pub fn fn_is_variadic(fty: Ty) -> bool { match fty.sty { ty_bare_fn(_, ref f) => f.sig.0.variadic, - ty_closure(ref f) => f.sig.0.variadic, ref s => { panic!("fn_is_variadic() called on non-fn type: {}", s) } @@ -4163,7 +4148,6 @@ pub fn fn_is_variadic(fty: Ty) -> bool { pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> { match fty.sty { ty_bare_fn(_, ref f) => &f.sig, - ty_closure(ref f) => &f.sig, ref s => { panic!("ty_fn_sig() called on non-fn type: {}", s) } @@ -4174,7 +4158,6 @@ pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx PolyFnSig<'tcx> { pub fn ty_fn_abi(fty: Ty) -> abi::Abi { match fty.sty { ty_bare_fn(_, ref f) => f.abi, - ty_closure(ref f) => f.abi, _ => panic!("ty_fn_abi() called on non-fn type"), } } @@ -4186,7 +4169,6 @@ pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] { pub fn ty_closure_store(fty: Ty) -> TraitStore { match fty.sty { - ty_closure(ref f) => f.store, ty_unboxed_closure(..) => { // Close enough for the purposes of all the callers of this // function (which is soon to be deprecated anyhow). @@ -4201,7 +4183,6 @@ pub fn ty_closure_store(fty: Ty) -> TraitStore { pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> { match fty.sty { ty_bare_fn(_, ref f) => f.sig.0.output, - ty_closure(ref f) => f.sig.0.output, ref s => { panic!("ty_fn_ret() called on non-fn type: {}", s) } @@ -4211,7 +4192,6 @@ pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> FnOutput<'tcx> { pub fn is_fn_ty(fty: Ty) -> bool { match fty.sty { ty_bare_fn(..) => true, - ty_closure(_) => true, _ => false } } @@ -4731,7 +4711,6 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String { ty_rptr(_, _) => "&-ptr".to_string(), ty_bare_fn(Some(_), _) => format!("fn item"), ty_bare_fn(None, _) => "fn pointer".to_string(), - ty_closure(_) => "fn".to_string(), ty_trait(ref inner) => { format!("trait {}", item_path_str(cx, inner.principal_def_id())) } @@ -6326,24 +6305,6 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) - fn_sig(state, &b.sig); return false; } - ty_closure(ref c) => { - byte!(15); - hash!(c.unsafety); - hash!(c.onceness); - hash!(c.bounds); - match c.store { - UniqTraitStore => byte!(0), - RegionTraitStore(r, m) => { - byte!(1); - region(state, r); - assert_eq!(m, ast::MutMutable); - } - } - - fn_sig(state, &c.sig); - - return false; - } ty_trait(ref data) => { byte!(17); did(state, data.principal_def_id()); @@ -6666,12 +6627,6 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec, ty_struct(_, substs) => { accum_substs(accumulator, substs); } - ty_closure(ref closure_ty) => { - match closure_ty.store { - RegionTraitStore(region, _) => accumulator.push(region), - UniqTraitStore => {} - } - } ty_unboxed_closure(_, region, substs) => { accumulator.push(*region); accum_substs(accumulator, substs); diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index 6fc5919669402..1bc0d70945899 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -604,9 +604,6 @@ pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, let bfn = f.fold_with(this); ty::ty_bare_fn(opt_def_id, this.tcx().mk_bare_fn(bfn)) } - ty::ty_closure(ref f) => { - ty::ty_closure(f.fold_with(this)) - } ty::ty_rptr(r, ref tm) => { let r = r.fold_with(this); ty::ty_rptr(this.tcx().mk_region(r), tm.fold_with(this)) diff --git a/src/librustc/middle/ty_walk.rs b/src/librustc/middle/ty_walk.rs index 6070a4208f663..4953e9a2ce1d1 100644 --- a/src/librustc/middle/ty_walk.rs +++ b/src/librustc/middle/ty_walk.rs @@ -51,9 +51,6 @@ impl<'tcx> TypeWalker<'tcx> { ty::ty_bare_fn(_, ref ft) => { self.push_sig_subtypes(&ft.sig); } - ty::ty_closure(ref ft) => { - self.push_sig_subtypes(&ft.sig); - } } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 9639af5ca1cd5..e6ee16d1789c0 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -18,7 +18,7 @@ use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty}; use middle::ty::{ReSkolemized, ReVar, BrEnv}; use middle::ty::{mt, Ty, ParamTy}; use middle::ty::{ty_bool, ty_char, ty_struct, ty_enum}; -use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure}; +use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn}; use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open}; use middle::ty::{ty_unboxed_closure}; use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer}; @@ -417,9 +417,6 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String { strs => format!("({})", strs.connect(", ")) } } - ty_closure(ref f) => { - closure_to_string(cx, &**f) - } ty_bare_fn(opt_def_id, ref f) => { bare_fn_to_string(cx, opt_def_id, f.unsafety, f.abi, None, &f.sig) } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 75545634b40cf..e1f0c9ec26677 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -662,13 +662,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { default_msgs: (&'static str, &'static str)) -> (&'static str, &'static str) { match ty.sty { - ty::ty_closure(box ty::ClosureTy { - store: ty::RegionTraitStore(..), - .. - }) => { - ("a non-copyable stack closure", - "capture it in a new closure, e.g. `|x| f(x)`, to override") - } _ => { if ty::type_moves_by_default(param_env, span, ty) { ("non-copyable", diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index 223df5d3a5785..01b47b728b6ba 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -355,12 +355,6 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>, // Functions are just pointers ty::ty_bare_fn(..) => Some(path), - // Closures are a pair of pointers: the code and environment - ty::ty_closure(..) => { - path.push(FAT_PTR_ADDR); - Some(path) - }, - // Is this the NonZero lang item wrapping a pointer or integer type? ty::ty_struct(did, substs) if Some(did) == tcx.lang_items.non_zero() => { let nonzero_fields = ty::lookup_struct_fields(tcx, did); diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 9814a4ed183a8..56c1e2ddba0b5 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -287,9 +287,6 @@ pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty::ty_bare_fn(_, ref f) => { (f.sig.0.inputs.clone(), f.sig.0.output, f.abi, None) } - ty::ty_closure(ref f) => { - (f.sig.0.inputs.clone(), f.sig.0.output, f.abi, Some(Type::i8p(ccx))) - } ty::ty_unboxed_closure(closure_did, _, substs) => { let typer = common::NormalizingUnboxedClosureTyper::new(ccx.tcx()); let function_type = typer.unboxed_closure_type(closure_did, substs); @@ -952,9 +949,6 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, } } } - ty::ty_closure(_) => { - get_extern_rust_fn(ccx, t, name[], did) - } _ => { get_extern_const(ccx, did, t) } @@ -2438,7 +2432,6 @@ pub fn get_fn_llvm_attributes<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty< use middle::ty::{BrAnon, ReLateBound}; let (fn_sig, abi, has_env) = match fn_ty.sty { - ty::ty_closure(ref f) => (f.sig.clone(), f.abi, true), ty::ty_bare_fn(_, ref f) => (f.sig.clone(), f.abi, false), ty::ty_unboxed_closure(closure_did, _, substs) => { let typer = common::NormalizingUnboxedClosureTyper::new(ccx.tcx()); diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index b0fc9fef2fd11..8048d0218df2d 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -111,14 +111,6 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) data: Fn(llval), }; } - ty::ty_closure(..) => { - let datum = unpack_datum!( - bcx, datum.to_lvalue_datum(bcx, "callee", expr.id)); - return Callee { - bcx: bcx, - data: Closure(datum), - }; - } _ => { bcx.tcx().sess.span_bug( expr.span, @@ -679,7 +671,6 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, let (abi, ret_ty) = match callee_ty.sty { ty::ty_bare_fn(_, ref f) => (f.abi, f.sig.0.output), - ty::ty_closure(ref f) => (f.abi, f.sig.0.output), _ => panic!("expected bare rust fn or closure in trans_call_inner") }; diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index 7b394cef192eb..cb0d2f3edd4d6 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -599,7 +599,6 @@ pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, debug!("get_wrapper_for_bare_fn(closure_ty={})", closure_ty.repr(tcx)); let f = match closure_ty.sty { - ty::ty_closure(ref f) => f, _ => { ccx.sess().bug(format!("get_wrapper_for_bare_fn: \ expected a closure ty, got {}", diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 916fcbfe13ef7..84ae088f5beae 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -465,11 +465,6 @@ impl<'tcx> TypeMap<'tcx> { } } }, - ty::ty_closure(box ref closure_ty) => { - self.get_unique_type_id_of_closure_type(cx, - closure_ty.clone(), - &mut unique_type_id); - }, ty::ty_unboxed_closure(def_id, _, substs) => { let typer = NormalizingUnboxedClosureTyper::new(cx.tcx()); let closure_ty = typer.unboxed_closure_type(def_id, substs); @@ -3017,9 +3012,6 @@ fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::ty_bare_fn(_, ref barefnty) => { subroutine_type_metadata(cx, unique_type_id, &barefnty.sig, usage_site_span) } - ty::ty_closure(ref closurety) => { - subroutine_type_metadata(cx, unique_type_id, &closurety.sig, usage_site_span) - } ty::ty_unboxed_closure(def_id, _, substs) => { let typer = NormalizingUnboxedClosureTyper::new(cx.tcx()); let sig = typer.unboxed_closure_type(def_id, substs).sig; @@ -3870,66 +3862,6 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, } } }, - ty::ty_closure(box ty::ClosureTy { unsafety, - onceness, - store, - ref sig, - .. // omitting bounds ... - }) => { - if unsafety == ast::Unsafety::Unsafe { - output.push_str("unsafe "); - } - - if onceness == ast::Once { - output.push_str("once "); - } - - let param_list_closing_char; - match store { - ty::UniqTraitStore => { - output.push_str("proc("); - param_list_closing_char = ')'; - } - ty::RegionTraitStore(_, ast::MutMutable) => { - output.push_str("&mut|"); - param_list_closing_char = '|'; - } - ty::RegionTraitStore(_, ast::MutImmutable) => { - output.push_str("&|"); - param_list_closing_char = '|'; - } - }; - - if sig.0.inputs.len() > 0 { - for ¶meter_type in sig.0.inputs.iter() { - push_debuginfo_type_name(cx, parameter_type, true, output); - output.push_str(", "); - } - output.pop(); - output.pop(); - } - - if sig.0.variadic { - if sig.0.inputs.len() > 0 { - output.push_str(", ..."); - } else { - output.push_str("..."); - } - } - - output.push(param_list_closing_char); - - match sig.0.output { - ty::FnConverging(result_type) if ty::type_is_nil(result_type) => {} - ty::FnConverging(result_type) => { - output.push_str(" -> "); - push_debuginfo_type_name(cx, result_type, true, output); - } - ty::FnDiverging => { - output.push_str(" -> !"); - } - } - }, ty::ty_unboxed_closure(..) => { output.push_str("closure"); } diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index 116ce2bf51dbe..491c6a83ca9bf 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -441,18 +441,6 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: Ty<'tcx>) v0, t, |bb, vv, tt| drop_ty(bb, vv, tt, None)), - ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => { - let box_cell_v = GEPi(bcx, v0, &[0u, abi::FAT_PTR_EXTRA]); - let env = Load(bcx, box_cell_v); - let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to(); - let env = PointerCast(bcx, env, env_ptr_ty); - with_cond(bcx, IsNotNull(bcx, env), |bcx| { - let dtor_ptr = GEPi(bcx, env, &[0u, abi::BOX_FIELD_DROP_GLUE]); - let dtor = Load(bcx, dtor_ptr); - Call(bcx, dtor, &[PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None); - bcx - }) - } ty::ty_trait(..) => { // No need to do a null check here (as opposed to the Box(cx: &CrateContext<'a, 'tcx>, // Given a function type and a count of ty params, construct an llvm type pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type { match fty.sty { - ty::ty_closure(ref f) => { - type_of_rust_fn(cx, - Some(Type::i8p(cx)), - f.sig.0.inputs.as_slice(), - f.sig.0.output, - f.abi) - } ty::ty_bare_fn(_, ref f) => { // FIXME(#19925) once fn item types are // zero-sized, we'll need to do something here @@ -207,7 +200,6 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ } ty::ty_bare_fn(..) => Type::i8p(cx), - ty::ty_closure(..) => Type::struct_(cx, &[Type::i8p(cx), Type::i8p(cx)], false), ty::ty_vec(ty, Some(size)) => { let llty = sizing_type_of(cx, ty); @@ -369,10 +361,6 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { ty::ty_bare_fn(..) => { type_of_fn_from_ty(cx, t).ptr_to() } - ty::ty_closure(_) => { - let fn_ty = type_of_fn_from_ty(cx, t).ptr_to(); - Type::struct_(cx, &[fn_ty, Type::i8p(cx)], false) - } ty::ty_tup(ref tys) if tys.is_empty() => Type::nil(cx), ty::ty_tup(..) => { let repr = adt::represent_type(cx, t); diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 153c6463fbebb..98a826355a73a 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -111,7 +111,7 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, { // If the callee is a bare function or a closure, then we're all set. match structurally_resolved_type(fcx, callee_expr.span, adjusted_ty).sty { - ty::ty_bare_fn(..) | ty::ty_closure(_) => { + ty::ty_bare_fn(..) => { fcx.write_adjustment(callee_expr.id, callee_expr.span, ty::AdjustDerefRef(autoderefref)); @@ -158,8 +158,7 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, let error_fn_sig; let fn_sig = match callee_ty.sty { - ty::ty_bare_fn(_, &ty::BareFnTy {ref sig, ..}) | - ty::ty_closure(box ty::ClosureTy {ref sig, ..}) => { + ty::ty_bare_fn(_, &ty::BareFnTy {ref sig, ..}) => { sig } _ => { diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index db84f1dce9751..1368b3325a57f 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -268,7 +268,6 @@ fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, // fresh bound regions for any bound regions we find in the // expected types so as to avoid capture. let expected_cenv = expected.map_to_option(fcx, |ty| match ty.sty { - ty::ty_closure(ref cenv) => Some(cenv), _ => None }); let (expected_sig, expected_onceness, expected_bounds) = match expected_cenv { diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 54d2378256d3a..adea5084aab2b 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -462,7 +462,6 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { method_callee: &MethodCallee) { let sig = match method_callee.ty.sty { ty::ty_bare_fn(_, ref f) => f.sig.clone(), - ty::ty_closure(ref f) => f.sig.clone(), _ => return, }; diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b5ddb528c2f2f..2adbd1f0a3f7f 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -735,29 +735,6 @@ fn check_expr_fn_block(rcx: &mut Rcx, let function_type = rcx.resolve_node_type(expr.id); match function_type.sty { - ty::ty_closure(box ty::ClosureTy{store: ty::RegionTraitStore(..), - ref bounds, - ..}) => { - // For closure, ensure that the variables outlive region - // bound, since they are captured by reference. - ty::with_freevars(tcx, expr.id, |freevars| { - if freevars.is_empty() { - // No free variables means that the environment - // will be NULL at runtime and hence the closure - // has static lifetime. - } else { - // Variables being referenced must outlive closure. - constrain_free_variables_in_by_ref_closure( - rcx, bounds.region_bound, expr, freevars); - - // Closure is stack allocated and hence cannot - // outlive the appropriate temporary scope. - let s = rcx.repeating_scope; - rcx.fcx.mk_subr(infer::InfStackClosure(expr.span), - bounds.region_bound, ty::ReScope(CodeExtent::from_node_id(s))); - } - }); - } ty::ty_unboxed_closure(_, region, _) => { if tcx.capture_modes.borrow()[expr.id].clone() == ast::CaptureByRef { ty::with_freevars(tcx, expr.id, |freevars| { @@ -778,11 +755,6 @@ fn check_expr_fn_block(rcx: &mut Rcx, rcx.set_repeating_scope(repeating_scope); match function_type.sty { - ty::ty_closure(box ty::ClosureTy {ref bounds, ..}) => { - ty::with_freevars(tcx, expr.id, |freevars| { - ensure_free_variable_types_outlive_closure_bound(rcx, bounds, expr, freevars); - }) - } ty::ty_unboxed_closure(_, region, _) => { ty::with_freevars(tcx, expr.id, |freevars| { let bounds = ty::region_existential_bound(*region); @@ -891,26 +863,6 @@ fn constrain_callee(rcx: &mut Rcx, let callee_ty = rcx.resolve_node_type(callee_id); match callee_ty.sty { ty::ty_bare_fn(..) => { } - ty::ty_closure(ref closure_ty) => { - let region = match closure_ty.store { - ty::RegionTraitStore(r, _) => { - // While we're here, link the closure's region with a unique - // immutable borrow (gathered later in borrowck) - let mc = mc::MemCategorizationContext::new(rcx.fcx); - let expr_cmt = ignore_err!(mc.cat_expr(callee_expr)); - link_region(rcx, callee_expr.span, call_region, - ty::UniqueImmBorrow, expr_cmt); - r - } - ty::UniqTraitStore => ty::ReStatic - }; - rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span), - call_region, region); - - let region = closure_ty.bounds.region_bound; - rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span), - call_region, region); - } _ => { // this should not happen, but it does if the program is // erroneous diff --git a/src/librustc_typeck/check/regionmanip.rs b/src/librustc_typeck/check/regionmanip.rs index 66cf077d4c21f..e73fa195b0448 100644 --- a/src/librustc_typeck/check/regionmanip.rs +++ b/src/librustc_typeck/check/regionmanip.rs @@ -67,10 +67,6 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { // No borrowed content reachable here. } - ty::ty_closure(box ref c) => { - self.accumulate_from_closure_ty(ty, c); - } - ty::ty_unboxed_closure(_, region, _) => { // An "unboxed closure type" is basically // modeled here as equivalent to a struct like diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 1fdb68854c01f..92fda96595c7b 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -122,7 +122,6 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> { _body: &ast::Block) { let is_old_skool_closure = match self.fcx.expr_ty(expr).sty { - ty::ty_closure(..) => true, _ => false, }; diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index bb2c6221e2162..09ab98745bd6a 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -22,7 +22,7 @@ use middle::subst::{self, Subst}; use middle::ty::RegionEscape; use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId}; use middle::ty::{ParameterEnvironment, TypeTraitItemId, lookup_item_type}; -use middle::ty::{Ty, ty_bool, ty_char, ty_closure, ty_enum, ty_err}; +use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err}; use middle::ty::{ty_param, TypeScheme, ty_ptr}; use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup}; use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open}; @@ -69,7 +69,7 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>, } ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) | - ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_closure(..) | ty_tup(..) | + ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_tup(..) | ty_param(..) | ty_err | ty_open(..) | ty_uniq(_) | ty_ptr(_) | ty_rptr(_, _) | ty_projection(..) => { None diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index 6bef7e713af28..e58c2275fcd96 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -831,20 +831,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } } - ty::ty_bare_fn(_, &ty::BareFnTy { ref sig, .. }) | - ty::ty_closure(box ty::ClosureTy { - ref sig, - store: ty::UniqTraitStore, - .. - }) => - { - self.add_constraints_from_sig(generics, sig, variance); - } - - ty::ty_closure(box ty::ClosureTy { ref sig, - store: ty::RegionTraitStore(region, _), .. }) => { - let contra = self.contravariant(variance); - self.add_constraints_from_region(generics, region, contra); + ty::ty_bare_fn(_, &ty::BareFnTy { ref sig, .. }) => { self.add_constraints_from_sig(generics, sig, variance); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5f6c62f1d7a68..e2ca4b1ecdbc7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1426,19 +1426,6 @@ impl<'tcx> Clean for ty::Ty<'tcx> { decl: (ast_util::local_def(0), &fty.sig).clean(cx), abi: fty.abi.to_string(), }), - ty::ty_closure(ref fty) => { - let decl = box ClosureDecl { - lifetimes: Vec::new(), // FIXME: this looks wrong... - decl: (ast_util::local_def(0), &fty.sig).clean(cx), - onceness: fty.onceness, - unsafety: fty.unsafety, - bounds: fty.bounds.clean(cx), - }; - match fty.store { - ty::UniqTraitStore => Proc(decl), - ty::RegionTraitStore(..) => Closure(decl), - } - } ty::ty_struct(did, substs) | ty::ty_enum(did, substs) => { let fqn = csearch::get_item_path(cx.tcx(), did); From 714a5b7f5e960c885030fac4b357ec1304f539f9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:51:37 -0500 Subject: [PATCH 14/37] remove TyClosure --- src/librustc/middle/resolve_lifetime.rs | 12 ------------ src/librustc_resolve/lib.rs | 10 +--------- src/librustc_typeck/astconv.rs | 22 ---------------------- src/librustdoc/clean/mod.rs | 1 - src/libsyntax/ast.rs | 2 -- src/libsyntax/ast_map/mod.rs | 3 --- src/libsyntax/feature_gate.rs | 6 ------ src/libsyntax/fold.rs | 11 ----------- src/libsyntax/parse/parser.rs | 10 ++-------- src/libsyntax/print/pprust.rs | 19 ------------------- src/libsyntax/visit.rs | 8 -------- 11 files changed, 3 insertions(+), 101 deletions(-) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index c9273e0b8d5b1..68cb8ca39b492 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -136,18 +136,6 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> { fn visit_ty(&mut self, ty: &ast::Ty) { match ty.node { - ast::TyClosure(ref c) => { - // Careful, the bounds on a closure/proc are *not* within its binder. - visit::walk_ty_param_bounds_helper(self, &c.bounds); - visit::walk_lifetime_decls_helper(self, &c.lifetimes); - self.with(LateScope(&c.lifetimes, self.scope), |old_scope, this| { - this.check_lifetime_defs(old_scope, &c.lifetimes); - for argument in c.decl.inputs.iter() { - this.visit_ty(&*argument.ty) - } - visit::walk_fn_ret_ty(this, &c.decl.output); - }); - } ast::TyBareFn(ref c) => { visit::walk_lifetime_decls_helper(self, &c.lifetimes); self.with(LateScope(&c.lifetimes, self.scope), |old_scope, this| { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2c2678c8dc68e..a2c86c3cdb756 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -71,7 +71,7 @@ use syntax::ast::{PatRange, PatStruct, Path}; use syntax::ast::{PolyTraitRef, PrimTy, SelfExplicit}; use syntax::ast::{RegionTyParamBound, StructField}; use syntax::ast::{TraitRef, TraitTyParamBound}; -use syntax::ast::{Ty, TyBool, TyChar, TyClosure, TyF32}; +use syntax::ast::{Ty, TyBool, TyChar, TyF32}; use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum}; use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyPolyTraitRef, TyQPath}; use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint}; @@ -3606,14 +3606,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.resolve_trait_reference(ty.id, &*qpath.trait_ref, TraitQPath); } - TyClosure(ref c) => { - self.resolve_type_parameter_bounds( - ty.id, - &c.bounds, - TraitBoundingTypeParameter); - visit::walk_ty(self, ty); - } - TyPolyTraitRef(ref bounds) => { self.resolve_type_parameter_bounds( ty.id, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index c616f4feaff02..bde834c2ff899 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1112,28 +1112,6 @@ pub fn ast_ty_to_ty<'tcx>( let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl); ty::mk_bare_fn(tcx, None, tcx.mk_bare_fn(bare_fn)) } - ast::TyClosure(ref f) => { - // Use corresponding trait store to figure out default bounds - // if none were specified. - let bounds = conv_existential_bounds(this, - rscope, - ast_ty.span, - None, - Vec::new(), - f.bounds.as_slice()); - let region_bound = bounds.region_bound; - let fn_decl = ty_of_closure(this, - f.unsafety, - f.onceness, - bounds, - ty::RegionTraitStore( - region_bound, - ast::MutMutable), - &*f.decl, - abi::Rust, - None); - ty::mk_closure(tcx, fn_decl) - } ast::TyPolyTraitRef(ref bounds) => { conv_ty_poly_trait_ref(this, rscope, ast_ty.span, bounds[]) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e2ca4b1ecdbc7..e01dbac68ee8d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1366,7 +1366,6 @@ impl Clean for ast::Ty { } } } - TyClosure(ref c) => Closure(box c.clean(cx)), TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)), TyParen(ref ty) => ty.clean(cx), TyQPath(ref qp) => qp.clean(cx), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c9d27e304ff15..e779821342a17 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1220,8 +1220,6 @@ pub enum Ty_ { TyPtr(MutTy), /// A reference (`&'a T` or `&'a mut T`) TyRptr(Option, MutTy), - /// A closure (e.g. `|uint| -> bool`) - TyClosure(P), /// A bare function (e.g. `fn(uint) -> bool`) TyBareFn(P), /// A tuple (`(A, B, C, D,...)`) diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index ce7b964959f11..cf09e2777f7c6 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -859,9 +859,6 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { fn visit_ty(&mut self, ty: &'ast Ty) { match ty.node { - TyClosure(ref fd) => { - self.visit_fn_decl(&*fd.decl); - } TyBareFn(ref fd) => { self.visit_fn_decl(&*fd.decl); } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index f8ac34cfe2920..cb6277069e1a2 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -364,12 +364,6 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_ty(&mut self, t: &ast::Ty) { - if let ast::TyClosure(ref closure) = t.node { - // this used to be blocked by a feature gate, but it should just - // be plain impossible right now - assert!(closure.onceness != ast::Once); - } - visit::walk_ty(self, t); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 35b2e5dbc5381..396b0033b815f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -414,17 +414,6 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { TyRptr(region, mt) => { TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt)) } - TyClosure(f) => { - TyClosure(f.map(|ClosureTy {unsafety, onceness, bounds, decl, lifetimes}| { - ClosureTy { - unsafety: unsafety, - 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, unsafety, abi, decl}| BareFnTy { lifetimes: fld.fold_lifetime_defs(lifetimes), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cc67079e53879..9bc91a95841a5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -55,7 +55,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, TyBareFn}; +use ast::{TypeField, TyFixedLengthVec, TyBareFn}; use ast::{TyTypeof, TyInfer, TypeMethod}; use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath}; use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq}; @@ -1252,13 +1252,7 @@ impl<'a> Parser<'a> { variadic: false }); - TyClosure(P(ClosureTy { - unsafety: unsafety, - onceness: Many, - bounds: bounds, - decl: decl, - lifetimes: lifetime_defs, - })) + panic!("stub"); } pub fn parse_unsafety(&mut self) -> Unsafety { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 61b7aa408a8d5..e44cc2257c24c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -714,25 +714,6 @@ impl<'a> State<'a> { Some(&generics), None)); } - ast::TyClosure(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.unsafety, - f.onceness, - &*f.decl, - None, - &f.bounds, - Some(&generics), - None)); - } ast::TyPath(ref path, _) => { try!(self.print_path(path, false)); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 054a288a69e6d..737f1b73b3290 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -404,14 +404,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_ty(&**tuple_element_type) } } - TyClosure(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) From 4e9c50e081f92cbf45df7f8ecbff3b05e26abf36 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:53:08 -0500 Subject: [PATCH 15/37] remove AdjustAddEnv --- src/librustc/middle/astencode.rs | 15 ---------- src/librustc/middle/expr_use_visitor.rs | 1 - src/librustc/middle/mem_categorization.rs | 4 +-- src/librustc/middle/ty.rs | 34 +---------------------- src/librustc_trans/trans/consts.rs | 14 ---------- src/librustc_trans/trans/expr.rs | 5 +--- src/librustc_typeck/check/mod.rs | 1 - src/librustc_typeck/check/writeback.rs | 4 --- 8 files changed, 4 insertions(+), 74 deletions(-) diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 269b09a5f2ed8..93a19a01f668f 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1031,13 +1031,6 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { self.emit_enum("AutoAdjustment", |this| { match *adj { - ty::AdjustAddEnv(def_id, store) => { - this.emit_enum_variant("AdjustAddEnv", 0, 2, |this| { - this.emit_enum_variant_arg(0, |this| def_id.encode(this)); - this.emit_enum_variant_arg(1, |this| store.encode(this)) - }) - } - ty::AdjustReifyFnPointer(def_id) => { this.emit_enum_variant("AdjustReifyFnPointer", 1, 2, |this| { this.emit_enum_variant_arg(0, |this| def_id.encode(this)) @@ -1678,14 +1671,6 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { let variants = ["AutoAddEnv", "AutoDerefRef"]; this.read_enum_variant(&variants, |this, i| { Ok(match i { - 0 => { - let def_id: ast::DefId = - this.read_def_id(dcx); - let store: ty::TraitStore = - this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap(); - - ty::AdjustAddEnv(def_id, store.tr(dcx)) - } 1 => { let def_id: ast::DefId = this.read_def_id(dcx); diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index ed5e8e31b7bb5..df2a4e4c2532a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -823,7 +823,6 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { None => { } Some(adjustment) => { match *adjustment { - ty::AdjustAddEnv(..) | ty::AdjustReifyFnPointer(..) => { // Creating a closure/fn-pointer consumes the // input and stores it into the resulting diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index f5ab4e80945ad..dd61db4270ce3 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -413,8 +413,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { Some(adjustment) => { match *adjustment { - ty::AdjustAddEnv(..) | ty::AdjustReifyFnPointer(..) => { - debug!("cat_expr(AdjustAddEnv|AdjustReifyFnPointer): {}", + ty::AdjustReifyFnPointer(..) => { + debug!("cat_expr(AdjustReifyFnPointer): {}", expr.repr(self.tcx())); // Convert a bare fn to a closure by adding NULL env. // Result is an rvalue. diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 31916848f5dc8..bc6ac8abe38f5 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -293,7 +293,6 @@ pub enum Variance { #[derive(Clone, Show)] pub enum AutoAdjustment<'tcx> { - AdjustAddEnv(ast::DefId, ty::TraitStore), AdjustReifyFnPointer(ast::DefId), // go from a fn-item type to a fn-pointer type AdjustDerefRef(AutoDerefRef<'tcx>) } @@ -4315,33 +4314,6 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>, return match adjustment { Some(adjustment) => { match *adjustment { - AdjustAddEnv(_, store) => { - match unadjusted_ty.sty { - ty::ty_bare_fn(Some(_), ref b) => { - let bounds = ty::ExistentialBounds { - region_bound: ReStatic, - builtin_bounds: all_builtin_bounds(), - projection_bounds: vec!(), - }; - - ty::mk_closure( - cx, - ty::ClosureTy {unsafety: b.unsafety, - onceness: ast::Many, - store: store, - bounds: bounds, - sig: b.sig.clone(), - abi: b.abi}) - } - ref b => { - cx.sess.bug( - format!("add_env adjustment on non-fn-item: \ - {}", - b).as_slice()); - } - } - } - AdjustReifyFnPointer(_) => { match unadjusted_ty.sty { ty::ty_bare_fn(Some(_), b) => { @@ -6696,7 +6668,6 @@ pub fn with_freevars(tcx: &ty::ctxt, fid: ast::NodeId, f: F) -> T where impl<'tcx> AutoAdjustment<'tcx> { pub fn is_identity(&self) -> bool { match *self { - AdjustAddEnv(..) => false, AdjustReifyFnPointer(..) => false, AdjustDerefRef(ref r) => r.is_identity(), } @@ -6820,11 +6791,8 @@ impl DebruijnIndex { impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { match *self { - AdjustAddEnv(def_id, ref trait_store) => { - format!("AdjustAddEnv({},{})", def_id.repr(tcx), trait_store) - } AdjustReifyFnPointer(def_id) => { - format!("AdjustAddEnv({})", def_id.repr(tcx)) + format!("AdjustReifyFnPointer({})", def_id.repr(tcx)) } AdjustDerefRef(ref data) => { data.repr(tcx) diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index b17e852d7cbc4..2738f1bca6e1e 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -189,20 +189,6 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, e: &ast::Expr) None => { } Some(adj) => { match adj { - ty::AdjustAddEnv(def_id, ty::RegionTraitStore(ty::ReStatic, _)) => { - let wrapper = closure::get_wrapper_for_bare_fn(cx, - ety_adjusted, - def_id, - llconst, - true); - llconst = C_struct(cx, &[wrapper, C_null(Type::i8p(cx))], false) - } - ty::AdjustAddEnv(_, store) => { - cx.sess() - .span_bug(e.span, - format!("unexpected static function: {}", - store)[]) - } ty::AdjustReifyFnPointer(_def_id) => { // FIXME(#19925) once fn item types are // zero-sized, we'll need to do something here diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 68557289d52ce..1bf96b7d180e2 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -54,7 +54,7 @@ use trans::inline; use trans::tvec; use trans::type_of; use middle::ty::{struct_fields, tup_fields}; -use middle::ty::{AdjustDerefRef, AdjustReifyFnPointer, AdjustAddEnv, AutoUnsafe}; +use middle::ty::{AdjustDerefRef, AdjustReifyFnPointer, AutoUnsafe}; use middle::ty::{AutoPtr}; use middle::ty::{self, Ty}; use middle::ty::MethodCall; @@ -179,9 +179,6 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, datum.to_string(bcx.ccx()), adjustment.repr(bcx.tcx())); match adjustment { - AdjustAddEnv(def_id, _) => { - datum = unpack_datum!(bcx, add_env(bcx, def_id, expr, datum)); - } AdjustReifyFnPointer(_def_id) => { // FIXME(#19925) once fn item types are // zero-sized, we'll need to do something here diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8b62c55ba31eb..2940d55616968 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1850,7 +1850,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, adj: &ty::AutoAdjustment<'tcx>) { match *adj { - ty::AdjustAddEnv(..) | ty::AdjustReifyFnPointer(..) => { } ty::AdjustDerefRef(ref d_r) => { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 4154937b3fdcd..70644b6e7de5d 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -266,10 +266,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { Some(adjustment) => { let adj_object = ty::adjust_is_object(&adjustment); let resolved_adjustment = match adjustment { - ty::AdjustAddEnv(def_id, store) => { - ty::AdjustAddEnv(def_id, self.resolve(&store, reason)) - } - ty::AdjustReifyFnPointer(def_id) => { ty::AdjustReifyFnPointer(def_id) } From 8a6d7a68b17542f67086d014720d13e3dc320d51 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 09:55:16 -0500 Subject: [PATCH 16/37] remove mk_closure --- src/librustc/metadata/tydecode.rs | 3 --- src/librustc/middle/ty.rs | 4 ---- src/librustc_driver/test.rs | 33 ---------------------------- src/librustc_trans/trans/closure.rs | 5 ++--- src/librustc_typeck/check/closure.rs | 2 +- 5 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 825daa7ddb94c..07dc13ff0d48f 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -506,9 +506,6 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w st.pos = st.pos + 1u; return ty::mk_tup(tcx, params); } - 'f' => { - return ty::mk_closure(tcx, parse_closure_ty_(st, conv)); - } 'F' => { let def_id = parse_def_(st, NominalType, conv); return ty::mk_bare_fn(tcx, Some(def_id), diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index bc6ac8abe38f5..715151434f29d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2738,10 +2738,6 @@ pub fn mk_nil<'tcx>(cx: &ctxt<'tcx>) -> Ty<'tcx> { mk_tup(cx, Vec::new()) } -pub fn mk_closure<'tcx>(cx: &ctxt<'tcx>, fty: ClosureTy<'tcx>) -> Ty<'tcx> { - panic!("stub"); -} - pub fn mk_bare_fn<'tcx>(cx: &ctxt<'tcx>, opt_def_id: Option, fty: &'tcx BareFnTy<'tcx>) -> Ty<'tcx> { diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index ab41ade576a58..b1e65dce6045a 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -277,26 +277,6 @@ impl<'a, 'tcx> Env<'a, 'tcx> { ty::mk_tup(self.infcx.tcx, vec![ty1, ty2]) } - pub fn t_closure(&self, - input_tys: &[Ty<'tcx>], - output_ty: Ty<'tcx>, - region_bound: ty::Region) - -> Ty<'tcx> - { - ty::mk_closure(self.infcx.tcx, ty::ClosureTy { - unsafety: ast::Unsafety::Normal, - onceness: ast::Many, - store: ty::RegionTraitStore(region_bound, ast::MutMutable), - bounds: ty::region_existential_bound(region_bound), - sig: ty::Binder(ty::FnSig { - inputs: input_tys.to_vec(), - output: ty::FnConverging(output_ty), - variadic: false, - }), - abi: abi::Rust, - }) - } - pub fn t_param(&self, space: subst::ParamSpace, index: u32) -> Ty<'tcx> { let name = format!("T{}", index); ty::mk_param(self.infcx.tcx, space, index, token::intern(name[])) @@ -780,19 +760,6 @@ fn escaping() { assert!(!ty::type_has_escaping_regions(t_param)); let t_fn = env.t_fn(&[t_param], env.t_nil()); assert!(!ty::type_has_escaping_regions(t_fn)); - - // t_fn = |&int|+'a - let t_fn = env.t_closure(&[t_rptr_bound1], env.t_nil(), env.re_free(0, 1)); - assert!(!ty::type_has_escaping_regions(t_fn)); - - // t_fn = |&int|+'a (where &int has depth 2) - let t_fn = env.t_closure(&[t_rptr_bound2], env.t_nil(), env.re_free(0, 1)); - assert!(ty::type_has_escaping_regions(t_fn)); - - // t_fn = |&int|+&int - let t_fn = env.t_closure(&[t_rptr_bound1], env.t_nil(), - env.re_late_bound_with_debruijn(1, ty::DebruijnIndex::new(1))); - assert!(ty::type_has_escaping_regions(t_fn)); }) } diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index cb0d2f3edd4d6..a8363699db8e3 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -530,7 +530,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( // of the closure expression. let typer = NormalizingUnboxedClosureTyper::new(bcx.tcx()); let function_type = typer.unboxed_closure_type(closure_id, bcx.fcx.param_substs); - let function_type = ty::mk_closure(bcx.tcx(), function_type); let freevars: Vec = ty::with_freevars(bcx.tcx(), id, |fv| fv.iter().map(|&fv| fv).collect()); @@ -543,8 +542,8 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( bcx.fcx.param_substs, id, &[], - ty::ty_fn_ret(function_type), - ty::ty_fn_abi(function_type), + function_type.sig.0.output, + function_type.abi, ClosureEnv::new(freevars[], UnboxedClosure(freevar_mode))); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 1368b3325a57f..fb15a55d83420 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -316,7 +316,7 @@ fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, abi::Rust, expected_sig); let fn_sig = fn_ty.sig.clone(); - let fty = ty::mk_closure(tcx, fn_ty); + let fty = panic!("stub"); debug!("check_expr_fn fty={}", fcx.infcx().ty_to_string(fty)); fcx.write_ty(expr.id, fty); From 865aabb6622c44ab47c616c244642a85ce0c4719 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 19:27:20 -0500 Subject: [PATCH 17/37] trans: remove Closure --- src/librustc_trans/trans/callee.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 8048d0218df2d..11f52ad62202e 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -66,8 +66,6 @@ pub struct MethodData { } pub enum CalleeData<'tcx> { - Closure(Datum<'tcx, Lvalue>), - // Constructor for enum variant/tuple-like-struct // i.e. Some, Ok NamedTupleConstructor(subst::Substs<'tcx>, ty::Disr), @@ -681,16 +679,6 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, TraitItem(d) => { (d.llfn, None, Some(d.llself)) } - Closure(d) => { - // Closures are represented as (llfn, llclosure) pair: - // load the requisite values out. - let pair = d.to_llref(); - let llfn = GEPi(bcx, pair, &[0u, abi::FAT_PTR_ADDR]); - let llfn = Load(bcx, llfn); - let llenv = GEPi(bcx, pair, &[0u, abi::FAT_PTR_EXTRA]); - let llenv = Load(bcx, llenv); - (llfn, Some(llenv), None) - } Intrinsic(node, substs) => { assert!(abi == synabi::RustIntrinsic); assert!(dest.is_some()); From 58b0d7479fb478d9c8293e78adaa86a8971442d5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 1 Jan 2015 17:21:25 -0500 Subject: [PATCH 18/37] syntax: make the closure type `f: |uint| -> bool` syntax obsolete --- src/libsyntax/parse/obsolete.rs | 5 +++++ src/libsyntax/parse/parser.rs | 29 +++++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index e1e456f880ed7..75b2c17b81bd4 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -34,6 +34,7 @@ pub enum ObsoleteSyntax { ObsoleteExternCrateRenaming, ObsoleteProcType, ObsoleteProcExpr, + ObsoleteClosureType, } pub trait ParserObsoleteMethods { @@ -94,6 +95,10 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> { ObsoleteExternCrateRenaming => ( "`extern crate foo = bar` syntax", "write `extern crate bar as foo` instead" + ), + ObsoleteClosureType => ( + "`|uint| -> bool` closure type syntax", + "use unboxed closures instead, no type annotation needed" ) }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9bc91a95841a5..678a3c574f5b8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1227,32 +1227,29 @@ impl<'a> Parser<'a> { */ - let unsafety = self.parse_unsafety(); + let ty_closure_span = self.last_span; - let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs); + // To be helpful, parse the closure type as ever + let _ = self.parse_unsafety(); - let inputs = if self.eat(&token::OrOr) { - Vec::new() - } else { + let _ = self.parse_legacy_lifetime_defs(lifetime_defs); + + if !self.eat(&token::OrOr) { self.expect_or(); - let inputs = self.parse_seq_to_before_or( + let _ = self.parse_seq_to_before_or( &token::Comma, |p| p.parse_arg_general(false)); self.expect_or(); - inputs - }; + } - let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare); + let _ = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare); - let output = self.parse_ret_ty(); - let decl = P(FnDecl { - inputs: inputs, - output: output, - variadic: false - }); + let _ = self.parse_ret_ty(); - panic!("stub"); + self.obsolete(ty_closure_span, ObsoleteClosureType); + + TyInfer } pub fn parse_unsafety(&mut self) -> Unsafety { From f258ee7d96577a2b54c94ff26d15fa3b703e8462 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 10:39:03 -0500 Subject: [PATCH 19/37] typeck: there are only unboxed closures now --- src/librustc_typeck/check/closure.rs | 123 +++------------------------ 1 file changed, 11 insertions(+), 112 deletions(-) diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index fb15a55d83420..a1756dd6334df 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -46,30 +46,17 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, // evidence than an unboxed closure is desired, we'll use // that, otherwise we'll fall back to boxed closures. match expected_sig_and_kind { - None => { // doesn't look like an unboxed closure - let region = astconv::opt_ast_region_to_region(fcx, - fcx, - expr.span, - &None); - - check_boxed_closure(fcx, - expr, - ty::RegionTraitStore(region, ast::MutMutable), - decl, - body, - expected); - - match capture { - CaptureByValue => { - fcx.ccx.tcx.sess.span_err( - expr.span, - "boxed closures can't capture by value, \ - if you want to use an unboxed closure, \ - explicitly annotate its kind: e.g. `move |:|`"); - }, - CaptureByRef => {} - } - } + None => { // don't have information about the kind, request explicit annotation + // HACK We still need to typeck the body, so assume `FnMut` kind just for that + let kind = ty::FnMutUnboxedClosureKind; + + check_unboxed_closure(fcx, expr, kind, decl, body, None); + + fcx.ccx.tcx.sess.span_err( + expr.span, + "Can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \ + `|&:| {}`"); + }, Some((sig, kind)) => { check_unboxed_closure(fcx, expr, kind, decl, body, Some(sig)); } @@ -254,91 +241,3 @@ fn deduce_unboxed_closure_expectations_from_obligations<'a,'tcx>( None } - - -fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, - expr: &ast::Expr, - store: ty::TraitStore, - decl: &ast::FnDecl, - body: &ast::Block, - expected: Expectation<'tcx>) { - let tcx = fcx.ccx.tcx; - - // Find the expected input/output types (if any). Substitute - // fresh bound regions for any bound regions we find in the - // expected types so as to avoid capture. - let expected_cenv = expected.map_to_option(fcx, |ty| match ty.sty { - _ => None - }); - let (expected_sig, expected_onceness, expected_bounds) = match expected_cenv { - Some(cenv) => { - let (sig, _) = - ty::replace_late_bound_regions( - tcx, - &cenv.sig, - |_, debruijn| fcx.inh.infcx.fresh_bound_region(debruijn)); - let onceness = match (&store, &cenv.store) { - // As the closure type and onceness go, only three - // combinations are legit: - // once closure - // many closure - // once proc - // If the actual and expected closure type disagree with - // each other, set expected onceness to be always Once or - // Many according to the actual type. Otherwise, it will - // yield either an illegal "many proc" or a less known - // "once closure" in the error message. - (&ty::UniqTraitStore, &ty::UniqTraitStore) | - (&ty::RegionTraitStore(..), &ty::RegionTraitStore(..)) => - cenv.onceness, - (&ty::UniqTraitStore, _) => ast::Once, - (&ty::RegionTraitStore(..), _) => ast::Many, - }; - (Some(sig), onceness, cenv.bounds.clone()) - } - _ => { - // Not an error! Means we're inferring the closure type - let region = fcx.infcx().next_region_var( - infer::AddrOfRegion(expr.span)); - let bounds = ty::region_existential_bound(region); - let onceness = ast::Many; - (None, onceness, bounds) - } - }; - - // construct the function type - let fn_ty = astconv::ty_of_closure(fcx, - ast::Unsafety::Normal, - expected_onceness, - expected_bounds, - store, - decl, - abi::Rust, - expected_sig); - let fn_sig = fn_ty.sig.clone(); - let fty = panic!("stub"); - debug!("check_expr_fn fty={}", fcx.infcx().ty_to_string(fty)); - - fcx.write_ty(expr.id, fty); - - // If the closure is a stack closure and hasn't had some non-standard - // style inferred for it, then check it under its parent's style. - // Otherwise, use its own - let (inherited_style, inherited_style_id) = match store { - ty::RegionTraitStore(..) => (fcx.ps.borrow().unsafety, - fcx.ps.borrow().def), - ty::UniqTraitStore => (ast::Unsafety::Normal, expr.id) - }; - - let fn_sig = - ty::liberate_late_bound_regions(tcx, CodeExtent::from_node_id(body.id), &fn_sig); - - check_fn(fcx.ccx, - inherited_style, - inherited_style_id, - &fn_sig, - &*decl, - expr.id, - &*body, - fcx.inh); -} From 799332fa3f968544831ed66e4e32bf331beddbc0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 10:42:11 -0500 Subject: [PATCH 20/37] syntax: remove dead code --- src/libsyntax/parse/parser.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 678a3c574f5b8..28c7293fc26a3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -14,7 +14,7 @@ pub use self::PathParsingMode::*; use self::ItemOrViewItem::*; use abi; -use ast::{AssociatedType, BareFnTy, ClosureTy}; +use ast::{AssociatedType, BareFnTy}; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::{ProvidedMethod, Public, Unsafety}; use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue}; @@ -30,7 +30,6 @@ use ast::{ExprLit, ExprLoop, ExprMac, ExprRange}; use ast::{ExprMethodCall, ExprParen, ExprPath}; use ast::{ExprRepeat, ExprRet, ExprStruct, ExprTup, ExprUnary}; use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl}; -use ast::{Many}; use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind}; use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy}; From 5d6a6f59575ab389bb6c2f199e5723923a68ab1d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 10:42:51 -0500 Subject: [PATCH 21/37] rustc: remove dead code --- src/librustc/middle/infer/coercion.rs | 1 - src/librustc/middle/ty.rs | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/src/librustc/middle/infer/coercion.rs b/src/librustc/middle/infer/coercion.rs index 12f34a9ae54e6..65de3a083d2d9 100644 --- a/src/librustc/middle/infer/coercion.rs +++ b/src/librustc/middle/infer/coercion.rs @@ -71,7 +71,6 @@ use middle::ty::{self, Ty}; use util::ppaux; use util::ppaux::Repr; -use syntax::abi; use syntax::ast; // Note: Coerce is not actually a combiner, in that it does not diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 715151434f29d..7cda6c21853a3 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3501,23 +3501,6 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { b | (TC::ReachesBorrowed).when(region != ty::ReStatic) } - fn closure_contents(cty: &ClosureTy) -> TypeContents { - // Closure contents are just like trait contents, but with potentially - // even more stuff. - let st = object_contents(&cty.bounds); - - let st = match cty.store { - UniqTraitStore => { - st.owned_pointer() - } - RegionTraitStore(r, mutbl) => { - st.reference(borrowed_contents(r, mutbl)) - } - }; - - st - } - fn object_contents(bounds: &ExistentialBounds) -> TypeContents { // These are the type contents of the (opaque) interior. We // make no assumptions (other than that it cannot have an From 643826150b502eddcc9b736e4320cb76ccedff8a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 10:50:24 -0500 Subject: [PATCH 22/37] trans: remove dead code --- src/librustc_trans/trans/callee.rs | 4 +- src/librustc_trans/trans/closure.rs | 98 +---------------------------- src/librustc_trans/trans/consts.rs | 2 +- src/librustc_trans/trans/expr.rs | 16 ----- 4 files changed, 4 insertions(+), 116 deletions(-) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 11f52ad62202e..f598083c5e44a 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -19,7 +19,7 @@ pub use self::CalleeData::*; pub use self::CallArgs::*; use arena::TypedArena; -use back::{abi,link}; +use back::link; use session; use llvm::{ValueRef}; use llvm::get_param; @@ -100,7 +100,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) -> Callee<'blk, 'tcx> { - let DatumBlock {mut bcx, datum} = expr::trans(bcx, expr); + let DatumBlock { datum, .. } = expr::trans(bcx, expr); match datum.ty.sty { ty::ty_bare_fn(..) => { let llval = datum.to_llscalarish(bcx); diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index a8363699db8e3..6f2def16e7674 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -19,7 +19,7 @@ use trans::base::*; use trans::build::*; use trans::cleanup::{CleanupMethods, ScopeId}; use trans::common::*; -use trans::datum::{Datum, DatumBlock, Expr, Lvalue, rvalue_scratch_datum}; +use trans::datum::{Datum, Lvalue, rvalue_scratch_datum}; use trans::datum::{Rvalue, ByValue}; use trans::debuginfo; use trans::expr; @@ -29,10 +29,8 @@ use trans::type_::Type; use middle::ty::{self, Ty, UnboxedClosureTyper}; use middle::subst::{Substs}; use session::config::FullDebugInfo; -use util::ppaux::Repr; use util::ppaux::ty_to_string; -use arena::TypedArena; use syntax::ast; use syntax::ast_util; @@ -581,97 +579,3 @@ pub fn trans_unboxed_closure<'blk, 'tcx>( bcx } - -pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, - closure_ty: Ty<'tcx>, - def_id: ast::DefId, - fn_ptr: ValueRef, - is_local: bool) -> ValueRef { - - match ccx.closure_bare_wrapper_cache().borrow().get(&fn_ptr) { - Some(&llval) => return llval, - None => {} - } - - let tcx = ccx.tcx(); - - debug!("get_wrapper_for_bare_fn(closure_ty={})", closure_ty.repr(tcx)); - - let f = match closure_ty.sty { - _ => { - ccx.sess().bug(format!("get_wrapper_for_bare_fn: \ - expected a closure ty, got {}", - closure_ty.repr(tcx))[]); - } - }; - - let name = ty::with_path(tcx, def_id, |path| { - mangle_internal_name_by_path_and_seq(path, "as_closure") - }); - let llfn = if is_local { - decl_internal_rust_fn(ccx, closure_ty, name[]) - } else { - decl_rust_fn(ccx, closure_ty, name[]) - }; - - ccx.closure_bare_wrapper_cache().borrow_mut().insert(fn_ptr, llfn); - - // This is only used by statics inlined from a different crate. - if !is_local { - // Don't regenerate the wrapper, just reuse the original one. - return llfn; - } - - let _icx = push_ctxt("closure::get_wrapper_for_bare_fn"); - - let arena = TypedArena::new(); - let empty_param_substs = Substs::trans_empty(); - let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.0.output, - &empty_param_substs, None, &arena); - let bcx = init_function(&fcx, true, f.sig.0.output); - - let args = create_datums_for_fn_args(&fcx, - ty::ty_fn_args(closure_ty) - []); - let mut llargs = Vec::new(); - match fcx.llretslotptr.get() { - Some(llretptr) => { - assert!(!fcx.needs_ret_allocas); - llargs.push(llretptr); - } - None => {} - } - llargs.extend(args.iter().map(|arg| arg.val)); - - let retval = Call(bcx, fn_ptr, llargs.as_slice(), None); - match f.sig.0.output { - ty::FnConverging(output_type) => { - if return_type_is_void(ccx, output_type) || fcx.llretslotptr.get().is_some() { - RetVoid(bcx); - } else { - Ret(bcx, retval); - } - } - ty::FnDiverging => { - RetVoid(bcx); - } - } - - // HACK(eddyb) finish_fn cannot be used here, we returned directly. - debuginfo::clear_source_location(&fcx); - fcx.cleanup(); - - llfn -} - -pub fn make_closure_from_bare_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - closure_ty: Ty<'tcx>, - def_id: ast::DefId, - fn_ptr: ValueRef) - -> DatumBlock<'blk, 'tcx, Expr> { - let scratch = rvalue_scratch_datum(bcx, closure_ty, "__adjust"); - let wrapper = get_wrapper_for_bare_fn(bcx.ccx(), closure_ty, def_id, fn_ptr, true); - fill_fn_pair(bcx, scratch.val, wrapper, C_null(Type::i8p(bcx.ccx()))); - - DatumBlock::new(bcx, scratch.to_expr_datum()) -} diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 2738f1bca6e1e..7e47c8f3b959a 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -15,7 +15,7 @@ use llvm::{ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, Tru use llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE, RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE}; use middle::{const_eval, def}; -use trans::{adt, closure, consts, debuginfo, expr, inline, machine}; +use trans::{adt, consts, debuginfo, expr, inline, machine}; use trans::base::{self, push_ctxt}; use trans::common::*; use trans::type_::Type; diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 1bf96b7d180e2..9221ae09df98a 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -473,22 +473,6 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, DatumBlock::new(bcx, scratch.to_expr_datum()) } - - fn add_env<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - def_id: ast::DefId, - expr: &ast::Expr, - datum: Datum<'tcx, Expr>) - -> DatumBlock<'blk, 'tcx, Expr> { - // This is not the most efficient thing possible; since closures - // are two words it'd be better if this were compiled in - // 'dest' mode, but I can't find a nice way to structure the - // code and keep it DRY that accommodates that use case at the - // moment. - - let closure_ty = expr_ty_adjusted(bcx, expr); - let fn_ptr = datum.to_llscalarish(bcx); - closure::make_closure_from_bare_fn(bcx, closure_ty, def_id, fn_ptr) - } } /// Translates an expression in "lvalue" mode -- meaning that it returns a reference to the memory From 8d0d7521d65eff290183e9d19858c6ca8779fe01 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 10:53:03 -0500 Subject: [PATCH 23/37] typeck: remove dead code --- src/librustc_typeck/check/closure.rs | 4 +--- src/librustc_typeck/check/regionck.rs | 6 ++---- src/librustc_typeck/check/regionmanip.rs | 16 ---------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index a1756dd6334df..7671ad36971ac 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -13,20 +13,18 @@ use super::{check_fn, Expectation, FnCtxt}; use astconv; -use middle::infer; use middle::region::CodeExtent; use middle::subst; use middle::ty::{self, ToPolyTraitRef, Ty}; use rscope::RegionScope; use syntax::abi; use syntax::ast; -use syntax::ast::CaptureClause::*; use syntax::ast_util; use util::ppaux::Repr; pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, expr: &ast::Expr, - capture: ast::CaptureClause, + _capture: ast::CaptureClause, opt_kind: Option, decl: &ast::FnDecl, body: &ast::Block, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 2adbd1f0a3f7f..5a8263263808e 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -856,10 +856,8 @@ fn check_expr_fn_block(rcx: &mut Rcx, fn constrain_callee(rcx: &mut Rcx, callee_id: ast::NodeId, - call_expr: &ast::Expr, - callee_expr: &ast::Expr) { - let call_region = ty::ReScope(CodeExtent::from_node_id(call_expr.id)); - + _call_expr: &ast::Expr, + _callee_expr: &ast::Expr) { let callee_ty = rcx.resolve_node_type(callee_id); match callee_ty.sty { ty::ty_bare_fn(..) => { } diff --git a/src/librustc_typeck/check/regionmanip.rs b/src/librustc_typeck/check/regionmanip.rs index e73fa195b0448..7a9961e750c21 100644 --- a/src/librustc_typeck/check/regionmanip.rs +++ b/src/librustc_typeck/check/regionmanip.rs @@ -319,22 +319,6 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } } - fn accumulate_from_closure_ty(&mut self, - ty: Ty<'tcx>, - c: &ty::ClosureTy<'tcx>) - { - match c.store { - ty::RegionTraitStore(r_b, _) => { - self.push_region_constraint_from_top(r_b); - } - ty::UniqTraitStore => { } - } - - let required_region_bounds = - ty::object_region_bounds(self.tcx, None, c.bounds.builtin_bounds); - self.accumulate_from_object_ty(ty, c.bounds.region_bound, required_region_bounds); - } - fn accumulate_from_object_ty(&mut self, ty: Ty<'tcx>, region_bound: ty::Region, From ca17d0812686012307e364a4dce7b84af6886f91 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 2 Jan 2015 17:32:54 -0500 Subject: [PATCH 24/37] fix rpass tests --- src/test/auxiliary/cci_impl_lib.rs | 4 +- src/test/auxiliary/cci_iter_lib.rs | 2 +- src/test/auxiliary/cci_no_inline_lib.rs | 2 +- src/test/auxiliary/iss.rs | 8 +- src/test/auxiliary/issue13507.rs | 4 - src/test/auxiliary/logging_right_crate.rs | 2 +- src/test/run-pass/argument-passing.rs | 2 +- src/test/run-pass/autobind.rs | 4 +- src/test/run-pass/block-arg-call-as.rs | 2 +- src/test/run-pass/block-explicit-types.rs | 2 +- src/test/run-pass/block-fn-coerce.rs | 5 +- src/test/run-pass/block-iter-1.rs | 2 +- src/test/run-pass/block-iter-2.rs | 2 +- .../borrowck-borrow-from-expr-block.rs | 2 +- .../run-pass/borrowck-closures-two-imm.rs | 14 ++-- src/test/run-pass/borrowck-mut-uniq.rs | 2 +- .../call-closure-from-overloaded-op.rs | 1 + .../capture-clauses-boxed-closures.rs | 2 +- src/test/run-pass/closure-inference.rs | 4 +- src/test/run-pass/closure-inference2.rs | 2 +- src/test/run-pass/closure-reform.rs | 25 +----- src/test/run-pass/closure-return-bang.rs | 20 ----- src/test/run-pass/closure-syntax.rs | 79 ------------------- .../run-pass/coerce-to-closure-and-proc.rs | 37 --------- src/test/run-pass/const-fn-val.rs | 4 +- src/test/run-pass/const-vec-of-fns.rs | 4 +- src/test/run-pass/empty-tag.rs | 2 +- src/test/run-pass/enum-null-pointer-opt.rs | 3 - src/test/run-pass/expr-block-fn.rs | 3 +- .../run-pass/expr-block-generic-unique1.rs | 9 +-- .../run-pass/expr-block-generic-unique2.rs | 9 +-- src/test/run-pass/expr-block-generic.rs | 13 +-- src/test/run-pass/expr-if-generic.rs | 15 ++-- .../run-pass/expr-match-generic-unique1.rs | 9 +-- .../run-pass/expr-match-generic-unique2.rs | 9 +-- src/test/run-pass/fn-bare-coerce-to-block.rs | 2 +- src/test/run-pass/fn-coerce-field.rs | 6 +- src/test/run-pass/fn-pattern-expected-type.rs | 2 +- src/test/run-pass/fn-type-infer.rs | 2 +- src/test/run-pass/foreach-nested.rs | 2 +- src/test/run-pass/foreach-put-structured.rs | 2 +- .../run-pass/foreach-simple-outer-slot.rs | 2 +- src/test/run-pass/fun-call-variants.rs | 2 +- src/test/run-pass/generic-static-methods.rs | 4 +- src/test/run-pass/hashmap-memory.rs | 10 ++- .../hrtb-debruijn-object-types-in-closures.rs | 3 +- src/test/run-pass/hrtb-parse.rs | 3 - .../hrtb-trait-object-passed-to-closure.rs | 2 +- src/test/run-pass/issue-13434.rs | 4 +- src/test/run-pass/issue-13507-2.rs | 1 - src/test/run-pass/issue-13808.rs | 6 +- src/test/run-pass/issue-1460.rs | 2 +- src/test/run-pass/issue-14919.rs | 8 +- src/test/run-pass/issue-1516.rs | 13 --- src/test/run-pass/issue-16256.rs | 2 +- src/test/run-pass/issue-2074.rs | 4 +- src/test/run-pass/issue-2487-a.rs | 2 +- src/test/run-pass/issue-3052.rs | 4 +- src/test/run-pass/issue-3429.rs | 4 +- src/test/run-pass/issue-3874.rs | 2 +- src/test/run-pass/issue-3904.rs | 10 +-- src/test/run-pass/issue-5239-2.rs | 2 +- src/test/run-pass/issue-6153.rs | 2 +- src/test/run-pass/issue-6157.rs | 6 +- src/test/run-pass/issue-868.rs | 4 +- src/test/run-pass/issue-9129.rs | 2 +- src/test/run-pass/iter-range.rs | 2 +- src/test/run-pass/lambda-infer-unresolved.rs | 2 +- src/test/run-pass/last-use-in-block.rs | 6 +- src/test/run-pass/last-use-in-cap-clause.rs | 9 ++- src/test/run-pass/last-use-is-capture.rs | 2 +- src/test/run-pass/match-phi.rs | 2 +- src/test/run-pass/monad.rs | 8 +- src/test/run-pass/move-nullary-fn.rs | 4 +- src/test/run-pass/mut-function-arguments.rs | 2 +- src/test/run-pass/mut-in-ident-patterns.rs | 2 +- src/test/run-pass/newlambdas.rs | 4 +- src/test/run-pass/non-legacy-modes.rs | 2 +- src/test/run-pass/pattern-in-closure.rs | 4 +- src/test/run-pass/purity-infer.rs | 2 +- src/test/run-pass/regions-copy-closure.rs | 12 +-- src/test/run-pass/regions-dependent-autofn.rs | 4 +- src/test/run-pass/regions-fn-subtyping-2.rs | 4 +- src/test/run-pass/regions-fn-subtyping.rs | 8 +- src/test/run-pass/regions-infer-call-2.rs | 2 +- .../regions-lifetime-nonfree-late-bound.rs | 8 +- src/test/run-pass/regions-link-fn-args.rs | 2 +- src/test/run-pass/regions-params.rs | 2 +- src/test/run-pass/regions-static-closure.rs | 12 +-- src/test/run-pass/return-from-closure.rs | 2 +- src/test/run-pass/sendfn-is-a-block.rs | 2 +- src/test/run-pass/static-impl.rs | 14 ++-- src/test/run-pass/struct-partial-move-1.rs | 2 +- src/test/run-pass/struct-partial-move-2.rs | 2 +- src/test/run-pass/tempfile.rs | 2 +- src/test/run-pass/trait-bounds-in-arc.rs | 14 ++-- src/test/run-pass/trait-generic.rs | 4 +- src/test/run-pass/type-id-higher-rank.rs | 18 ----- src/test/run-pass/type-params-in-for-each.rs | 2 +- src/test/run-pass/unnamed_argument_mode.rs | 2 +- src/test/run-pass/unused-move-capture.rs | 2 +- src/test/run-pass/variadic-ffi.rs | 2 +- src/test/run-pass/vec-matching-fold.rs | 22 ++++-- src/test/run-pass/weird-exprs.rs | 2 +- 104 files changed, 212 insertions(+), 414 deletions(-) delete mode 100644 src/test/run-pass/closure-return-bang.rs delete mode 100644 src/test/run-pass/closure-syntax.rs delete mode 100644 src/test/run-pass/coerce-to-closure-and-proc.rs delete mode 100644 src/test/run-pass/issue-1516.rs diff --git a/src/test/auxiliary/cci_impl_lib.rs b/src/test/auxiliary/cci_impl_lib.rs index 40a9a52061fe5..3b1857f9ccb69 100644 --- a/src/test/auxiliary/cci_impl_lib.rs +++ b/src/test/auxiliary/cci_impl_lib.rs @@ -11,12 +11,12 @@ #![crate_name="cci_impl_lib"] pub trait uint_helpers { - fn to(&self, v: uint, f: |uint|); + fn to(&self, v: uint, f: F) where F: FnMut(uint); } impl uint_helpers for uint { #[inline] - fn to(&self, v: uint, f: |uint|) { + fn to(&self, v: uint, mut f: F) where F: FnMut(uint) { let mut i = *self; while i < v { f(i); diff --git a/src/test/auxiliary/cci_iter_lib.rs b/src/test/auxiliary/cci_iter_lib.rs index 84ade3572f95c..3ba068df058b3 100644 --- a/src/test/auxiliary/cci_iter_lib.rs +++ b/src/test/auxiliary/cci_iter_lib.rs @@ -11,7 +11,7 @@ #![crate_name="cci_iter_lib"] #[inline] -pub fn iter(v: &[T], f: |&T|) { +pub fn iter(v: &[T], mut f: F) where F: FnMut(&T) { let mut i = 0u; let n = v.len(); while i < n { diff --git a/src/test/auxiliary/cci_no_inline_lib.rs b/src/test/auxiliary/cci_no_inline_lib.rs index 67f55cca1e16b..474925d8838b5 100644 --- a/src/test/auxiliary/cci_no_inline_lib.rs +++ b/src/test/auxiliary/cci_no_inline_lib.rs @@ -12,7 +12,7 @@ // same as cci_iter_lib, more-or-less, but not marked inline -pub fn iter(v: Vec , f: |uint|) { +pub fn iter(v: Vec , mut f: F) where F: FnMut(uint) { let mut i = 0u; let n = v.len(); while i < n { diff --git a/src/test/auxiliary/iss.rs b/src/test/auxiliary/iss.rs index 37edcdf762898..690d5783c4bc2 100644 --- a/src/test/auxiliary/iss.rs +++ b/src/test/auxiliary/iss.rs @@ -12,12 +12,12 @@ // part of issue-6919.rs -pub struct C<'a> { - pub k: ||: 'a, +pub struct C where K: FnOnce() { + pub k: K, } fn no_op() { } -pub const D : C<'static> = C { - k: no_op +pub const D : C = C { + k: no_op as fn() }; diff --git a/src/test/auxiliary/issue13507.rs b/src/test/auxiliary/issue13507.rs index 961dad000914a..c2820a8d4ae5d 100644 --- a/src/test/auxiliary/issue13507.rs +++ b/src/test/auxiliary/issue13507.rs @@ -21,7 +21,6 @@ pub mod testtypes { ids.push(TypeId::of::()); ids.push(TypeId::of::()); ids.push(TypeId::of::()); - ids.push(TypeId::of::()); ids.push(TypeId::of::<&'static FooTrait>()); ids.push(TypeId::of::()); ids.push(TypeId::of::()); @@ -68,9 +67,6 @@ pub mod testtypes { // Skipping ty_bare_fn (how do you get a bare function type, rather than proc or closure?) - // Tests ty_closure (does not test all types of closures) - pub type FooClosure = |arg: u8|: 'static -> u8; - // Tests ty_trait pub trait FooTrait { fn foo_method(&self) -> uint; diff --git a/src/test/auxiliary/logging_right_crate.rs b/src/test/auxiliary/logging_right_crate.rs index fad70a917980d..399dfb9fa9a5b 100644 --- a/src/test/auxiliary/logging_right_crate.rs +++ b/src/test/auxiliary/logging_right_crate.rs @@ -13,5 +13,5 @@ pub fn foo() { fn death() -> int { panic!() } - debug!("{}", (||{ death() })()); + debug!("{}", (|&:|{ death() })()); } diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index 75e197923c635..dfce311529028 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -20,7 +20,7 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int { return r; } -fn f2(a: int, f: |int|) -> int { f(1); return a; } +fn f2(a: int, f: F) -> int where F: FnOnce(int) { f(1); return a; } pub fn main() { let mut a = X {x: 1}; diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs index f5766ae1e53c2..ed471ed0079e3 100644 --- a/src/test/run-pass/autobind.rs +++ b/src/test/run-pass/autobind.rs @@ -11,11 +11,11 @@ fn f(x: Vec) -> T { return x.into_iter().next().unwrap(); } -fn g(act: |Vec | -> int) -> int { return act(vec!(1, 2, 3)); } +fn g(act: F) -> int where F: FnOnce(Vec) -> int { return act(vec!(1, 2, 3)); } pub fn main() { assert_eq!(g(f), 1); - let f1: |Vec| -> String = f; + let f1 = f; assert_eq!(f1(vec!["x".to_string(), "y".to_string(), "z".to_string()]), "x".to_string()); } diff --git a/src/test/run-pass/block-arg-call-as.rs b/src/test/run-pass/block-arg-call-as.rs index b4e3662965174..6c54f33fbe6c9 100644 --- a/src/test/run-pass/block-arg-call-as.rs +++ b/src/test/run-pass/block-arg-call-as.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn asBlock(f: || -> uint) -> uint { +fn asBlock(f: F) -> uint where F: FnOnce() -> uint { return f(); } diff --git a/src/test/run-pass/block-explicit-types.rs b/src/test/run-pass/block-explicit-types.rs index 63051d71271dd..54b650d762bf4 100644 --- a/src/test/run-pass/block-explicit-types.rs +++ b/src/test/run-pass/block-explicit-types.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - fn as_buf(s: String, f: |String| -> T) -> T { f(s) } + fn as_buf(s: String, f: F) -> T where F: FnOnce(String) -> T { f(s) } as_buf("foo".to_string(), |foo: String| -> () println!("{}", foo) ); } diff --git a/src/test/run-pass/block-fn-coerce.rs b/src/test/run-pass/block-fn-coerce.rs index bbb30e9578e9e..fe52b1a693cdc 100644 --- a/src/test/run-pass/block-fn-coerce.rs +++ b/src/test/run-pass/block-fn-coerce.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: || -> int) -> int { return f(); } +fn force(f: F) -> int where F: FnOnce() -> int { return f(); } + pub fn main() { fn f() -> int { return 7; } assert_eq!(force(f), 7); - let g = {||force(f)}; + let g = {|&:|force(f)}; assert_eq!(g(), 7); } diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index ce20c3024d6fb..972bde5f29a0d 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn iter_vec(v: Vec , f: |&T|) { for x in v.iter() { f(x); } } +fn iter_vec(v: Vec , mut f: F) where F: FnMut(&T) { for x in v.iter() { f(x); } } pub fn main() { let v = vec!(1i, 2, 3, 4, 5, 6, 7); diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index 7bb9d0ddf99af..1032fb486a1ed 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn iter_vec(v: Vec , f: |&T|) { for x in v.iter() { f(x); } } +fn iter_vec(v: Vec, mut f: F) where F: FnMut(&T) { for x in v.iter() { f(x); } } pub fn main() { let v = vec!(1i, 2, 3, 4, 5); diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index 8c4995e710097..038f9e5c9ab43 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn borrow(x: &int, f: |x: &int|) { +fn borrow(x: &int, f: F) where F: FnOnce(&int) { f(x) } diff --git a/src/test/run-pass/borrowck-closures-two-imm.rs b/src/test/run-pass/borrowck-closures-two-imm.rs index 3bd12b030411e..33e4294366f07 100644 --- a/src/test/run-pass/borrowck-closures-two-imm.rs +++ b/src/test/run-pass/borrowck-closures-two-imm.rs @@ -15,10 +15,10 @@ // the closures are in scope. Issue #6801. fn a() -> int { - let mut x = 3; + let mut x = 3i; x += 1; - let c1 = || x * 4; - let c2 = || x * 5; + let c1 = |&:| x * 4; + let c2 = |&:| x * 5; c1() * c2() * x } @@ -29,16 +29,16 @@ fn get(x: &int) -> int { fn b() -> int { let mut x = 3; x += 1; - let c1 = || get(&x); - let c2 = || get(&x); + let c1 = |&:| get(&x); + let c2 = |&:| get(&x); c1() * c2() * x } fn c() -> int { let mut x = 3; x += 1; - let c1 = || x * 5; - let c2 = || get(&x); + let c1 = |&:| x * 5; + let c2 = |&:| get(&x); c1() * c2() * x } diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index 176c7277efddc..dac8945b6e828 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -21,7 +21,7 @@ fn add_int(x: &mut Ints, v: int) { swap(&mut values, &mut x.values); } -fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool { +fn iter_ints(x: &Ints, mut f: F) -> bool where F: FnMut(&int) -> bool { let l = x.values.len(); range(0u, l).all(|i| f(&x.values[i])) } diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs index 432d022c69b77..032bb83d3ab50 100644 --- a/src/test/run-pass/call-closure-from-overloaded-op.rs +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) this ICEs fn foo() -> int { 22 } diff --git a/src/test/run-pass/capture-clauses-boxed-closures.rs b/src/test/run-pass/capture-clauses-boxed-closures.rs index d24b9332917bf..6e8ed4fd5a15a 100644 --- a/src/test/run-pass/capture-clauses-boxed-closures.rs +++ b/src/test/run-pass/capture-clauses-boxed-closures.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn each(x: &[T], f: |&T|) { +fn each(x: &[T], mut f: F) where F: FnMut(&T) { for val in x.iter() { f(val) } diff --git a/src/test/run-pass/closure-inference.rs b/src/test/run-pass/closure-inference.rs index 410b741654602..893003dd99722 100644 --- a/src/test/run-pass/closure-inference.rs +++ b/src/test/run-pass/closure-inference.rs @@ -11,9 +11,9 @@ fn foo(i: int) -> int { i + 1 } -fn apply(f: |A| -> A, v: A) -> A { f(v) } +fn apply(f: F, v: A) -> A where F: FnOnce(A) -> A { f(v) } pub fn main() { - let f = {|i| foo(i)}; + let f = {|: i| foo(i)}; assert_eq!(apply(f, 2), 3); } diff --git a/src/test/run-pass/closure-inference2.rs b/src/test/run-pass/closure-inference2.rs index 6666b8e3cfad5..03b10b881f7ae 100644 --- a/src/test/run-pass/closure-inference2.rs +++ b/src/test/run-pass/closure-inference2.rs @@ -11,7 +11,7 @@ // Test a rather underspecified example: pub fn main() { - let f = {|i| i}; + let f = {|&: i| i}; assert_eq!(f(2i), 2i); assert_eq!(f(5i), 5i); } diff --git a/src/test/run-pass/closure-reform.rs b/src/test/run-pass/closure-reform.rs index 03d9511b41c78..a2e7d7bd7e3e3 100644 --- a/src/test/run-pass/closure-reform.rs +++ b/src/test/run-pass/closure-reform.rs @@ -22,25 +22,14 @@ fn call_it(f: F) println!("{}", f("Fred".to_string())) } -fn call_a_thunk(f: ||) { +fn call_a_thunk(f: F) where F: FnOnce() { f(); } -fn call_this(f: |&str|:Send) { +fn call_this(f: F) where F: FnOnce(&str) + Send { f("Hello!"); } -fn call_that(f: <'a>|&'a int, &'a int| -> int) { - let (ten, forty_two) = (10, 42); - println!("Your lucky number is {}", f(&ten, &forty_two)); -} - -fn call_cramped(f:||->uint,g:<'a>||->&'a uint) { - let number = f(); - let other_number = *g(); - println!("Ticket {} wins an all-expenses-paid trip to Mountain View", number + other_number); -} - fn call_bare(f: fn(&str)) { f("Hello world!") } @@ -71,16 +60,6 @@ pub fn main() { call_this(|s| println!("{}", s)); - call_that(|x, y| *x + *y); - - let z = 100; - call_that(|x, y| *x + *y - z); - - call_cramped(|| 1, || unsafe { - static a: uint = 100; - mem::transmute(&a) - }); - // External functions call_bare(println); diff --git a/src/test/run-pass/closure-return-bang.rs b/src/test/run-pass/closure-return-bang.rs deleted file mode 100644 index 9b4033ae0d722..0000000000000 --- a/src/test/run-pass/closure-return-bang.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 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. - -#![allow(dead_code)] - -fn f(x: || -> !) -> ! { - x(); -} - -fn main() { - let x: || -> ! = || panic!(); - let _y: || -> ! = || x(); -} diff --git a/src/test/run-pass/closure-syntax.rs b/src/test/run-pass/closure-syntax.rs deleted file mode 100644 index 4caa234ac7ae3..0000000000000 --- a/src/test/run-pass/closure-syntax.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 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. - -#![allow(dead_code)] -#![feature(unboxed_closures)] - -// compile-flags:-g - -fn foo() {} - -trait Bar3 {} -impl<'b> Bar3 for <'a>|&'a int|: 'b + Send -> &'a int {} - -struct Foo<'a> { - a: ||: 'a, - b: ||: 'static, - c: <'b>||: 'a, - d: ||: 'a + Sync, - e: <'b>|int|: 'a + Sync -> &'b f32, -} - -fn f<'a>(a: &'a int, f: <'b>|&'b int| -> &'b int) -> &'a int { - f(a) -} - -fn g<'a>(a: &'a int) -> &'a int { - a -} - -struct A; - -impl A { - fn foo(&self) {} -} - -fn bar<'b>() { - foo::<||>(); - foo::<|| -> ()>(); - foo::<||:>(); - foo::<||:'b>(); - foo::<||:'b + Sync>(); - foo::<||:Sync>(); - foo::< <'a>|int, f32, &'a int|:'b + Sync -> &'a int>(); - - foo::<<'a>||>(); - - // issue #11209 - let _: ||: 'b; // for comparison - let _: <'a> ||; - - let _: Option<||:'b>; - let _: Option<<'a>||>; - let _: Option< <'a>||>; - - // issue #11210 - let _: ||: 'static; - - let a = A; - a.foo::<<'a>||>(); - - // issue #13490 - let _ = || -> ! loop {}; - - // issue #17021 - let c = box |&:| {}; -} - -struct B; -impl<'b> B<<'a>||: 'b> {} - -pub fn main() { -} diff --git a/src/test/run-pass/coerce-to-closure-and-proc.rs b/src/test/run-pass/coerce-to-closure-and-proc.rs deleted file mode 100644 index 413717d9226ba..0000000000000 --- a/src/test/run-pass/coerce-to-closure-and-proc.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 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. - -#![feature(unboxed_closures)] - -fn id(x: T) -> T { - x -} - -#[derive(PartialEq, Show)] -struct Foo(T); - -#[derive(PartialEq, Show)] -enum Bar { - Baz(T) -} - -pub fn main() { - let f: |int| -> int = id; - assert_eq!(f(5), 5); - - let f: |int| -> Foo = Foo; - assert_eq!(f(5), Foo(5)); - - let f: |int| -> Bar = Bar::Baz; - assert_eq!(f(5), Bar::Baz(5)); - - let f: |int| -> Option = Some; - assert_eq!(f(5), Some(5)); -} diff --git a/src/test/run-pass/const-fn-val.rs b/src/test/run-pass/const-fn-val.rs index 57e37aaf393bc..8394c53cba5cb 100644 --- a/src/test/run-pass/const-fn-val.rs +++ b/src/test/run-pass/const-fn-val.rs @@ -12,9 +12,9 @@ fn foo() -> int { return 0xca7f000d; } -struct Bar<'a> { f: ||: 'a -> int } +struct Bar where F: FnMut() -> int { f: F } -static mut b : Bar<'static> = Bar { f: foo }; +static mut b : Bar int> = Bar { f: foo as fn() -> int}; pub fn main() { unsafe { assert_eq!((b.f)(), 0xca7f000d); } diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 86cac14b4439d..f21f7d1903cf3 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -17,8 +17,8 @@ fn f() { } static bare_fns: &'static [fn()] = &[f, f]; -struct S<'a>(||:'a); -static mut closures: &'static mut [S<'static>] = &mut [S(f), S(f)]; +struct S(F); +static mut closures: &'static mut [S] = &mut [S(f as fn()), S(f as fn())]; pub fn main() { unsafe { diff --git a/src/test/run-pass/empty-tag.rs b/src/test/run-pass/empty-tag.rs index 58eb4ce2f7a55..d920174644085 100644 --- a/src/test/run-pass/empty-tag.rs +++ b/src/test/run-pass/empty-tag.rs @@ -25,6 +25,6 @@ fn wrapper3(i: chan) { } pub fn main() { - let wrapped = {||wrapper3(chan::chan_t)}; + let wrapped = {|&:|wrapper3(chan::chan_t)}; wrapped(); } diff --git a/src/test/run-pass/enum-null-pointer-opt.rs b/src/test/run-pass/enum-null-pointer-opt.rs index 34ff0b3821cc6..797c26556aaa1 100644 --- a/src/test/run-pass/enum-null-pointer-opt.rs +++ b/src/test/run-pass/enum-null-pointer-opt.rs @@ -19,9 +19,6 @@ use std::sync::Arc; trait Trait {} fn main() { - // Closures - || - assert_eq!(size_of::<||>(), size_of::>()); - // Functions assert_eq!(size_of::(), size_of::>()); assert_eq!(size_of::(), size_of::>()); diff --git a/src/test/run-pass/expr-block-fn.rs b/src/test/run-pass/expr-block-fn.rs index 3a6cd61fa0992..ed246e2cb7d7b 100644 --- a/src/test/run-pass/expr-block-fn.rs +++ b/src/test/run-pass/expr-block-fn.rs @@ -11,9 +11,8 @@ fn test_fn() { - type t = ||: 'static -> int; fn ten() -> int { return 10; } - let rs: t = ten; + let rs = ten; assert!((rs() == 10)); } diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index ec5013122acae..5c1039fe43368 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -8,12 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -type compare<'a, T> = |Box, Box|: 'a -> bool; - -fn test_generic(expected: Box, eq: compare) { +fn test_generic(expected: Box, eq: F) where T: Clone, F: FnOnce(Box, Box) -> bool { let actual: Box = { expected.clone() }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_box() { @@ -22,7 +19,7 @@ fn test_box() { println!("{}", *b2); return *b1 == *b2; } - test_generic::(box true, compare_box); + test_generic::(box true, compare_box); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index 48e27dc449cba..3d736cca6d524 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -8,17 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -type compare<'a, T> = |T, T|: 'a -> bool; - -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: F) where T: Clone, F: FnOnce(T, T) -> bool { let actual: T = { expected.clone() }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_vec() { fn compare_vec(v1: Box, v2: Box) -> bool { return v1 == v2; } - test_generic::>(box 1, compare_vec); + test_generic::, _>(box 1, compare_vec); } pub fn main() { test_vec(); } diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index f1363c42961e1..91b847d47cbcc 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -8,19 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - -// Tests for standalone blocks as expressions with dynamic type sizes -type compare<'a, T> = |T, T|: 'a -> bool; - -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: F) where F: FnOnce(T, T) -> bool { let actual: T = { expected.clone() }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_bool() { fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; } - test_generic::(true, compare_bool); + test_generic::(true, compare_bool); } #[derive(Clone)] @@ -33,7 +28,7 @@ fn test_rec() { fn compare_rec(t1: Pair, t2: Pair) -> bool { t1.a == t2.a && t1.b == t2.b } - test_generic::(Pair {a: 1, b: 2}, compare_rec); + test_generic::(Pair {a: 1, b: 2}, compare_rec); } pub fn main() { test_bool(); test_rec(); } diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index d9300d0bc335a..fb2a120e6f4a1 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -8,18 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -// Tests for if as expressions with dynamic type sizes -type compare = |T, T|: 'static -> bool; - -fn test_generic(expected: T, not_expected: T, eq: compare) { +fn test_generic(expected: T, not_expected: T, eq: F) where + T: Clone, + F: FnOnce(T, T) -> bool, +{ let actual: T = if true { expected.clone() } else { not_expected }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_bool() { fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; } - test_generic::(true, false, compare_bool); + test_generic::(true, false, compare_bool); } #[derive(Clone)] @@ -32,7 +31,7 @@ fn test_rec() { fn compare_rec(t1: Pair, t2: Pair) -> bool { t1.a == t2.a && t1.b == t2.b } - test_generic::(Pair{a: 1, b: 2}, Pair{a: 2, b: 3}, compare_rec); + test_generic::(Pair{a: 1, b: 2}, Pair{a: 2, b: 3}, compare_rec); } pub fn main() { test_bool(); test_rec(); } diff --git a/src/test/run-pass/expr-match-generic-unique1.rs b/src/test/run-pass/expr-match-generic-unique1.rs index aed4024b5bc5c..5fc9a502ca8a0 100644 --- a/src/test/run-pass/expr-match-generic-unique1.rs +++ b/src/test/run-pass/expr-match-generic-unique1.rs @@ -8,22 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -type compare = |Box, Box|: 'static -> bool; - -fn test_generic(expected: Box, eq: compare) { +fn test_generic(expected: Box, eq: F) where F: FnOnce(Box, Box) -> bool { let actual: Box = match true { true => { expected.clone() }, _ => panic!("wat") }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_box() { fn compare_box(b1: Box, b2: Box) -> bool { return *b1 == *b2; } - test_generic::(box true, compare_box); + test_generic::(box true, compare_box); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/expr-match-generic-unique2.rs b/src/test/run-pass/expr-match-generic-unique2.rs index 89adef378f1a1..e608f9c46c79c 100644 --- a/src/test/run-pass/expr-match-generic-unique2.rs +++ b/src/test/run-pass/expr-match-generic-unique2.rs @@ -8,20 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -type compare<'a, T> = |T, T|: 'a -> bool; - -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: F) where F: FnOnce(T, T) -> bool { let actual: T = match true { true => expected.clone(), _ => panic!("wat") }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_vec() { fn compare_box(v1: Box, v2: Box) -> bool { return v1 == v2; } - test_generic::>(box 1, compare_box); + test_generic::, _>(box 1, compare_box); } pub fn main() { test_vec(); } diff --git a/src/test/run-pass/fn-bare-coerce-to-block.rs b/src/test/run-pass/fn-bare-coerce-to-block.rs index 1231a49dcd31b..09508b9b13629 100644 --- a/src/test/run-pass/fn-bare-coerce-to-block.rs +++ b/src/test/run-pass/fn-bare-coerce-to-block.rs @@ -10,7 +10,7 @@ fn bare() {} -fn likes_block(f: ||) { f() } +fn likes_block(f: F) where F: FnOnce() { f() } pub fn main() { likes_block(bare); diff --git a/src/test/run-pass/fn-coerce-field.rs b/src/test/run-pass/fn-coerce-field.rs index 6b7490ba67368..bf6926050ba96 100644 --- a/src/test/run-pass/fn-coerce-field.rs +++ b/src/test/run-pass/fn-coerce-field.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct r<'a> { - field: ||: 'a, +struct r where F: FnOnce() { + field: F, } pub fn main() { fn f() {} - let _i: r = r {field: f}; + let _i: r = r {field: f as fn()}; } diff --git a/src/test/run-pass/fn-pattern-expected-type.rs b/src/test/run-pass/fn-pattern-expected-type.rs index fb75abc6ea093..24bf1f94d887b 100644 --- a/src/test/run-pass/fn-pattern-expected-type.rs +++ b/src/test/run-pass/fn-pattern-expected-type.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let f: |(int,int)| = |(x, y)| { + let f = |&: (x, y): (int, int)| { assert_eq!(x, 1); assert_eq!(y, 2); }; diff --git a/src/test/run-pass/fn-type-infer.rs b/src/test/run-pass/fn-type-infer.rs index 80d3527736f40..ae22ff5cce035 100644 --- a/src/test/run-pass/fn-type-infer.rs +++ b/src/test/run-pass/fn-type-infer.rs @@ -12,7 +12,7 @@ pub fn main() { // We should be able to type infer inside of ||s. - let _f = || { + let _f = |&:| { let i = 10i; }; } diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index 2a54f22ee665b..f6466994955e7 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn two(it: |int|) { it(0); it(1); } +fn two(mut it: F) where F: FnMut(int) { it(0); it(1); } pub fn main() { let mut a: Vec = vec!(-1, -1, -1, -1); diff --git a/src/test/run-pass/foreach-put-structured.rs b/src/test/run-pass/foreach-put-structured.rs index 7a728e18a2901..029dddb7a2110 100644 --- a/src/test/run-pass/foreach-put-structured.rs +++ b/src/test/run-pass/foreach-put-structured.rs @@ -10,7 +10,7 @@ -fn pairs(it: |(int, int)|) { +fn pairs(mut it: F) where F: FnMut((int, int)) { let mut i: int = 0; let mut j: int = 0; while i < 10 { it((i, j)); i += 1; j += i; } diff --git a/src/test/run-pass/foreach-simple-outer-slot.rs b/src/test/run-pass/foreach-simple-outer-slot.rs index bb726773bb5db..9ccb2dd56cfdc 100644 --- a/src/test/run-pass/foreach-simple-outer-slot.rs +++ b/src/test/run-pass/foreach-simple-outer-slot.rs @@ -19,7 +19,7 @@ pub fn main() { assert_eq!(sum, 45); } -fn first_ten(it: |int|) { +fn first_ten(mut it: F) where F: FnMut(int) { let mut i: int = 0; while i < 10 { println!("first_ten"); it(i); i = i + 1; } } diff --git a/src/test/run-pass/fun-call-variants.rs b/src/test/run-pass/fun-call-variants.rs index 479f4f8387fb4..3955bedb168ae 100644 --- a/src/test/run-pass/fun-call-variants.rs +++ b/src/test/run-pass/fun-call-variants.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ho(f: |int| -> int) -> int { let n: int = f(3); return n; } +fn ho(f: F) -> int where F: FnOnce(int) -> int { let n: int = f(3); return n; } fn direct(x: int) -> int { return x + 1; } diff --git a/src/test/run-pass/generic-static-methods.rs b/src/test/run-pass/generic-static-methods.rs index 032db16c61714..f992847e4e9f6 100644 --- a/src/test/run-pass/generic-static-methods.rs +++ b/src/test/run-pass/generic-static-methods.rs @@ -10,11 +10,11 @@ trait vec_utils { - fn map_(x: &Self, f: |&T| -> U) -> Vec ; + fn map_(x: &Self, f: F) -> Vec where F: FnMut(&T) -> U; } impl vec_utils for Vec { - fn map_(x: &Vec , f: |&T| -> U) -> Vec { + fn map_(x: &Vec , mut f: F) -> Vec where F: FnMut(&T) -> U { let mut r = Vec::new(); for elt in x.iter() { r.push(f(elt)); diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 7fd8ca1fd8a9e..a8ecc2decd08a 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -9,14 +9,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(unboxed_closures)] + /** A somewhat reduced test case to expose some Valgrind issues. This originally came from the word-count benchmark. */ -pub fn map(filename: String, emit: map_reduce::putter) { - emit(filename, "1".to_string()); +pub fn map(filename: String, mut emit: map_reduce::putter) { + emit.call_mut((filename, "1".to_string(),)); } mod map_reduce { @@ -25,7 +27,7 @@ mod map_reduce { use std::str; use std::thread::Thread; - pub type putter<'a> = |String, String|: 'a; + pub type putter<'a> = Box; pub type mapper = extern fn(String, putter); @@ -58,7 +60,7 @@ mod map_reduce { } let ctrl_clone = ctrl.clone(); - ::map(input, |a,b| emit(&mut intermediates, ctrl.clone(), a, b) ); + ::map(input, box |a,b| emit(&mut intermediates, ctrl.clone(), a, b) ); ctrl_clone.send(ctrl_proto::mapper_done).unwrap(); } diff --git a/src/test/run-pass/hrtb-debruijn-object-types-in-closures.rs b/src/test/run-pass/hrtb-debruijn-object-types-in-closures.rs index 5bdfa3cafd747..9e857a33245d1 100644 --- a/src/test/run-pass/hrtb-debruijn-object-types-in-closures.rs +++ b/src/test/run-pass/hrtb-debruijn-object-types-in-closures.rs @@ -13,8 +13,7 @@ trait Typer<'tcx> { fn dummy(&self) { } } -fn g(_: |&Typer|) { -} +fn g(_: F) where F: FnOnce(&Typer) {} fn h() { g(|typer| typer.dummy()) diff --git a/src/test/run-pass/hrtb-parse.rs b/src/test/run-pass/hrtb-parse.rs index 53749f09f741e..41b7c0fae0746 100644 --- a/src/test/run-pass/hrtb-parse.rs +++ b/src/test/run-pass/hrtb-parse.rs @@ -40,8 +40,5 @@ fn foo21(t: for<'a> unsafe fn(int) -> int) { } fn foo22(t: for<'a> extern "C" fn(int) -> int) { } fn foo23(t: for<'a> unsafe extern "C" fn(int) -> int) { } -fn foo30(t: for<'a> |int| -> int) { } -fn foo31(t: for<'a> unsafe |int| -> int) { } - fn main() { } diff --git a/src/test/run-pass/hrtb-trait-object-passed-to-closure.rs b/src/test/run-pass/hrtb-trait-object-passed-to-closure.rs index 076b9c7684ec4..c90c3643d4e54 100644 --- a/src/test/run-pass/hrtb-trait-object-passed-to-closure.rs +++ b/src/test/run-pass/hrtb-trait-object-passed-to-closure.rs @@ -23,7 +23,7 @@ struct NoAnn<'ast> { impl<'ast> PrinterSupport<'ast> for NoAnn<'ast> { } -fn foo<'ast> (f: Option<&'ast uint>, g: |&PrinterSupport|) { +fn foo<'ast, G>(f: Option<&'ast uint>, g: G) where G: FnOnce(&PrinterSupport) { let annotation = NoAnn { f: f }; g(&annotation) } diff --git a/src/test/run-pass/issue-13434.rs b/src/test/run-pass/issue-13434.rs index e223feede02e6..e5fd17e2dfed0 100644 --- a/src/test/run-pass/issue-13434.rs +++ b/src/test/run-pass/issue-13434.rs @@ -15,7 +15,7 @@ trait Repro { fn repro(self, s: MyStruct) -> String; } -impl Repro for |MyStruct|:'static -> String { +impl Repro for F where F: FnOnce(MyStruct) -> String { fn repro(self, s: MyStruct) -> String { self(s) } @@ -26,5 +26,5 @@ fn do_stuff(r: R) -> String { } pub fn main() { - assert_eq!("MyStruct".to_string(), do_stuff(|s: MyStruct| format!("{}", s))); + assert_eq!("MyStruct".to_string(), do_stuff(|: s: MyStruct| format!("{}", s))); } diff --git a/src/test/run-pass/issue-13507-2.rs b/src/test/run-pass/issue-13507-2.rs index 626381c334dd7..4d150e7a68e7c 100644 --- a/src/test/run-pass/issue-13507-2.rs +++ b/src/test/run-pass/issue-13507-2.rs @@ -24,7 +24,6 @@ pub fn type_ids() -> Vec { ids.push(TypeId::of::()); ids.push(TypeId::of::()); ids.push(TypeId::of::()); - ids.push(TypeId::of::()); ids.push(TypeId::of::<&'static testtypes::FooTrait>()); ids.push(TypeId::of::()); ids.push(TypeId::of::()); diff --git a/src/test/run-pass/issue-13808.rs b/src/test/run-pass/issue-13808.rs index e20090adcf613..c0652b946dbe5 100644 --- a/src/test/run-pass/issue-13808.rs +++ b/src/test/run-pass/issue-13808.rs @@ -9,12 +9,12 @@ // except according to those terms. struct Foo<'a> { - listener: ||: 'a + listener: Box, } impl<'a> Foo<'a> { - fn new(listener: ||: 'a) -> Foo<'a> { - Foo { listener: listener } + fn new(listener: F) -> Foo<'a> where F: FnMut() + 'a { + Foo { listener: box listener } } } diff --git a/src/test/run-pass/issue-1460.rs b/src/test/run-pass/issue-1460.rs index 8176262abd918..2091a5437c2dc 100644 --- a/src/test/run-pass/issue-1460.rs +++ b/src/test/run-pass/issue-1460.rs @@ -10,5 +10,5 @@ pub fn main() { - {|i| if 1i == i { }}; + {|&: i| if 1i == i { }}; } diff --git a/src/test/run-pass/issue-14919.rs b/src/test/run-pass/issue-14919.rs index d66bbe9187a28..d5590e99f2cb9 100644 --- a/src/test/run-pass/issue-14919.rs +++ b/src/test/run-pass/issue-14919.rs @@ -16,7 +16,7 @@ trait Matcher { struct CharPredMatcher<'a, 'b> { str: &'a str, - pred: |char|:'b -> bool + pred: Box bool + 'b>, } impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> { @@ -29,11 +29,11 @@ trait IntoMatcher<'a, T> { fn into_matcher(self, &'a str) -> T; } -impl<'a, 'b> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for |char|:'b -> bool { +impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b { fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> { CharPredMatcher { str: s, - pred: self + pred: box self, } } } @@ -57,6 +57,6 @@ fn match_indices<'a, M, T: IntoMatcher<'a, M>>(s: &'a str, from: T) -> MatchIndi fn main() { let s = "abcbdef"; - match_indices(s, |c: char| c == 'b') + match_indices(s, |&mut: c: char| c == 'b') .collect::>(); } diff --git a/src/test/run-pass/issue-1516.rs b/src/test/run-pass/issue-1516.rs deleted file mode 100644 index 3c5af9ca032c1..0000000000000 --- a/src/test/run-pass/issue-1516.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2012 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. - -pub fn main() { - let early_error: |&str|: 'static -> ! = |_msg| { panic!() }; -} diff --git a/src/test/run-pass/issue-16256.rs b/src/test/run-pass/issue-16256.rs index 48ea3a93296e3..e7422e233a629 100644 --- a/src/test/run-pass/issue-16256.rs +++ b/src/test/run-pass/issue-16256.rs @@ -10,5 +10,5 @@ fn main() { let mut buf = Vec::new(); - |c: u8| buf.push(c); + |&mut: c: u8| buf.push(c); } diff --git a/src/test/run-pass/issue-2074.rs b/src/test/run-pass/issue-2074.rs index ebcaf97c5f7e7..120ada96c15b7 100644 --- a/src/test/run-pass/issue-2074.rs +++ b/src/test/run-pass/issue-2074.rs @@ -11,11 +11,11 @@ #![allow(non_camel_case_types)] pub fn main() { - let one: || -> uint = || { + let one = |&:| { enum r { a }; r::a as uint }; - let two: || -> uint = || { + let two = |&:| { enum r { a }; r::a as uint }; diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index d8c12d8511c32..aa61d52b2a32d 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -29,7 +29,7 @@ fn socket() -> socket { } } -fn closure(f: ||) { f() } +fn closure(f: F) where F: FnOnce() { f() } fn setsockopt_bytes(_sock: int) { } diff --git a/src/test/run-pass/issue-3052.rs b/src/test/run-pass/issue-3052.rs index 00e6b5ca8fedc..72cf2219bb6f0 100644 --- a/src/test/run-pass/issue-3052.rs +++ b/src/test/run-pass/issue-3052.rs @@ -9,10 +9,10 @@ // except according to those terms. -type Connection = |Vec|: 'static; +type Connection = Box) + 'static>; fn f() -> Option { - let mock_connection: Connection = |_| {}; + let mock_connection: Connection = box |&mut: _| {}; Some(mock_connection) } diff --git a/src/test/run-pass/issue-3429.rs b/src/test/run-pass/issue-3429.rs index cce90f8a2cd29..60c5345000436 100644 --- a/src/test/run-pass/issue-3429.rs +++ b/src/test/run-pass/issue-3429.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = 1; - let y: || -> int = || x; + let x = 1u; + let y = |&:| x; let _z = y(); } diff --git a/src/test/run-pass/issue-3874.rs b/src/test/run-pass/issue-3874.rs index c616c09c70e60..9226bebd2dcea 100644 --- a/src/test/run-pass/issue-3874.rs +++ b/src/test/run-pass/issue-3874.rs @@ -10,7 +10,7 @@ enum PureCounter { PureCounterVariant(uint) } -fn each(thing: PureCounter, blk: |v: &uint|) { +fn each(thing: PureCounter, blk: F) where F: FnOnce(&uint) { let PureCounter::PureCounterVariant(ref x) = thing; blk(x); } diff --git a/src/test/run-pass/issue-3904.rs b/src/test/run-pass/issue-3904.rs index 81a7d073c4cda..e917ecc745f0b 100644 --- a/src/test/run-pass/issue-3904.rs +++ b/src/test/run-pass/issue-3904.rs @@ -8,21 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type ErrPrinter<'a> = |&str, &str|: 'a; - fn example_err(prog: &str, arg: &str) { println!("{}: {}", prog, arg) } -fn exit(print: ErrPrinter, prog: &str, arg: &str) { +fn exit(print: F, prog: &str, arg: &str) where F: FnOnce(&str, &str) { print(prog, arg); } -struct X<'a> { - err: ErrPrinter<'a> +struct X where F: FnOnce(&str, &str) { + err: F, } -impl<'a> X<'a> { +impl X where F: FnOnce(&str, &str) { pub fn boom(self) { exit(self.err, "prog", "arg"); } diff --git a/src/test/run-pass/issue-5239-2.rs b/src/test/run-pass/issue-5239-2.rs index 863acc5c0c3c0..69255c576811f 100644 --- a/src/test/run-pass/issue-5239-2.rs +++ b/src/test/run-pass/issue-5239-2.rs @@ -11,7 +11,7 @@ // Regression test for issue #5239 pub fn main() { - let _f: |int| -> int = |ref x: int| { *x }; + let _f = |&: ref x: int| { *x }; let foo = 10; assert!(_f(foo) == 10); } diff --git a/src/test/run-pass/issue-6153.rs b/src/test/run-pass/issue-6153.rs index fa784e17b10f2..b2b64e62c39a4 100644 --- a/src/test/run-pass/issue-6153.rs +++ b/src/test/run-pass/issue-6153.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn swap(f: |Vec | -> Vec ) -> Vec { +fn swap(f: F) -> Vec where F: FnOnce(Vec) -> Vec { let x = vec!(1, 2, 3); f(x) } diff --git a/src/test/run-pass/issue-6157.rs b/src/test/run-pass/issue-6157.rs index 23e700855040c..07c7c6888e1eb 100644 --- a/src/test/run-pass/issue-6157.rs +++ b/src/test/run-pass/issue-6157.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub trait OpInt<'a> { fn call(&mut self, int, int) -> int; } +pub trait OpInt { fn call(&mut self, int, int) -> int; } -impl<'a> OpInt<'a> for |int, int|: 'a -> int { +impl OpInt for F where F: FnMut(int, int) -> int { fn call(&mut self, a:int, b:int) -> int { (*self)(a, b) } @@ -21,7 +21,7 @@ fn squarei<'a>(x: int, op: &'a mut OpInt) -> int { op.call(x, x) } fn muli(x:int, y:int) -> int { x * y } pub fn main() { - let mut f = |x,y| muli(x,y); + let mut f = |&mut: x, y| muli(x, y); { let g = &mut f; let h = g as &mut OpInt; diff --git a/src/test/run-pass/issue-868.rs b/src/test/run-pass/issue-868.rs index 99ab83ec62073..72bdd1af746c1 100644 --- a/src/test/run-pass/issue-868.rs +++ b/src/test/run-pass/issue-868.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(g: || -> T) -> T { g() } +fn f(g: F) -> T where F: FnOnce() -> T { g() } pub fn main() { let _x = f( | | { 10i }); @@ -20,5 +20,5 @@ pub fn main() { let _: () = f(| | { }); // empty block with no type info should compile too let _ = f(||{}); - let _ = (||{}); + let _ = (|&:|{}); } diff --git a/src/test/run-pass/issue-9129.rs b/src/test/run-pass/issue-9129.rs index a6746f452065d..3ca060f45a5f5 100644 --- a/src/test/run-pass/issue-9129.rs +++ b/src/test/run-pass/issue-9129.rs @@ -29,7 +29,7 @@ fn Ident_new() -> Ident { pub fn light_fuse(fld: Box) { int3!(); - let f = || { + let f = |&:| { int3!(); fld.boom(Ident_new()); // *** 1 }; diff --git a/src/test/run-pass/iter-range.rs b/src/test/run-pass/iter-range.rs index 794c4f4016e62..29ac563878bc4 100644 --- a/src/test/run-pass/iter-range.rs +++ b/src/test/run-pass/iter-range.rs @@ -10,7 +10,7 @@ -fn range_(a: int, b: int, it: |int|) { +fn range_(a: int, b: int, mut it: F) where F: FnMut(int) { assert!((a < b)); let mut i: int = a; while i < b { it(i); i += 1; } diff --git a/src/test/run-pass/lambda-infer-unresolved.rs b/src/test/run-pass/lambda-infer-unresolved.rs index 190d25015840c..b33e6512b18bd 100644 --- a/src/test/run-pass/lambda-infer-unresolved.rs +++ b/src/test/run-pass/lambda-infer-unresolved.rs @@ -16,7 +16,7 @@ struct Refs { refs: Vec , n: int } pub fn main() { let mut e = Refs{refs: vec!(), n: 0}; - let _f: || = || println!("{}", e.n); + let _f = |&:| println!("{}", e.n); let x: &[int] = e.refs.as_slice(); assert_eq!(x.len(), 0); } diff --git a/src/test/run-pass/last-use-in-block.rs b/src/test/run-pass/last-use-in-block.rs index c0dcf9e609418..8ef5df5d69697 100644 --- a/src/test/run-pass/last-use-in-block.rs +++ b/src/test/run-pass/last-use-in-block.rs @@ -10,7 +10,7 @@ // Issue #1818 -fn lp(s: String, f: |String| -> T) -> T { +fn lp(s: String, mut f: F) -> T where F: FnMut(String) -> T { while false { let r = f(s); return (r); @@ -18,8 +18,8 @@ fn lp(s: String, f: |String| -> T) -> T { panic!(); } -fn apply(s: String, f: |String| -> T) -> T { - fn g(s: String, f: |String| -> T) -> T {f(s)} +fn apply(s: String, mut f: F) -> T where F: FnMut(String) -> T { + fn g(s: String, mut f: F) -> T where F: FnMut(String) -> T {f(s)} g(s, |v| { let r = f(v); r }) } diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index c9ea520576a75..6615bb6368fd7 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -10,16 +10,17 @@ // Make sure #1399 stays fixed +#![feature(unboxed_closures)] struct A { a: Box } -fn foo() -> ||: 'static -> int { +fn foo() -> Box int + 'static> { let k = box 22i; let _u = A {a: k.clone()}; - let result: ||: 'static -> int = || 22; - result + let result = |&mut:| 22; + box result } pub fn main() { - assert_eq!(foo()(), 22); + assert_eq!(foo().call_mut(()), 22); } diff --git a/src/test/run-pass/last-use-is-capture.rs b/src/test/run-pass/last-use-is-capture.rs index 6d5624e2b5880..206d4db3db4f8 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -13,7 +13,7 @@ struct A { a: Box } pub fn main() { - fn invoke(f: ||) { f(); } + fn invoke(f: F) where F: FnOnce() { f(); } let k = box 22i; let _u = A {a: k.clone()}; invoke(|| println!("{}", k.clone()) ) diff --git a/src/test/run-pass/match-phi.rs b/src/test/run-pass/match-phi.rs index c5f39bc1a5383..2a0a2b208875f 100644 --- a/src/test/run-pass/match-phi.rs +++ b/src/test/run-pass/match-phi.rs @@ -13,7 +13,7 @@ enum thing { a, b, c, } -fn foo(it: |int|) { it(10); } +fn foo(it: F) where F: FnOnce(int) { it(10); } pub fn main() { let mut x = true; diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 4f9e573ccff26..acd8078b1f4d3 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -11,11 +11,11 @@ trait vec_monad { - fn bind(&self, f: |&A| -> Vec ) -> Vec ; + fn bind(&self, f: F ) -> Vec where F: FnMut(&A) -> Vec ; } impl vec_monad for Vec { - fn bind(&self, f: |&A| -> Vec ) -> Vec { + fn bind(&self, mut f: F) -> Vec where F: FnMut(&A) -> Vec { let mut r = Vec::new(); for elt in self.iter() { r.extend(f(elt).into_iter()); @@ -25,11 +25,11 @@ impl vec_monad for Vec { } trait option_monad { - fn bind(&self, f: |&A| -> Option) -> Option; + fn bind(&self, f: F) -> Option where F: FnOnce(&A) -> Option; } impl option_monad for Option { - fn bind(&self, f: |&A| -> Option) -> Option { + fn bind(&self, f: F) -> Option where F: FnOnce(&A) -> Option { match *self { Some(ref a) => { f(a) } None => { None } diff --git a/src/test/run-pass/move-nullary-fn.rs b/src/test/run-pass/move-nullary-fn.rs index 4b613e9beaab2..b7cd3003e750c 100644 --- a/src/test/run-pass/move-nullary-fn.rs +++ b/src/test/run-pass/move-nullary-fn.rs @@ -9,9 +9,9 @@ // except according to those terms. // Issue #922 -fn f2(_thing: ||) { } +fn f2(_thing: F) where F: FnOnce() { } -fn f(thing: ||) { +fn f(thing: F) where F: FnOnce() { f2(thing); } diff --git a/src/test/run-pass/mut-function-arguments.rs b/src/test/run-pass/mut-function-arguments.rs index 39441227f6074..f80728519136e 100644 --- a/src/test/run-pass/mut-function-arguments.rs +++ b/src/test/run-pass/mut-function-arguments.rs @@ -15,7 +15,7 @@ fn f(mut y: Box) { } fn g() { - let frob: |Box| = |mut q| { *q = 2; assert!(*q == 2); }; + let frob = |&: mut q: Box| { *q = 2; assert!(*q == 2); }; let w = box 37; frob(w); diff --git a/src/test/run-pass/mut-in-ident-patterns.rs b/src/test/run-pass/mut-in-ident-patterns.rs index 139122b7b8125..ad9161f9bd487 100644 --- a/src/test/run-pass/mut-in-ident-patterns.rs +++ b/src/test/run-pass/mut-in-ident-patterns.rs @@ -75,6 +75,6 @@ pub fn main() { x = 30; assert_eq!(x, 30); - (|A { x: mut t }: A| { t = t+1; t })(A { x: 34 }); + (|&: A { x: mut t }: A| { t = t+1; t })(A { x: 34 }); } diff --git a/src/test/run-pass/newlambdas.rs b/src/test/run-pass/newlambdas.rs index 043136fdad995..01875288aef0e 100644 --- a/src/test/run-pass/newlambdas.rs +++ b/src/test/run-pass/newlambdas.rs @@ -10,9 +10,9 @@ // Tests for the new |args| expr lambda syntax -fn f(i: int, f: |int| -> int) -> int { f(i) } +fn f(i: int, f: F) -> int where F: FnOnce(int) -> int { f(i) } -fn g(_g: ||) { } +fn g(_g: G) where G: FnOnce() { } pub fn main() { assert_eq!(f(10, |a| a), 10); diff --git a/src/test/run-pass/non-legacy-modes.rs b/src/test/run-pass/non-legacy-modes.rs index 8262432db607f..e422cb803215b 100644 --- a/src/test/run-pass/non-legacy-modes.rs +++ b/src/test/run-pass/non-legacy-modes.rs @@ -12,7 +12,7 @@ struct X { repr: int } -fn apply(x: T, f: |T|) { +fn apply(x: T, f: F) where F: FnOnce(T) { f(x); } diff --git a/src/test/run-pass/pattern-in-closure.rs b/src/test/run-pass/pattern-in-closure.rs index e4f1df2d6376d..c718b948f8dc0 100644 --- a/src/test/run-pass/pattern-in-closure.rs +++ b/src/test/run-pass/pattern-in-closure.rs @@ -14,8 +14,8 @@ struct Foo { } pub fn main() { - let f = |(x, _): (int, int)| println!("{}", x + 1); - let g = |Foo { x: x, y: _y }: Foo| println!("{}", x + 1); + let f = |&: (x, _): (int, int)| println!("{}", x + 1); + let g = |&: Foo { x: x, y: _y }: Foo| println!("{}", x + 1); f((2, 3)); g(Foo { x: 1, y: 2 }); } diff --git a/src/test/run-pass/purity-infer.rs b/src/test/run-pass/purity-infer.rs index 3bceefb831851..c5588a29cb526 100644 --- a/src/test/run-pass/purity-infer.rs +++ b/src/test/run-pass/purity-infer.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn something(f: ||) { f(); } +fn something(f: F) where F: FnOnce() { f(); } pub fn main() { something(|| println!("hi!") ); } diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index b4523ce41ce75..a7724e68310a7 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(unboxed_closures)] + struct closure_box<'a> { - cl: ||: 'a, + cl: Box, } -fn box_it(x: ||) -> closure_box { +fn box_it<'a>(x: Box) -> closure_box<'a> { closure_box {cl: x} } @@ -20,9 +22,9 @@ pub fn main() { let mut i = 3i; assert_eq!(i, 3); { - let cl = || i += 1; - let cl_box = box_it(cl); - (cl_box.cl)(); + let cl = |&mut:| i += 1; + let mut cl_box = box_it(box cl); + cl_box.cl.call_mut(()); } assert_eq!(i, 4); } diff --git a/src/test/run-pass/regions-dependent-autofn.rs b/src/test/run-pass/regions-dependent-autofn.rs index 311fd1bcdf2e0..e7dc5e99c2bb9 100644 --- a/src/test/run-pass/regions-dependent-autofn.rs +++ b/src/test/run-pass/regions-dependent-autofn.rs @@ -11,9 +11,9 @@ // Test lifetimes are linked properly when we autoslice a vector. // Issue #3148. -fn subslice(v: ||) -> || { v } +fn subslice(v: F) -> F where F: FnOnce() { v } -fn both(v: ||) -> || { +fn both(v: F) -> F where F: FnOnce() { subslice(subslice(v)) } diff --git a/src/test/run-pass/regions-fn-subtyping-2.rs b/src/test/run-pass/regions-fn-subtyping-2.rs index 9d2a959eae1c7..70c90ee05b357 100644 --- a/src/test/run-pass/regions-fn-subtyping-2.rs +++ b/src/test/run-pass/regions-fn-subtyping-2.rs @@ -13,13 +13,13 @@ // Here, `f` is a function that takes a pointer `x` and a function // `g`, where `g` requires its argument `y` to be in the same region // that `x` is in. -fn has_same_region(f: <'a>|x: &'a int, g: |y: &'a int||) { +fn has_same_region(f: Box FnMut(&'a int, Box)>) { // `f` should be the type that `wants_same_region` wants, but // right now the compiler complains that it isn't. wants_same_region(f); } -fn wants_same_region(_f: <'b>|x: &'b int, g: |y: &'b int||) { +fn wants_same_region(_f: Box FnMut(&'b int, Box)>) { } pub fn main() { diff --git a/src/test/run-pass/regions-fn-subtyping.rs b/src/test/run-pass/regions-fn-subtyping.rs index 705a0e128522c..e9f774150dcfd 100644 --- a/src/test/run-pass/regions-fn-subtyping.rs +++ b/src/test/run-pass/regions-fn-subtyping.rs @@ -14,21 +14,21 @@ #![allow(unused_variable)] // Should pass region checking. -fn ok(f: |x: &uint|) { +fn ok(f: Box) { // Here, g is a function that can accept a uint pointer with // lifetime r, and f is a function that can accept a uint pointer // with any lifetime. The assignment g = f should be OK (i.e., // f's type should be a subtype of g's type), because f can be // used in any context that expects g's type. But this currently // fails. - let mut g: <'r>|y: &'r uint| = |x| { }; + let mut g: Box FnMut(&'r uint)> = box |x| { }; g = f; } // This version is the same as above, except that here, g's type is // inferred. -fn ok_inferred(f: |x: &uint|) { - let mut g: <'r>|x: &'r uint| = |_| {}; +fn ok_inferred(f: Box) { + let mut g: Box FnMut(&'r uint)> = box |_| {}; g = f; } diff --git a/src/test/run-pass/regions-infer-call-2.rs b/src/test/run-pass/regions-infer-call-2.rs index 3350c3b65d090..cfb6c8585634d 100644 --- a/src/test/run-pass/regions-infer-call-2.rs +++ b/src/test/run-pass/regions-infer-call-2.rs @@ -10,7 +10,7 @@ fn takes_two(x: &int, y: &int) -> int { *x + *y } -fn with(f: |x: &int| -> T) -> T { +fn with(f: F) -> T where F: FnOnce(&int) -> T { f(&20) } diff --git a/src/test/run-pass/regions-lifetime-nonfree-late-bound.rs b/src/test/run-pass/regions-lifetime-nonfree-late-bound.rs index 77ecb077fef16..c796566b79d57 100644 --- a/src/test/run-pass/regions-lifetime-nonfree-late-bound.rs +++ b/src/test/run-pass/regions-lifetime-nonfree-late-bound.rs @@ -24,15 +24,15 @@ pub fn main() { fn explicit() { - fn test(_x: Option<|f: <'a> |g: &'a int||>) {} - test(Some(|_f: <'a> |g: &'a int|| {})); + fn test(_x: Option>) where F: FnMut(Box FnMut(&'a int)>) {} + test(Some(box |&mut: _f: Box FnMut(&'a int)>| {})); } // The code below is shorthand for the code above (and more likely // to represent what one encounters in practice). fn implicit() { - fn test(_x: Option<|f: |g: & int||>) {} - test(Some(|_f: |g: & int|| {})); + fn test(_x: Option>) where F: FnMut(Box< FnMut(& int)>) {} + test(Some(box |&mut: _f: Box< FnMut(& int)>| {})); } explicit(); diff --git a/src/test/run-pass/regions-link-fn-args.rs b/src/test/run-pass/regions-link-fn-args.rs index 2823622bdf6d9..8822d3880397a 100644 --- a/src/test/run-pass/regions-link-fn-args.rs +++ b/src/test/run-pass/regions-link-fn-args.rs @@ -13,7 +13,7 @@ #![allow(dead_code)] -fn with<'a>(_: |&'a Vec| -> &'a Vec) { } +fn with<'a, F>(_: F) where F: FnOnce(&'a Vec) -> &'a Vec { } fn foo() { with(|&ref ints| ints); diff --git a/src/test/run-pass/regions-params.rs b/src/test/run-pass/regions-params.rs index c0e821b8d3854..0042d3a765bfd 100644 --- a/src/test/run-pass/regions-params.rs +++ b/src/test/run-pass/regions-params.rs @@ -11,7 +11,7 @@ fn region_identity(x: &uint) -> &uint { x } -fn apply(t: T, f: |T| -> T) -> T { f(t) } +fn apply(t: T, f: F) -> T where F: FnOnce(T) -> T { f(t) } fn parameterized(x: &uint) -> uint { let z = apply(x, ({|y| diff --git a/src/test/run-pass/regions-static-closure.rs b/src/test/run-pass/regions-static-closure.rs index f1d2adcaf94d8..0f36dc0457544 100644 --- a/src/test/run-pass/regions-static-closure.rs +++ b/src/test/run-pass/regions-static-closure.rs @@ -8,19 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(unboxed_closures)] + struct closure_box<'a> { - cl: ||: 'a, + cl: Box, } -fn box_it(x: ||) -> closure_box { +fn box_it<'a>(x: Box) -> closure_box<'a> { closure_box {cl: x} } -fn call_static_closure(cl: closure_box<'static>) { - (cl.cl)(); +fn call_static_closure(mut cl: closure_box<'static>) { + cl.cl.call_mut(()) } pub fn main() { - let cl_box = box_it(|| println!("Hello, world!")); + let cl_box = box_it(box |&mut:| println!("Hello, world!")); call_static_closure(cl_box); } diff --git a/src/test/run-pass/return-from-closure.rs b/src/test/run-pass/return-from-closure.rs index b905ebf52fcb3..899dc8ddbe90d 100644 --- a/src/test/run-pass/return-from-closure.rs +++ b/src/test/run-pass/return-from-closure.rs @@ -13,7 +13,7 @@ static mut calls: uint = 0; fn surrounding() { - let return_works = |n: int| { + let return_works = |&: n: int| { unsafe { calls += 1 } if n >= 0 { return; } diff --git a/src/test/run-pass/sendfn-is-a-block.rs b/src/test/run-pass/sendfn-is-a-block.rs index 3f94c7c8e547a..c70ed9a3d749e 100644 --- a/src/test/run-pass/sendfn-is-a-block.rs +++ b/src/test/run-pass/sendfn-is-a-block.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn test(f: |uint| -> uint) -> uint { +fn test(f: F) -> uint where F: FnOnce(uint) -> uint { return f(22u); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index ff6e0e4bbc9f5..74c0663971ec5 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -26,14 +26,14 @@ mod b { trait uint_utils { fn str(&self) -> String; - fn multi(&self, f: |uint|); + fn multi(&self, f: F) where F: FnMut(uint); } impl uint_utils for uint { fn str(&self) -> String { self.to_string() } - fn multi(&self, f: |uint|) { + fn multi(&self, mut f: F) where F: FnMut(uint) { let mut c = 0u; while c < *self { f(c); c += 1u; } } @@ -41,14 +41,14 @@ impl uint_utils for uint { trait vec_utils { fn length_(&self, ) -> uint; - fn iter_(&self, f: |&T|); - fn map_(&self, f: |&T| -> U) -> Vec ; + fn iter_(&self, f: F) where F: FnMut(&T); + fn map_(&self, f: F) -> Vec where F: FnMut(&T) -> U; } impl vec_utils for Vec { fn length_(&self) -> uint { self.len() } - fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } } - fn map_(&self, f: |&T| -> U) -> Vec { + fn iter_(&self, mut f: F) where F: FnMut(&T) { for x in self.iter() { f(x); } } + fn map_(&self, mut f: F) -> Vec where F: FnMut(&T) -> U { let mut r = Vec::new(); for elt in self.iter() { r.push(f(elt)); @@ -64,7 +64,7 @@ pub fn main() { assert_eq!((vec!(1i)).length_().str(), "1".to_string()); let vect = vec!(3i, 4).map_(|a| *a + 4); assert_eq!(vect[0], 7); - let vect = (vec!(3i, 4)).map_::(|a| *a as uint + 4u); + let vect = (vec!(3i, 4)).map_::(|a| *a as uint + 4u); assert_eq!(vect[0], 7u); let mut x = 0u; 10u.multi(|_n| x += 2u ); diff --git a/src/test/run-pass/struct-partial-move-1.rs b/src/test/run-pass/struct-partial-move-1.rs index 8cc4cd142be09..043ca121b1bb5 100644 --- a/src/test/run-pass/struct-partial-move-1.rs +++ b/src/test/run-pass/struct-partial-move-1.rs @@ -16,7 +16,7 @@ struct S { val: int } impl S { fn new(v: int) -> S { S { val: v } } } impl Drop for S { fn drop(&mut self) { } } -pub fn f((b1, b2): (T, T), f: |T| -> T) -> Partial { +pub fn f((b1, b2): (T, T), mut f: F) -> Partial where F: FnMut(T) -> T { let p = Partial { x: b1, y: b2 }; // Move of `p` is legal even though we are also moving `p.y`; the diff --git a/src/test/run-pass/struct-partial-move-2.rs b/src/test/run-pass/struct-partial-move-2.rs index aafe9e632b1ed..6327e03e528af 100644 --- a/src/test/run-pass/struct-partial-move-2.rs +++ b/src/test/run-pass/struct-partial-move-2.rs @@ -18,7 +18,7 @@ impl Drop for S { fn drop(&mut self) { } } pub type Two = (Partial, Partial); -pub fn f((b1, b2): (T, T), (b3, b4): (T, T), f: |T| -> T) -> Two { +pub fn f((b1, b2): (T, T), (b3, b4): (T, T), mut f: F) -> Two where F: FnMut(T) -> T { let p = Partial { x: b1, y: b2 }; let q = Partial { x: b3, y: b4 }; diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index 8fda8a951693f..33e10cc77b7c1 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -189,7 +189,7 @@ pub fn dont_double_panic() { assert!(r.is_err()); } -fn in_tmpdir(f: ||) { +fn in_tmpdir(f: F) where F: FnOnce() { let tmpdir = TempDir::new("test").ok().expect("can't make tmpdir"); assert!(os::change_dir(tmpdir.path()).is_ok()); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index c8abfcaa721de..b193ad7892a6d 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -11,12 +11,16 @@ // Tests that a heterogeneous list of existential types can be put inside an Arc // and shared between tasks as long as all types fulfill Send. +// ignore-pretty + +#![feature(unboxed_closures)] + use std::sync::Arc; use std::sync::mpsc::channel; use std::thread::Thread; trait Pet { - fn name(&self, blk: |&str|); + fn name(&self, blk: Box); fn num_legs(&self) -> uint; fn of_good_pedigree(&self) -> bool; } @@ -38,19 +42,19 @@ struct Goldfyshe { } impl Pet for Catte { - fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } + fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 } } impl Pet for Dogge { - fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } + fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.bark_decibels < 70 || self.tricks_known > 20 } } impl Pet for Goldfyshe { - fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } + fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } fn num_legs(&self) -> uint { 0 } fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 } } @@ -98,7 +102,7 @@ fn check_legs(arc: Arc>>) { } fn check_names(arc: Arc>>) { for pet in arc.iter() { - pet.name(|name| { + pet.name(box |name| { assert!(name.as_bytes()[0] == 'a' as u8 && name.as_bytes()[1] == 'l' as u8); }) } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index eeda6e2c88b45..d4c1b688b47b6 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -24,10 +24,10 @@ impl to_str for () { } trait map { - fn map(&self, f: |&T| -> U) -> Vec ; + fn map(&self, f: F) -> Vec where F: FnMut(&T) -> U; } impl map for Vec { - fn map(&self, f: |&T| -> U) -> Vec { + fn map(&self, mut f: F) -> Vec where F: FnMut(&T) -> U { let mut r = Vec::new(); for i in self.iter() { r.push(f(i)); diff --git a/src/test/run-pass/type-id-higher-rank.rs b/src/test/run-pass/type-id-higher-rank.rs index efda7771403a3..7287d149f5100 100644 --- a/src/test/run-pass/type-id-higher-rank.rs +++ b/src/test/run-pass/type-id-higher-rank.rs @@ -34,24 +34,6 @@ fn main() { let f = TypeId::of:: fn(&'a int) -> &'a int)>(); assert!(e != f); } - // Stack closures - { - let a = TypeId::of::<|&'static int, &'static int|>(); - let b = TypeId::of:: |&'static int, &'a int|>(); - let c = TypeId::of:: |&'a int, &'b int|>(); - let d = TypeId::of:: |&'b int, &'a int|>(); - assert!(a != b); - assert!(a != c); - assert!(a != d); - assert!(b != c); - assert!(b != d); - assert_eq!(c, d); - - // Make sure De Bruijn indices are handled correctly - let e = TypeId::of:: |(|&'a int| -> &'a int)|>(); - let f = TypeId::of::<|for<'a> |&'a int| -> &'a int|>(); - assert!(e != f); - } // Boxed unboxed closures { let a = TypeId::of::>(); diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs index 5bf1a72dc6b2a..24cc5fab8ed77 100644 --- a/src/test/run-pass/type-params-in-for-each.rs +++ b/src/test/run-pass/type-params-in-for-each.rs @@ -14,7 +14,7 @@ struct S { b: uint, } -fn range_(lo: uint, hi: uint, it: |uint|) { +fn range_(lo: uint, hi: uint, mut it: F) where F: FnMut(uint) { let mut lo_ = lo; while lo_ < hi { it(lo_); lo_ += 1u; } } diff --git a/src/test/run-pass/unnamed_argument_mode.rs b/src/test/run-pass/unnamed_argument_mode.rs index 3a5e0dd8ae3b9..d22a6652e16f3 100644 --- a/src/test/run-pass/unnamed_argument_mode.rs +++ b/src/test/run-pass/unnamed_argument_mode.rs @@ -13,7 +13,7 @@ fn good(_a: &int) { // unnamed argument &int is now parse x: &int -fn called(_f: |&int|) { +fn called(_f: F) where F: FnOnce(&int) { } pub fn main() { diff --git a/src/test/run-pass/unused-move-capture.rs b/src/test/run-pass/unused-move-capture.rs index ba48ae1c0cef8..bd20a174d1e49 100644 --- a/src/test/run-pass/unused-move-capture.rs +++ b/src/test/run-pass/unused-move-capture.rs @@ -10,6 +10,6 @@ pub fn main() { let _x = box 1i; - let lam_move: || = || {}; + let lam_move = |&:| {}; lam_move(); } diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index ec320c1f8a309..3e7718970258f 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -19,7 +19,7 @@ extern { fn sprintf(s: *mut c_char, format: *const c_char, ...) -> c_int; } -unsafe fn check(expected: &str, f: |*mut c_char| -> T) { +unsafe fn check(expected: &str, f: F) where F: FnOnce(*mut c_char) -> T { let mut x = [0 as c_char; 50]; f(&mut x[0] as *mut c_char); let res = CString::new(&x[0], false); diff --git a/src/test/run-pass/vec-matching-fold.rs b/src/test/run-pass/vec-matching-fold.rs index cc2061c3cf385..576601833330d 100644 --- a/src/test/run-pass/vec-matching-fold.rs +++ b/src/test/run-pass/vec-matching-fold.rs @@ -10,10 +10,13 @@ #![feature(advanced_slice_patterns)] -fn foldl(values: &[T], - initial: U, - function: |partial: U, element: &T| -> U) - -> U { +fn foldl(values: &[T], + initial: U, + mut function: F) + -> U where + U: Clone, + F: FnMut(U, &T) -> U, +{ match values { [ref head, tail..] => foldl(tail, function(initial, head), function), @@ -21,10 +24,13 @@ fn foldl(values: &[T], } } -fn foldr(values: &[T], - initial: U, - function: |element: &T, partial: U| -> U) - -> U { +fn foldr(values: &[T], + initial: U, + mut function: F) + -> U where + U: Clone, + F: FnMut(&T, U) -> U, +{ match values { [head.., ref tail] => foldr(head, function(tail, initial), function), diff --git a/src/test/run-pass/weird-exprs.rs b/src/test/run-pass/weird-exprs.rs index f73800b89db64..c8ed1a2610573 100644 --- a/src/test/run-pass/weird-exprs.rs +++ b/src/test/run-pass/weird-exprs.rs @@ -26,7 +26,7 @@ fn what() { return while !x.get() { x.set(true); }; } let i = &Cell::new(false); - let dont = {||the(i)}; + let dont = {|&:|the(i)}; dont(); assert!((i.get())); } From 7d5b0454e9ee5ea9b99c6315174b498df60a7bb5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Jan 2015 10:45:00 -0500 Subject: [PATCH 25/37] fix cfail tests --- .../compile-fail/access-mode-in-closures.rs | 2 +- src/test/compile-fail/assign-to-method.rs | 2 +- src/test/compile-fail/block-coerce-no-2.rs | 23 ------- src/test/compile-fail/block-coerce-no.rs | 26 -------- .../compile-fail/borrowck-assign-comp-idx.rs | 2 +- .../compile-fail/borrowck-autoref-3261.rs | 4 +- src/test/compile-fail/borrowck-block-unint.rs | 2 +- .../borrowck-call-is-borrow-issue-12224.rs | 37 ++++++------ .../borrowck-closures-mut-and-imm.rs | 24 ++++---- .../borrowck-closures-mut-of-imm.rs | 4 +- .../compile-fail/borrowck-closures-two-mut.rs | 20 +++---- .../borrowck-closures-unique-imm.rs | 2 +- .../compile-fail/borrowck-closures-unique.rs | 18 +++--- .../borrowck-closures-use-after-free.rs | 2 +- .../borrowck-init-in-called-fn-expr.rs | 2 +- .../compile-fail/borrowck-init-in-fn-expr.rs | 2 +- .../borrowck-insert-during-each.rs | 2 +- .../compile-fail/borrowck-lend-flow-if.rs | 2 +- .../compile-fail/borrowck-lend-flow-loop.rs | 6 +- src/test/compile-fail/borrowck-lend-flow.rs | 2 +- .../borrowck-loan-blocks-move-cc.rs | 2 +- .../borrowck-loan-blocks-mut-uniq.rs | 2 +- src/test/compile-fail/borrowck-loan-rcvr.rs | 4 +- .../compile-fail/borrowck-loan-vec-content.rs | 2 +- .../compile-fail/borrowck-move-by-capture.rs | 2 +- .../borrowck-move-in-irrefut-pat.rs | 2 +- .../borrowck-report-with-custom-diagnostic.rs | 2 +- src/test/compile-fail/break-outside-loop.rs | 2 +- ...bounds-cant-promote-superkind-in-struct.rs | 9 +-- .../closure-bounds-not-builtin.rs | 18 ------ ...ure-bounds-static-cant-capture-borrowed.rs | 3 +- .../compile-fail/closure-bounds-subtype.rs | 10 ++-- src/test/compile-fail/closure-reform-bad.rs | 2 +- src/test/compile-fail/closure-that-fails.rs | 20 ------- .../coerce-bare-fn-to-closure-and-proc.rs | 28 --------- .../compile-fail/dead-code-closure-bang.rs | 4 +- .../compile-fail/extern-wrong-value-type.rs | 4 +- src/test/compile-fail/fn-variance-1.rs | 2 +- .../compile-fail/immut-function-arguments.rs | 2 +- src/test/compile-fail/issue-10291.rs | 2 +- src/test/compile-fail/issue-11192.rs | 2 +- src/test/compile-fail/issue-11873.rs | 2 +- src/test/compile-fail/issue-14182.rs | 2 + src/test/compile-fail/issue-16939.rs | 2 +- src/test/compile-fail/issue-17636.rs | 19 ------ src/test/compile-fail/issue-17651.rs | 2 +- src/test/compile-fail/issue-18343.rs | 6 +- src/test/compile-fail/issue-18345.rs | 20 ------- src/test/compile-fail/issue-18783.rs | 14 ++--- src/test/compile-fail/issue-19009.rs | 19 ------ src/test/compile-fail/issue-19141.rs | 15 ----- src/test/compile-fail/issue-20193.rs | 24 -------- src/test/compile-fail/issue-20228-1.rs | 20 ------- src/test/compile-fail/issue-20228-2.rs | 20 ------- src/test/compile-fail/issue-2149.rs | 6 +- src/test/compile-fail/issue-3044.rs | 2 +- src/test/compile-fail/issue-3563.rs | 7 ++- src/test/compile-fail/issue-4335.rs | 8 ++- src/test/compile-fail/issue-4523.rs | 17 ------ src/test/compile-fail/issue-5216.rs | 4 +- src/test/compile-fail/issue-5239-1.rs | 2 +- src/test/compile-fail/issue-6801.rs | 4 +- src/test/compile-fail/issue-7573.rs | 4 +- src/test/compile-fail/kindck-copy.rs | 3 - src/test/compile-fail/kindck-send-object.rs | 5 -- .../compile-fail/lint-unused-mut-variables.rs | 6 +- src/test/compile-fail/lint-unused-unsafe.rs | 2 +- .../liveness-closure-require-ret.rs | 2 +- .../moves-based-on-type-block-bad.rs | 2 +- ...type-move-out-of-closure-env-issue-1965.rs | 2 +- ...ased-on-type-no-recursive-stack-closure.rs | 12 ++-- src/test/compile-fail/pptypedef.rs | 2 +- .../refutable-pattern-in-fn-arg.rs | 2 +- .../region-bound-on-closure-outlives-call.rs | 4 +- .../regionck-closure-lifetimes.rs | 60 ------------------- .../regions-addr-of-upvar-self.rs | 2 +- .../compile-fail/regions-bounded-by-send.rs | 5 -- .../compile-fail/regions-creating-enums.rs | 8 +-- .../compile-fail/regions-escape-bound-fn-2.rs | 2 +- .../compile-fail/regions-escape-bound-fn.rs | 2 +- .../compile-fail/regions-escape-method.rs | 2 +- .../regions-escape-via-trait-or-not.rs | 2 +- src/test/compile-fail/regions-fn-subtyping.rs | 45 -------------- src/test/compile-fail/regions-fns.rs | 21 ------- .../regions-free-region-ordering-callee.rs | 2 +- src/test/compile-fail/regions-freevar.rs | 18 ------ .../regions-infer-at-fn-not-param.rs | 6 +- .../regions-infer-borrow-scope-within-loop.rs | 5 +- src/test/compile-fail/regions-infer-call-3.rs | 2 +- ...ns-infer-invariance-due-to-mutability-3.rs | 2 +- ...ns-infer-invariance-due-to-mutability-4.rs | 2 +- .../compile-fail/regions-infer-not-param.rs | 4 +- .../compile-fail/regions-name-undeclared.rs | 15 ++--- src/test/compile-fail/regions-nested-fns-2.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 4 +- .../compile-fail/regions-ref-in-fn-arg.rs | 2 +- .../compile-fail/regions-ret-borrowed-1.rs | 2 +- src/test/compile-fail/regions-ret-borrowed.rs | 2 +- ...regions-return-ref-to-upvar-issue-17403.rs | 7 --- .../compile-fail/regions-steal-closure.rs | 12 ++-- .../compile-fail/type-arg-out-of-scope.rs | 2 +- 101 files changed, 195 insertions(+), 612 deletions(-) delete mode 100644 src/test/compile-fail/block-coerce-no-2.rs delete mode 100644 src/test/compile-fail/block-coerce-no.rs delete mode 100644 src/test/compile-fail/closure-bounds-not-builtin.rs delete mode 100644 src/test/compile-fail/closure-that-fails.rs delete mode 100644 src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs delete mode 100644 src/test/compile-fail/issue-17636.rs delete mode 100644 src/test/compile-fail/issue-18345.rs delete mode 100644 src/test/compile-fail/issue-19009.rs delete mode 100644 src/test/compile-fail/issue-19141.rs delete mode 100644 src/test/compile-fail/issue-20193.rs delete mode 100644 src/test/compile-fail/issue-20228-1.rs delete mode 100644 src/test/compile-fail/issue-20228-2.rs delete mode 100644 src/test/compile-fail/issue-4523.rs delete mode 100644 src/test/compile-fail/regionck-closure-lifetimes.rs delete mode 100644 src/test/compile-fail/regions-fn-subtyping.rs delete mode 100644 src/test/compile-fail/regions-fns.rs delete mode 100644 src/test/compile-fail/regions-freevar.rs diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index e1696f0e63ed7..f15157d126ed7 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -11,7 +11,7 @@ struct sty(Vec ); -fn unpack(_unpack: |v: &sty| -> Vec ) {} +fn unpack(_unpack: F) where F: FnOnce(&sty) -> Vec {} fn main() { let _foo = unpack(|s| { diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 453d7ffdad5c3..f14668192f850 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -27,5 +27,5 @@ fn cat(in_x : uint, in_y : int) -> cat { fn main() { let nyan : cat = cat(52u, 99); - nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method + nyan.speak = |&:| println!("meow"); //~ ERROR attempted to take value of method } diff --git a/src/test/compile-fail/block-coerce-no-2.rs b/src/test/compile-fail/block-coerce-no-2.rs deleted file mode 100644 index e268b0e93fdad..0000000000000 --- a/src/test/compile-fail/block-coerce-no-2.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 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. - -// Make sure that fn-to-block coercion isn't incorrectly lifted over -// other tycons. - -fn main() { - fn f(f: fn(fn(fn()))) { - } - - fn g(f: fn(||)) { - } - - f(g); - //~^ ERROR mismatched types: expected `fn(fn(fn()))` -} diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs deleted file mode 100644 index 76af956a26fff..0000000000000 --- a/src/test/compile-fail/block-coerce-no.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 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. - -// Make sure that fn-to-block coercion isn't incorrectly lifted over -// other tycons. - -fn coerce(b: ||) -> extern fn() { - fn lol(f: extern fn(v: ||) -> extern fn(), - g: ||) -> extern fn() { return f(g); } - fn fn_id(f: extern fn()) -> extern fn() { return f } - return lol(fn_id, b); - //~^ ERROR mismatched types -} - -fn main() { - let i = 8i; - let f = coerce(|| println!("{}", i) ); - f(); -} diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index e14911d3508da..a6801a6a51a52 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -24,7 +24,7 @@ fn a() { println!("{}", *q); } -fn borrow(_x: &[int], _f: ||) {} +fn borrow(_x: &[int], _f: F) where F: FnOnce() {} fn b() { // here we alias the mutable vector into an imm slice and try to diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 1b4e5891f941d..2804b8c48a703 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -13,7 +13,7 @@ enum Either { Left(T), Right(U) } struct X(Either<(uint,uint), fn()>); impl X { - pub fn with(&self, blk: |x: &Either<(uint,uint), fn()>|) { + pub fn with(&self, blk: F) where F: FnOnce(&Either<(uint, uint), fn()>) { let X(ref e) = *self; blk(e) } @@ -25,7 +25,7 @@ fn main() { |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time match opt { &Either::Right(ref f) => { - x = X(Either::Left((0,0))); + x = X(Either::Left((0, 0))); (*f)() }, _ => panic!() diff --git a/src/test/compile-fail/borrowck-block-unint.rs b/src/test/compile-fail/borrowck-block-unint.rs index a37717ed5d998..e519e57d178c8 100644 --- a/src/test/compile-fail/borrowck-block-unint.rs +++ b/src/test/compile-fail/borrowck-block-unint.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: ||) { f(); } +fn force(f: F) where F: FnOnce() { f(); } fn main() { let x: int; force(|| { //~ ERROR capture of possibly uninitialized variable: `x` diff --git a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs index 002ae5a7d28b4..6dbdff9441d55 100644 --- a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs +++ b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs @@ -10,53 +10,54 @@ // Ensure that invoking a closure counts as a unique immutable borrow +#![feature(unboxed_closures)] -type Fn<'a> = ||:'a; +type Fn<'a> = Box; struct Test<'a> { - f: ||: 'a + f: Box } -fn call(f: |Fn|) { - f(|| { - //~^ ERROR: closure requires unique access to `f` but it is already borrowed - f(|| {}) +fn call(mut f: F) where F: FnMut(Fn) { + f(box || { + //~^ ERROR: cannot borrow `f` as mutable more than once + f(box || {}) }); } fn test1() { - call(|a| { - a(); + call(|mut a| { + a.call_mut(()); }); } -fn test2(f: &||) { - (*f)(); //~ ERROR: closure invocation in a `&` reference +fn test2(f: &F) where F: FnMut() { + (*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable } -fn test3(f: &mut ||) { +fn test3(f: &mut F) where F: FnMut() { (*f)(); } fn test4(f: &Test) { - (f.f)() //~ ERROR: closure invocation in a `&` reference + f.f.call_mut(()) //~ ERROR: cannot borrow immutable dereference of `Box` `*f.f` as mutable } fn test5(f: &mut Test) { - (f.f)() + f.f.call_mut(()) } fn test6() { - let f = || {}; - (|| { + let mut f = |&mut:| {}; + (|&mut:| { f(); })(); } fn test7() { - fn foo(_: |g: |int|, b: int|) {} - let f = |g: |int|, b: int| {}; - f(|a| { //~ ERROR: cannot borrow `f` as immutable because previous closure + fn foo(_: F) where F: FnMut(Box, int) {} + let mut f = |&mut: g: Box, b: int| {}; + f(box |a| { //~ ERROR: cannot borrow `f` as immutable because it is also borrowed as mutable foo(f); //~ ERROR: cannot move out of captured outer variable }, 3); } diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs index 886026e45d90f..47a47d0443255 100644 --- a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs @@ -22,37 +22,37 @@ fn set(x: &mut int) { fn a() { let mut x = 3i; - let c1 = || x = 4; - let c2 = || x * 5; //~ ERROR cannot borrow `x` + let c1 = |&mut:| x = 4; + let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x` } fn b() { let mut x = 3i; - let c1 = || set(&mut x); - let c2 = || get(&x); //~ ERROR cannot borrow `x` + let c1 = |&mut:| set(&mut x); + let c2 = |&mut:| get(&x); //~ ERROR cannot borrow `x` } fn c() { let mut x = 3i; - let c1 = || set(&mut x); - let c2 = || x * 5; //~ ERROR cannot borrow `x` + let c1 = |&mut:| set(&mut x); + let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x` } fn d() { let mut x = 3i; - let c2 = || x * 5; + let c2 = |&mut:| x * 5; x = 5; //~ ERROR cannot assign } fn e() { let mut x = 3i; - let c1 = || get(&x); + let c1 = |&mut:| get(&x); x = 5; //~ ERROR cannot assign } fn f() { let mut x = box 3i; - let c1 = || get(&*x); + let c1 = |&mut:| get(&*x); *x = 5; //~ ERROR cannot assign } @@ -62,7 +62,7 @@ fn g() { } let mut x = box Foo { f: box 3 }; - let c1 = || get(&*x.f); + let c1 = |&mut:| get(&*x.f); *x.f = 5; //~ ERROR cannot assign to `*x.f` } @@ -72,8 +72,8 @@ fn h() { } let mut x = box Foo { f: box 3 }; - let c1 = || get(&*x.f); - let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable + let c1 = |&mut:| get(&*x.f); + let c2 = |&mut:| *x.f = 5; //~ ERROR cannot borrow `x` as mutable } fn main() { diff --git a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs index 8163df5e967cd..30e1421ba2660 100644 --- a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs @@ -20,9 +20,9 @@ fn set(x: &mut int) { } fn a(x: &int) { - let c1 = || set(&mut *x); + let c1 = |&mut:| set(&mut *x); //~^ ERROR cannot borrow - let c2 = || set(&mut *x); + let c2 = |&mut:| set(&mut *x); //~^ ERROR cannot borrow //~| ERROR closure requires unique access } diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs index 6d382854d49f2..0f284b5384913 100644 --- a/src/test/compile-fail/borrowck-closures-two-mut.rs +++ b/src/test/compile-fail/borrowck-closures-two-mut.rs @@ -15,8 +15,8 @@ fn a() { let mut x = 3i; - let c1 = || x = 4; - let c2 = || x = 5; //~ ERROR cannot borrow `x` as mutable more than once + let c1 = |&mut:| x = 4; + let c2 = |&mut:| x = 5; //~ ERROR cannot borrow `x` as mutable more than once } fn set(x: &mut int) { @@ -25,20 +25,20 @@ fn set(x: &mut int) { fn b() { let mut x = 3i; - let c1 = || set(&mut x); - let c2 = || set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once + let c1 = |&mut:| set(&mut x); + let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once } fn c() { let mut x = 3i; - let c1 = || x = 5; - let c2 = || set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once + let c1 = |&mut:| x = 5; + let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once } fn d() { let mut x = 3i; - let c1 = || x = 5; - let c2 = || { let _y = || set(&mut x); }; // (nested closure) + let c1 = |&mut:| x = 5; + let c2 = |&mut:| { let _y = |&mut:| set(&mut x); }; // (nested closure) //~^ ERROR cannot borrow `x` as mutable more than once } @@ -48,8 +48,8 @@ fn g() { } let mut x = box Foo { f: box 3 }; - let c1 = || set(&mut *x.f); - let c2 = || set(&mut *x.f); + let c1 = |&mut:| set(&mut *x.f); + let c2 = |&mut:| set(&mut *x.f); //~^ ERROR cannot borrow `x` as mutable more than once } diff --git a/src/test/compile-fail/borrowck-closures-unique-imm.rs b/src/test/compile-fail/borrowck-closures-unique-imm.rs index dfe5de09c5097..a9cc9e967f6ff 100644 --- a/src/test/compile-fail/borrowck-closures-unique-imm.rs +++ b/src/test/compile-fail/borrowck-closures-unique-imm.rs @@ -16,7 +16,7 @@ pub fn main() { let mut this = &mut Foo { x: 1, }; - let r = || { + let mut r = |&mut:| { let p = &this.x; &mut this.x; //~ ERROR cannot borrow }; diff --git a/src/test/compile-fail/borrowck-closures-unique.rs b/src/test/compile-fail/borrowck-closures-unique.rs index febc84ccd4461..9a772cc49b87b 100644 --- a/src/test/compile-fail/borrowck-closures-unique.rs +++ b/src/test/compile-fail/borrowck-closures-unique.rs @@ -23,27 +23,27 @@ fn set(x: &mut int) -> int { } fn a(x: &mut int) { - let c1 = || get(x); - let c2 = || get(x); + let c1 = |&mut:| get(x); + let c2 = |&mut:| get(x); } fn b(x: &mut int) { - let c1 = || get(x); - let c2 = || set(x); //~ ERROR closure requires unique access to `x` + let c1 = |&mut:| get(x); + let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x` } fn c(x: &mut int) { - let c1 = || get(x); - let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x` + let c1 = |&mut:| get(x); + let c2 = |&mut:| { get(x); set(x); }; //~ ERROR closure requires unique access to `x` } fn d(x: &mut int) { - let c1 = || set(x); - let c2 = || set(x); //~ ERROR closure requires unique access to `x` + let c1 = |&mut:| set(x); + let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x` } fn e(x: &mut int) { - let c1: || = || x = panic!(); //~ ERROR closure cannot assign to immutable local variable + let c1 = |&mut:| x = panic!(); //~ ERROR closure cannot assign to immutable local variable } fn main() { diff --git a/src/test/compile-fail/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck-closures-use-after-free.rs index 735d9ece9b1a5..23c90fcf574d5 100644 --- a/src/test/compile-fail/borrowck-closures-use-after-free.rs +++ b/src/test/compile-fail/borrowck-closures-use-after-free.rs @@ -25,7 +25,7 @@ impl Drop for Foo { fn main() { let mut ptr = box Foo { x: 0 }; - let test = |foo: &Foo| { + let mut test = |&mut: foo: &Foo| { ptr = box Foo { x: ptr.x + 1 }; }; test(&*ptr); //~ ERROR cannot borrow `*ptr` diff --git a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs index d759a5738bd22..5496a9dd4b361 100644 --- a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let j: || -> int = || { + let j = |&:| -> int { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; diff --git a/src/test/compile-fail/borrowck-init-in-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-fn-expr.rs index 07e2ff084664d..33c284c71b341 100644 --- a/src/test/compile-fail/borrowck-init-in-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let f: || -> int = || { + let f = |&:| -> int { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index a84a025d8a8ee..0428ee8306517 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -16,7 +16,7 @@ struct Foo { } impl Foo { - pub fn foo(&mut self, fun: |&int|) { + pub fn foo(&mut self, mut fun: F) where F: FnMut(&int) { for f in self.n.iter() { fun(f); } diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index 8a7ecde700ae6..f798d170f963b 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -18,7 +18,7 @@ fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { panic!() } -fn for_func(_f: || -> bool) { panic!() } +fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 6adcfad33f46c..ff038b545d5fe 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -112,7 +112,9 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) { } } -fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) { +fn loop_break_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where + F: FnMut(&'r mut uint) -> bool, +{ // Here we check that when you break out of an inner loop, the // borrows that go out of scope as you exit the inner loop are // removed from the bitset. @@ -128,7 +130,7 @@ fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) { } } -fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) { +fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where F: FnMut(&'r mut uint) -> bool { // Similar to `loop_break_pops_scopes` but for the `loop` keyword while cond() { diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index de8c7d9def4e1..85fc7fb87b340 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -18,7 +18,7 @@ fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { panic!() } -fn for_func(_f: || -> bool) { panic!() } +fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 9bd2d48b29a85..5c282495cc239 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -10,7 +10,7 @@ use std::thread::Thread; -fn borrow(v: &int, f: |x: &int|) { +fn borrow(v: &int, f: F) where F: FnOnce(&int) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index bfa890ada9f19..b6a71fcd446ab 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn borrow(v: &int, f: |x: &int|) { +fn borrow(v: &int, f: F) where F: FnOnce(&int) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index d678fd48f21d2..0ada3db47a4b6 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -13,14 +13,14 @@ struct point { x: int, y: int } trait methods { fn impurem(&self); - fn blockm(&self, f: ||); + fn blockm(&self, f: F) where F: FnOnce(); } impl methods for point { fn impurem(&self) { } - fn blockm(&self, f: ||) { f() } + fn blockm(&self, f: F) where F: FnOnce() { f() } } fn a() { diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 200d208d140b6..7849475ec6799 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -12,7 +12,7 @@ // (locally rooted) mutable, unique vector, and that we then prevent // modifications to the contents. -fn takes_imm_elt(_v: &int, f: ||) { +fn takes_imm_elt(_v: &int, f: F) where F: FnOnce() { f(); } diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index 9c9641bccfa14..35f0751aa7895 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -10,7 +10,7 @@ pub fn main() { let bar = box 3; - let _g = || { + let _g = |&mut:| { let _h = move |:| -> int { *bar }; //~ ERROR cannot move out of captured outer variable }; } diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index c7b573562e348..c5d23925a89b1 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with(f: |&String|) {} +fn with(f: F) where F: FnOnce(&String) {} fn arg_item(&_x: &String) {} //~^ ERROR cannot move out of dereference of `&`-pointer diff --git a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs index 82189c6b7c1f1..0a47353683cfb 100644 --- a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs +++ b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs @@ -32,7 +32,7 @@ fn foo() { fn bar() { // Original borrow ends at end of closure - || { + |&:| { let mut x = 1u; let y = &mut x; let z = &mut x; //~ ERROR cannot borrow diff --git a/src/test/compile-fail/break-outside-loop.rs b/src/test/compile-fail/break-outside-loop.rs index d72398a6ac5a7..1f257b8a5cba8 100644 --- a/src/test/compile-fail/break-outside-loop.rs +++ b/src/test/compile-fail/break-outside-loop.rs @@ -14,7 +14,7 @@ struct Foo { fn cond() -> bool { true } -fn foo(_: ||) {} +fn foo(_: F) where F: FnOnce() {} fn main() { let pth = break; //~ ERROR: `break` outside of loop diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index 1ff9dc9dac4c2..a02d6b7f5173a 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct X { - field: ||:'static + Send, +struct X where F: FnOnce() + 'static + Send { + field: F, } -fn foo(blk: ||:'static) -> X { - return X { field: blk }; //~ ERROR expected bounds `Send` +fn foo(blk: F) -> X where F: FnOnce() + 'static { + //~^ ERROR the trait `core::kinds::Send` is not implemented for the type + return X { field: blk }; } fn main() { diff --git a/src/test/compile-fail/closure-bounds-not-builtin.rs b/src/test/compile-fail/closure-bounds-not-builtin.rs deleted file mode 100644 index 6b25e4be2d9a3..0000000000000 --- a/src/test/compile-fail/closure-bounds-not-builtin.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 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. - - -trait Foo {} - -fn take(f: ||:Foo) { - //~^ ERROR only the builtin traits can be used as closure or object bounds -} - -fn main() {} diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 6769740294bc6..d27529bad4305 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -8,13 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn bar(blk: ||:'static) { +fn bar(blk: F) where F: FnOnce() + 'static { } fn foo(x: &()) { bar(|| { //~ ERROR cannot infer an appropriate lifetime let _ = x; - //~^ ERROR captured variable `x` does not outlive }) } diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index 5bd9f20dd8343..509fffc5c9a88 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -9,19 +9,19 @@ // except according to those terms. -fn take_any(_: ||) { +fn take_any(_: F) where F: FnOnce() { } -fn take_const_owned(_: ||:Sync+Send) { +fn take_const_owned(_: F) where F: FnOnce() + Sync + Send { } -fn give_any(f: ||) { +fn give_any(f: F) where F: FnOnce() { take_any(f); } -fn give_owned(f: ||:Send) { +fn give_owned(f: F) where F: FnOnce() + Send { take_any(f); - take_const_owned(f); //~ ERROR expected bounds `Send+Sync`, found bounds `Send` + take_const_owned(f); //~ ERROR the trait `core::kinds::Sync` is not implemented for the type } fn main() {} diff --git a/src/test/compile-fail/closure-reform-bad.rs b/src/test/compile-fail/closure-reform-bad.rs index 1e1889c7339d2..ef01c96addeb8 100644 --- a/src/test/compile-fail/closure-reform-bad.rs +++ b/src/test/compile-fail/closure-reform-bad.rs @@ -17,7 +17,7 @@ fn call_bare(f: fn(&str)) { fn main() { let string = "world!"; - let f: |&str| = |s| println!("{}{}", s, string); + let f = |&: s: &str| println!("{}{}", s, string); call_bare(f) //~ ERROR mismatched types } diff --git a/src/test/compile-fail/closure-that-fails.rs b/src/test/compile-fail/closure-that-fails.rs deleted file mode 100644 index 7a1ebed0a82ac..0000000000000 --- a/src/test/compile-fail/closure-that-fails.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 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. - -fn foo(f: || -> !) {} - -fn main() { - // Type inference didn't use to be able to handle this: - foo(|| panic!()); - foo(|| -> ! panic!()); - foo(|| 22i); //~ ERROR computation may converge in a function marked as diverging - foo(|| -> ! 22i); //~ ERROR computation may converge in a function marked as diverging - let x = || -> ! 1i; //~ ERROR computation may converge in a function marked as diverging -} diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs deleted file mode 100644 index 52f4c4749e224..0000000000000 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 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 coercions from fn item types are ok, but not fn pointer -// types to closures/procs are not allowed. - -fn foo() {} - -fn fn_item_type() { - let f = foo; - - let f_closure: || = f; -} - -fn fn_pointer_type() { - let f = foo as fn(); - let f_closure: || = f; - //~^ ERROR: mismatched types -} - -fn main() { } diff --git a/src/test/compile-fail/dead-code-closure-bang.rs b/src/test/compile-fail/dead-code-closure-bang.rs index 0aa3c40fa5f88..46f5f41d7282f 100644 --- a/src/test/compile-fail/dead-code-closure-bang.rs +++ b/src/test/compile-fail/dead-code-closure-bang.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#20574) + #![deny(unreachable_code)] fn main() { - let x: || -> ! = || panic!(); + let x = |:| panic!(); x(); std::io::println("Foo bar"); //~ ERROR: unreachable statement } diff --git a/src/test/compile-fail/extern-wrong-value-type.rs b/src/test/compile-fail/extern-wrong-value-type.rs index 6b01b83db21fd..d7586af291e86 100644 --- a/src/test/compile-fail/extern-wrong-value-type.rs +++ b/src/test/compile-fail/extern-wrong-value-type.rs @@ -11,8 +11,10 @@ extern fn f() { } +fn is_fn(_: F) where F: Fn() {} + fn main() { // extern functions are extern "C" fn let _x: extern "C" fn() = f; // OK - let _x: || = f; //~ ERROR mismatched types + is_fn(f); //~ ERROR the trait `core::ops::Fn()` is not implemented for the type `extern "C" fn() } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index 2277f7080af75..039628b675282 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -12,7 +12,7 @@ fn takes_imm(x: &int) { } fn takes_mut(x: &mut int) { } -fn apply(t: T, f: |T|) { +fn apply(t: T, f: F) where F: FnOnce(T) { f(t) } diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 71328acdd7017..827e648cca86d 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -14,7 +14,7 @@ fn f(y: Box) { } fn g() { - let _frob: |Box| = |q| { *q = 2; }; //~ ERROR cannot assign + let _frob = |&: q: Box| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/issue-10291.rs b/src/test/compile-fail/issue-10291.rs index 924132c6de26b..dec4fc3b8f5b2 100644 --- a/src/test/compile-fail/issue-10291.rs +++ b/src/test/compile-fail/issue-10291.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test<'x>(x: &'x int) { - drop::< for<'z>|&'z int| -> &'z int >(|z| { + drop:: FnMut(&'z int) -> &'z int>>(box |z| { x //~^ ERROR cannot infer an appropriate lifetime }); diff --git a/src/test/compile-fail/issue-11192.rs b/src/test/compile-fail/issue-11192.rs index 18a00d15eafe3..f496c1e1227db 100644 --- a/src/test/compile-fail/issue-11192.rs +++ b/src/test/compile-fail/issue-11192.rs @@ -20,7 +20,7 @@ impl Drop for Foo { fn main() { let mut ptr = box Foo { x: 0 }; - let test = |foo: &Foo| { + let mut test = |&mut: foo: &Foo| { println!("access {}", foo.x); ptr = box Foo { x: ptr.x + 1 }; println!("access {}", foo.x); diff --git a/src/test/compile-fail/issue-11873.rs b/src/test/compile-fail/issue-11873.rs index e1acab4008a9b..8966793753153 100644 --- a/src/test/compile-fail/issue-11873.rs +++ b/src/test/compile-fail/issue-11873.rs @@ -10,7 +10,7 @@ fn main() { let mut v = vec!(1i); - let f = || v.push(2i); + let mut f = |&mut:| v.push(2i); let _w = v; //~ ERROR: cannot move out of `v` f(); diff --git a/src/test/compile-fail/issue-14182.rs b/src/test/compile-fail/issue-14182.rs index 24256e31118e3..5033576a23482 100644 --- a/src/test/compile-fail/issue-14182.rs +++ b/src/test/compile-fail/issue-14182.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japari) remove test + struct Foo { f: for <'b> |&'b int|: 'b -> &'b int //~ ERROR use of undeclared lifetime name `'b` diff --git a/src/test/compile-fail/issue-16939.rs b/src/test/compile-fail/issue-16939.rs index 7ec3fef5c878e..9d2212b69cee1 100644 --- a/src/test/compile-fail/issue-16939.rs +++ b/src/test/compile-fail/issue-16939.rs @@ -14,7 +14,7 @@ // wrong arity. fn _foo (f: F) { - |t| f(t); //~ ERROR E0057 + |&: t| f(t); //~ ERROR E0057 } fn main() {} diff --git a/src/test/compile-fail/issue-17636.rs b/src/test/compile-fail/issue-17636.rs deleted file mode 100644 index ad2ebff59bc51..0000000000000 --- a/src/test/compile-fail/issue-17636.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 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. - -trait MyItem {} -impl MyItem for T {} - -pub fn build_archive<'a, I: MyItem<&'a (|&uint|:'a)>>(files: I) {} - -fn main() { - build_archive(&(|_| { })); -//~^ ERROR not implemented -} diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs index ab396edddf49c..970b14c7eb7cc 100644 --- a/src/test/compile-fail/issue-17651.rs +++ b/src/test/compile-fail/issue-17651.rs @@ -12,7 +12,7 @@ // and rejected. fn main() { - (|| box *[0u].as_slice())(); + (|&:| box *[0u].as_slice())(); //~^ ERROR cannot move out of dereference //~^^ ERROR cannot move a value of type [uint] } diff --git a/src/test/compile-fail/issue-18343.rs b/src/test/compile-fail/issue-18343.rs index 1608d2137fc32..f87a0d774fa7c 100644 --- a/src/test/compile-fail/issue-18343.rs +++ b/src/test/compile-fail/issue-18343.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Obj<'a> { - closure: ||: 'a -> u32 +struct Obj where F: FnMut() -> u32 { + closure: F, } fn main() { let o = Obj { closure: || 42 }; - o.closure(); //~ ERROR type `Obj<'_>` does not implement any method in scope named `closure` + o.closure(); //~ ERROR does not implement any method in scope named `closure` //~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field } diff --git a/src/test/compile-fail/issue-18345.rs b/src/test/compile-fail/issue-18345.rs deleted file mode 100644 index e93acb3f064af..0000000000000 --- a/src/test/compile-fail/issue-18345.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 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. - -type Step<'s, R, T> = |R, T|: 's -> R; -type Transducer<'t, R, T, U> = |Step<'t, R, U>|: 't -> Step<'t, R, T>; - -fn mapping<'f, R, T, U>(f: |T|: 'f -> U) -> &'f Transducer<'f, R, T, U> { - |step| |r, x| - step(r, f(x)) - //~^ ERROR the type of this value must be known in this context -} - -fn main() {} diff --git a/src/test/compile-fail/issue-18783.rs b/src/test/compile-fail/issue-18783.rs index 8097d93ca0745..3a0fbddf8185f 100644 --- a/src/test/compile-fail/issue-18783.rs +++ b/src/test/compile-fail/issue-18783.rs @@ -13,8 +13,8 @@ use std::cell::RefCell; fn main() { let c = RefCell::new(vec![]); let mut y = 1u; - c.push(|| y = 0); - c.push(|| y = 0); + c.push(box || y = 0); + c.push(box || y = 0); //~^ ERROR cannot borrow `y` as mutable more than once at a time } @@ -22,16 +22,16 @@ fn ufcs() { let c = RefCell::new(vec![]); let mut y = 1u; - Push::push(&c, || y = 0); - Push::push(&c, || y = 0); + Push::push(&c, box || y = 0); + Push::push(&c, box || y = 0); } trait Push<'c> { - fn push<'f: 'c>(&self, push: ||:'f -> ()); + fn push<'f: 'c>(&self, push: Box); } -impl<'c> Push<'c> for RefCell> { - fn push<'f: 'c>(&self, fun: ||:'f -> ()) { +impl<'c> Push<'c> for RefCell>> { + fn push<'f: 'c>(&self, fun: Box) { self.borrow_mut().push(fun) } } diff --git a/src/test/compile-fail/issue-19009.rs b/src/test/compile-fail/issue-19009.rs deleted file mode 100644 index aa7c4c3060bdb..0000000000000 --- a/src/test/compile-fail/issue-19009.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 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. - -#![feature(lang_items)] -#![no_std] -#![crate_type="rlib"] -#[lang="sized"] pub trait Sized for Sized? {} - -fn ice(f: for <'s> || - :'s //~ ERROR use of undeclared lifetime name `'s` -) {} -fn main() { ice(||{}) } diff --git a/src/test/compile-fail/issue-19141.rs b/src/test/compile-fail/issue-19141.rs deleted file mode 100644 index 545e3f8acb139..0000000000000 --- a/src/test/compile-fail/issue-19141.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2014 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. - -fn main() { - let n = 0u; - - let f = move || n += 1; //~error boxed closures can't capture by value -} diff --git a/src/test/compile-fail/issue-20193.rs b/src/test/compile-fail/issue-20193.rs deleted file mode 100644 index e5d8d3327199b..0000000000000 --- a/src/test/compile-fail/issue-20193.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 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. - -fn foo(t: &mut int){ - println!("{}", t); -} - -fn main() { - let test = 10; - - let h = move || { //~error boxed closures can't capture by value - let mut r = &mut test.clone(); - foo(r); - }; - - h(); -} diff --git a/src/test/compile-fail/issue-20228-1.rs b/src/test/compile-fail/issue-20228-1.rs deleted file mode 100644 index 3ff4557ae80ed..0000000000000 --- a/src/test/compile-fail/issue-20228-1.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 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. - -struct S; - -impl S { - fn foo(&self) { - let _ = move || { self }; //~error boxed closures can't capture by value - } -} - -fn main() { -} diff --git a/src/test/compile-fail/issue-20228-2.rs b/src/test/compile-fail/issue-20228-2.rs deleted file mode 100644 index 5fec4268bf7c2..0000000000000 --- a/src/test/compile-fail/issue-20228-2.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 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. - -struct S; - -impl S { - fn foo(&self) { - let _ = move || { self.foo() }; //~error boxed closures can't capture by value - } -} - -fn main() { -} diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index b688cafb67459..691660f897157 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -9,17 +9,17 @@ // except according to those terms. trait vec_monad { - fn bind(&self, f: |A| -> Vec ); + fn bind(&self, f: F) where F: FnMut(A) -> Vec; } impl vec_monad for Vec { - fn bind(&self, f: |A| -> Vec ) { + fn bind(&self, mut f: F) where F: FnMut(A) -> Vec { let mut r = panic!(); for elt in self.iter() { r = r + f(*elt); } //~^ ERROR the type of this value must be known } } fn main() { - ["hi"].bind(|x| [x] ); + ["hi"].bind(|&mut: x| [x] ); //~^ ERROR type `[&str; 1]` does not implement any method in scope named `bind` } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 0f7cc2cb72b8e..c67d6b1ce8f7c 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -11,7 +11,7 @@ fn main() { let needlesArr: Vec = vec!('a', 'f'); - needlesArr.iter().fold(|x, y| { + needlesArr.iter().fold(|&: x, y| { }); //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied // diff --git a/src/test/compile-fail/issue-3563.rs b/src/test/compile-fail/issue-3563.rs index 38f28bd79dfa1..86ab9be77fc68 100644 --- a/src/test/compile-fail/issue-3563.rs +++ b/src/test/compile-fail/issue-3563.rs @@ -9,8 +9,9 @@ // except according to those terms. trait A { - fn a(&self) { - || self.b() //~ ERROR type `&Self` does not implement any method in scope named `b` - } + fn a(&self) { + |&:| self.b() //~ ERROR type `&Self` does not implement any method in scope named `b` + //~^ ERROR expected (), found closure + } } fn main() {} diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index eadd16348b2e8..d4f9ea5b276f9 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(unboxed_closures)] + fn id(t: T) -> T { t } -fn f<'r, T>(v: &'r T) -> ||: 'r -> T { - id(|| *v) //~ ERROR cannot infer +fn f<'r, T>(v: &'r T) -> Box T + 'r> { + id(box |&mut:| *v) //~ ERROR cannot infer } fn main() { let v = &5i; - println!("{}", f(v)()); + println!("{}", f(v).call_mut(())); } diff --git a/src/test/compile-fail/issue-4523.rs b/src/test/compile-fail/issue-4523.rs deleted file mode 100644 index 5063a78e38348..0000000000000 --- a/src/test/compile-fail/issue-4523.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 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. - -fn foopy() {} - -static f: ||: 'static = foopy; - -fn main () { - f(); //~ ERROR closure invocation in a static location -} diff --git a/src/test/compile-fail/issue-5216.rs b/src/test/compile-fail/issue-5216.rs index 18af9736ed9f8..fef414ce978a8 100644 --- a/src/test/compile-fail/issue-5216.rs +++ b/src/test/compile-fail/issue-5216.rs @@ -9,12 +9,12 @@ // except according to those terms. fn f() { } -struct S(||); //~ ERROR explicit lifetime bound required +struct S(Box); //~ ERROR explicit lifetime bound required pub static C: S = S(f); fn g() { } -type T = ||; //~ ERROR explicit lifetime bound required +type T = Box; //~ ERROR explicit lifetime bound required pub static D: T = g; fn main() {} diff --git a/src/test/compile-fail/issue-5239-1.rs b/src/test/compile-fail/issue-5239-1.rs index 88b08655caad2..1691688fd8464 100644 --- a/src/test/compile-fail/issue-5239-1.rs +++ b/src/test/compile-fail/issue-5239-1.rs @@ -11,6 +11,6 @@ // Regression test for issue #5239 fn main() { - let x: |int| -> int = |ref x| { x += 1; }; + let x = |&: ref x: int| -> int { x += 1; }; //~^ ERROR binary assignment operation `+=` cannot be applied to type `&int` } diff --git a/src/test/compile-fail/issue-6801.rs b/src/test/compile-fail/issue-6801.rs index 5925f6869391a..433ae3bf89e03 100644 --- a/src/test/compile-fail/issue-6801.rs +++ b/src/test/compile-fail/issue-6801.rs @@ -17,13 +17,13 @@ fn twice(x: Box) -> uint { *x * 2 } -fn invoke(f: || -> uint) { +fn invoke(f: F) where F: FnOnce() -> uint { f(); } fn main() { let x : Box = box 9; - let sq : || -> uint = || { *x * *x }; + let sq = |:| { *x * *x }; twice(x); //~ ERROR: cannot move out of invoke(sq); diff --git a/src/test/compile-fail/issue-7573.rs b/src/test/compile-fail/issue-7573.rs index 0e978a09edd2d..897afb1c10245 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -25,7 +25,7 @@ impl CrateId { pub fn remove_package_from_database() { let mut lines_to_use: Vec<&CrateId> = Vec::new(); - let push_id = |installed_id: &CrateId| { + let push_id = |&mut: installed_id: &CrateId| { lines_to_use.push(installed_id); //~^ ERROR cannot infer an appropriate lifetime for automatic coercion due to // conflicting requirements @@ -38,7 +38,7 @@ pub fn remove_package_from_database() { } -pub fn list_database(f: |&CrateId|) { +pub fn list_database(mut f: F) where F: FnMut(&CrateId) { let stuff = ["foo", "bar"]; for l in stuff.iter() { diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index 8868c7f8256da..b5725249812f6 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -57,9 +57,6 @@ fn test<'a,T,U:Copy>(_: &'a int) { // mutable object types are not ok assert_copy::<&'a mut (Dummy+Copy)>(); //~ ERROR `core::kinds::Copy` is not implemented - // closures are like an `&mut` object - assert_copy::<||>(); //~ ERROR `core::kinds::Copy` is not implemented - // unsafe ptrs are ok assert_copy::<*const int>(); assert_copy::<*const &'a mut int>(); diff --git a/src/test/compile-fail/kindck-send-object.rs b/src/test/compile-fail/kindck-send-object.rs index 3b67e98f42ca8..c300096caf1e0 100644 --- a/src/test/compile-fail/kindck-send-object.rs +++ b/src/test/compile-fail/kindck-send-object.rs @@ -27,14 +27,9 @@ fn box_object_with_no_bound_not_ok<'a>() { assert_send::>(); //~ ERROR the trait `core::kinds::Send` is not implemented } -fn closure_with_no_bound_not_ok<'a>() { - assert_send::<||:'static>(); //~ ERROR the trait `core::kinds::Send` is not implemented -} - fn object_with_send_bound_ok() { assert_send::<&'static (Dummy+Send)>(); assert_send::>(); - assert_send::<||:Send>; } fn main() { } diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 29b4686198be1..7513e1bc21a4a 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -35,7 +35,7 @@ fn main() { _ => {} } - let x = |mut y: int| 10i; //~ ERROR: variable does not need to be mutable + let x = |&: mut y: int| 10i; //~ ERROR: variable does not need to be mutable fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable // positive cases @@ -65,7 +65,7 @@ fn main() { _ => {} } - let x = |mut y: int| y = 32i; + let x = |&mut: mut y: int| y = 32i; fn nothing(mut foo: int) { foo = 37i; } // leading underscore should avoid the warning, just like the @@ -73,7 +73,7 @@ fn main() { let mut _allowed = 1i; } -fn callback(f: ||) {} +fn callback(f: F) where F: FnOnce() {} // make sure the lint attribute can be turned off #[allow(unused_mut)] diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index df3feefa881f3..5c8e73e674751 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -20,7 +20,7 @@ mod foo { } } -fn callback(_f: || -> T) -> T { panic!() } +fn callback(_f: F) -> T where F: FnOnce() -> T { panic!() } unsafe fn unsf() {} fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block diff --git a/src/test/compile-fail/liveness-closure-require-ret.rs b/src/test/compile-fail/liveness-closure-require-ret.rs index 6466310eb4d2e..82de02f09813c 100644 --- a/src/test/compile-fail/liveness-closure-require-ret.rs +++ b/src/test/compile-fail/liveness-closure-require-ret.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: || -> int) -> int { f() } +fn force(f: F) -> int where F: FnOnce() -> int { f() } fn main() { println!("{}", force(|| {})); } //~ ERROR mismatched types diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index ee57377943d12..14af49dfc49c5 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -20,7 +20,7 @@ enum E { Baz } -fn f(s: &S, g: |&S|) { +fn f(s: &S, g: G) where G: FnOnce(&S) { g(s) } diff --git a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs index f9614574abda9..ab762332ee43d 100644 --- a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs +++ b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs @@ -14,5 +14,5 @@ fn test(_x: Box) {} fn main() { let i = box 3; - let _f = || test(i); //~ ERROR cannot move out + let _f = |&:| test(i); //~ ERROR cannot move out } diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index 2a73b769895ee..787e25ea31954 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -12,11 +12,13 @@ // bound must be noncopyable. For details see // http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/ +#![feature(unboxed_closures)] + struct R<'a> { // This struct is needed to create the // otherwise infinite type of a fn that // accepts itself as argument: - c: |&mut R, bool|: 'a + c: Box } fn innocent_looking_victim() { @@ -27,8 +29,8 @@ fn innocent_looking_victim() { } else { match x { Some(ref msg) => { - (f.c)(f, true); - //~^ ERROR: cannot borrow `*f` as mutable because + f.c.call_mut((f, true)); + //~^ ERROR: cannot borrow `*f` as mutable more than once at a time println!("{}", msg); }, None => panic!("oops"), @@ -37,8 +39,8 @@ fn innocent_looking_victim() { }) } -fn conspirator(f: |&mut R, bool|) { - let mut r = R {c: f}; +fn conspirator(mut f: F) where F: FnMut(&mut R, bool) { + let mut r = R {c: box f}; f(&mut r, false) //~ ERROR use of moved value } diff --git a/src/test/compile-fail/pptypedef.rs b/src/test/compile-fail/pptypedef.rs index 4de56e32f560a..ebda4e9103d60 100644 --- a/src/test/compile-fail/pptypedef.rs +++ b/src/test/compile-fail/pptypedef.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn let_in(x: T, f: |T|) {} +fn let_in(x: T, f: F) where F: FnOnce(T) {} fn main() { let_in(3u, |i| { assert!(i == 3i); }); diff --git a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs index 954d4b23e30fa..575e9864a92d3 100644 --- a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs +++ b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let f = |3: int| println!("hello"); + let f = |&: 3: int| println!("hello"); //~^ ERROR refutable pattern in function argument: `_` not covered f(4); } diff --git a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs index 13ab7acaf4835..9e8281faf2f56 100644 --- a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs +++ b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn call_rec(f: |uint| -> uint) -> uint { - (|x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f` +fn call_rec(mut f: F) -> uint where F: FnMut(uint) -> uint { + (|&mut: x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f` } fn main() {} diff --git a/src/test/compile-fail/regionck-closure-lifetimes.rs b/src/test/compile-fail/regionck-closure-lifetimes.rs deleted file mode 100644 index bb895a318ff17..0000000000000 --- a/src/test/compile-fail/regionck-closure-lifetimes.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2013 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. - -fn env<'a>(blk: |p: ||: 'a|) { - // Test that the closure here cannot be assigned - // the lifetime `'a`, which outlives the current - // block. - - let mut state = 0i; - let statep = &mut state; - blk(|| *statep = 1i); //~ ERROR captured variable `statep` does not outlive -} - -fn no_env_no_for<'a>(blk: |p: |||: 'a) { - // Test that a closure with no free variables CAN - // outlive the block in which it is created. - - blk(|| ()) -} - -fn repeating_loop() { - // Test that the closure cannot be created within `loop` loop and - // called without, even though the state that it closes over is - // external to the loop. - - let closure; - let state = 0i; - - loop { - closure = || state; //~ ERROR cannot infer - break; - } - - closure(); -} - -fn repeating_while() { - // Test that the closure cannot be created within `while` loop and - // called without, even though the state that it closes over is - // external to the loop. - - let closure; - let state = 0i; - - while true { - closure = || state; //~ ERROR cannot infer - break; - } - - closure(); -} - -fn main() {} diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index 7a146c043c838..fb60d8f7b27a4 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -16,7 +16,7 @@ struct dog { impl dog { pub fn chase_cat(&mut self) { - let _f = || { + let _f = |&:| { let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer *p = 3u; }; diff --git a/src/test/compile-fail/regions-bounded-by-send.rs b/src/test/compile-fail/regions-bounded-by-send.rs index e15cb25295aac..0628bbb8bb08e 100644 --- a/src/test/compile-fail/regions-bounded-by-send.rs +++ b/src/test/compile-fail/regions-bounded-by-send.rs @@ -69,11 +69,6 @@ fn object_with_send_bound_not_ok<'a>() { //~^ ERROR declared lifetime bound not satisfied } -fn closure_with_lifetime_not_ok<'a>() { - assert_send::<||:'a>(); - //~^ ERROR not implemented -} - // unsafe pointers are ok unless they point at unsendable things struct UniqueUnsafePtr(Unique<*const int>); diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index b15f0405d23c6..1774c9fada946 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -27,14 +27,14 @@ fn compute(x: &ast) -> uint { } } -fn map_nums<'a,'b>(x: &ast, f: |uint| -> uint) -> &'a ast<'b> { +fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(uint) -> uint { match *x { ast::num(x) => { - return &ast::num(f(x)); //~ ERROR borrowed value does not live long enough + return &ast::num((*f)(x)); //~ ERROR borrowed value does not live long enough } ast::add(x, y) => { - let m_x = map_nums(x, |z| f(z)); - let m_y = map_nums(y, |z| f(z)); + let m_x = map_nums(x, f); + let m_y = map_nums(y, f); return &ast::add(m_x, m_y); //~ ERROR borrowed value does not live long enough } } diff --git a/src/test/compile-fail/regions-escape-bound-fn-2.rs b/src/test/compile-fail/regions-escape-bound-fn-2.rs index 66103eb95888a..547accbf0860d 100644 --- a/src/test/compile-fail/regions-escape-bound-fn-2.rs +++ b/src/test/compile-fail/regions-escape-bound-fn-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: |x: &int|) { +fn with_int(f: F) where F: FnOnce(&int) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-bound-fn.rs b/src/test/compile-fail/regions-escape-bound-fn.rs index fee84cf9656d1..6d67bd80650fa 100644 --- a/src/test/compile-fail/regions-escape-bound-fn.rs +++ b/src/test/compile-fail/regions-escape-bound-fn.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: |x: &int|) { +fn with_int(f: F) where F: FnOnce(&int) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-method.rs b/src/test/compile-fail/regions-escape-method.rs index f92c264784ae6..e3771cfebba25 100644 --- a/src/test/compile-fail/regions-escape-method.rs +++ b/src/test/compile-fail/regions-escape-method.rs @@ -16,7 +16,7 @@ struct S; impl S { - fn f(&self, _: |&i32| -> B) { + fn f(&self, _: F) where F: FnOnce(&i32) -> B { } } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index adc960b069d05..873d4cea0395e 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -20,7 +20,7 @@ impl<'a> Deref for &'a int { } } -fn with(f: |x: &int| -> R) -> int { +fn with(f: F) -> int where F: FnOnce(&int) -> R { f(&3).get() } diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs deleted file mode 100644 index 91a6ff789ea39..0000000000000 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2012 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. - -fn of<'a,T>() -> |T|:'a { panic!(); } -fn subtype(x: |T|) { panic!(); } - -fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) { - // Here, x, y, and z are free. Other letters - // are bound. Note that the arrangement - // subtype::(of::()) will typecheck - // iff T1 <: T2. - - subtype::< for<'a>|&'a T|>( - of::< for<'a>|&'a T|>()); - - subtype::< for<'a>|&'a T|>( - of::< for<'b>|&'b T|>()); - - subtype::< for<'b>|&'b T|>( - of::<|&'x T|>()); - - subtype::<|&'x T|>( - of::< for<'b>|&'b T|>()); //~ ERROR mismatched types - - subtype::< for<'a,'b>|&'a T, &'b T|>( - of::< for<'a>|&'a T, &'a T|>()); - - subtype::< for<'a>|&'a T, &'a T|>( - of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types - - subtype::< for<'a,'b>|&'a T, &'b T|>( - of::<|&'x T, &'y T|>()); - - subtype::<|&'x T, &'y T|>( - of::< for<'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types -} - -fn main() {} diff --git a/src/test/compile-fail/regions-fns.rs b/src/test/compile-fail/regions-fns.rs deleted file mode 100644 index 854584ec535e6..0000000000000 --- a/src/test/compile-fail/regions-fns.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 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. - -// Before fn subtyping was properly implemented, -// we reported errors in this case: - -fn not_ok<'b>(a: &uint, b: &'b uint) { - let mut g: |x: &uint| = |x: &'b uint| {}; - //~^ ERROR mismatched types - g(a); -} - -fn main() { -} diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index 435d10a0a29a1..6e59a29b8cf22 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -30,7 +30,7 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint { panic!(); } -fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: |&'a &'b uint|) { +fn ordering4<'a, 'b, F>(a: &'a uint, b: &'b uint, x: F) where F: FnOnce(&'a &'b uint) { // Do not infer ordering from closure argument types. let z: Option<&'a &'b uint> = None; //~^ ERROR reference has a longer lifetime than the data it references diff --git a/src/test/compile-fail/regions-freevar.rs b/src/test/compile-fail/regions-freevar.rs deleted file mode 100644 index 76bbe71cf75b5..0000000000000 --- a/src/test/compile-fail/regions-freevar.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2012 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. - -fn wants_static_fn(_x: ||: 'static) {} - -fn main() { - let i = 3i; - wants_static_fn(|| { - println!("i={}", i); //~ ERROR captured variable `i` does not outlive - }) -} diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs index 8af341e3ace42..0c250e38258ce 100644 --- a/src/test/compile-fail/regions-infer-at-fn-not-param.rs +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -9,15 +9,15 @@ // except according to those terms. struct parameterized1<'a> { - g: ||: 'a + g: Box } struct not_parameterized1 { - g: ||: 'static + g: Box } struct not_parameterized2 { - g: ||: 'static + g: Box } fn take1<'a>(p: parameterized1) -> parameterized1<'a> { p } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index cf1fa2cfc4c2c..c8edd936bf28b 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -11,7 +11,10 @@ fn borrow(x: &T) -> &T {x} -fn foo(cond: || -> bool, make_box: || -> Box) { +fn foo(mut cond: C, mut make_box: M) where + C: FnMut() -> bool, + M: FnMut() -> Box, +{ let mut y: ∫ loop { let x = make_box(); diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index 66f958c789336..ac41f2a5b3e47 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -10,7 +10,7 @@ fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x } -fn with(f: |x: &int| -> T) -> T { +fn with(f: F) -> T where F: FnOnce(&int) -> T { f(&20) } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs index 33573cae0f66d..190e444fe7e83 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: |x: &mut &'a int|: 'static + f: Box, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs index 66dcb5fdebd2d..71d0c988c5e27 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: ||: 'static -> &mut &'a int + f: Box FnOnce() -> &'b mut &'a int + 'static>, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index b84f13ec37feb..323ebc3c20b37 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -14,12 +14,12 @@ struct direct<'a> { struct indirect1 { // Here the lifetime parameter of direct is bound by the fn() - g: |direct|: 'static + g: Box } struct indirect2<'a> { // But here it is set to 'a - g: |direct<'a>|: 'static + g: Box) + 'static> } fn take_direct<'a,'b>(p: direct<'a>) -> direct<'b> { p } //~ ERROR mismatched types diff --git a/src/test/compile-fail/regions-name-undeclared.rs b/src/test/compile-fail/regions-name-undeclared.rs index ffd1501075e94..b9c721159f2b4 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -43,19 +43,16 @@ fn bar<'a>(x: &'a int) { // &'a CAN be declared on functions and used then: fn g<'a>(a: &'a int) { } // OK - fn h(a: for<'a>|&'a int|) { } // OK - - // But not in the bound of a closure, it's not in scope *there* - fn i(a: for<'a>|&int|:'a) { } //~ ERROR undeclared lifetime + fn h(a: Box FnOnce(&'a int)>) { } // OK } // Test nesting of lifetimes in fn type declarations fn fn_types(a: &'a int, //~ ERROR undeclared lifetime - b: for<'a>|a: &'a int, - b: &'b int, //~ ERROR undeclared lifetime - c: for<'b>|a: &'a int, - b: &'b int|, - d: &'b int|, //~ ERROR undeclared lifetime + b: Box FnOnce(&'a int, + &'b int, //~ ERROR undeclared lifetime + Box FnOnce(&'a int, + &'b int)>, + &'b int)>, //~ ERROR undeclared lifetime c: &'a int) //~ ERROR undeclared lifetime { } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index a08cf2263894d..b7fe893a1f5bb 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ignore(_f: for<'z>|&'z int| -> &'z int) {} +fn ignore(_f: F) where F: for<'z> FnOnce(&'z int) -> &'z int {} fn nested() { let y = 3; diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index f4654367970d1..5d8ef718ef0d3 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) { let y = 3; let mut ay = &y; - ignore::< for<'z>|&'z int|>(|z| { + ignore:: FnMut(&'z int)>>(box |z| { ay = x; //~ ERROR cannot infer ay = &y; ay = z; }); - ignore::< for<'z>|&'z int| -> &'z int>(|z| { + ignore::< Box FnMut(&'z int) -> &'z int>>(box |z| { if false { return x; } //~ ERROR cannot infer an appropriate lifetime for automatic if false { return ay; } return z; diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index 47fca8bb8df23..f9eecb60c6af1 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -13,7 +13,7 @@ fn arg_item(box ref x: Box) -> &'static int { x //~^ ERROR borrowed value does not live long enough } -fn with(f: |Box| -> R) -> R { f(box 3) } +fn with(f: F) -> R where F: FnOnce(Box) -> R { f(box 3) } fn arg_closure() -> &'static int { with(|box ref x| x) //~ ERROR borrowed value does not live long enough diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index 997775efa84b5..bd14d31217e88 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,7 +12,7 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with(f: for<'a>|x: &'a int| -> R) -> R { +fn with(f: F) -> R where F: for<'a> FnOnce(&'a int) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index 465f4410fbbcc..4dfd4f1709a6f 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -15,7 +15,7 @@ // used to successfully compile because we failed to account for the // fact that fn(x: &int) rebound the region &. -fn with(f: |x: &int| -> R) -> R { +fn with(f: F) -> R where F: FnOnce(&int) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs index aedaced5794a7..d7b2a45cc63bb 100644 --- a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs +++ b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs @@ -20,11 +20,4 @@ fn main() { let x = f(); let y = f(); } - // Boxed closure case - { - let mut x = 0u; - let f = || &mut x; //~ ERROR cannot infer - let x = f(); - let y = f(); - } } diff --git a/src/test/compile-fail/regions-steal-closure.rs b/src/test/compile-fail/regions-steal-closure.rs index 7ffc6a75cff8c..991040bc62fea 100644 --- a/src/test/compile-fail/regions-steal-closure.rs +++ b/src/test/compile-fail/regions-steal-closure.rs @@ -8,18 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(unboxed_closures)] + struct closure_box<'a> { - cl: ||: 'a + cl: Box, } -fn box_it<'r>(x: ||: 'r) -> closure_box<'r> { +fn box_it<'r>(x: Box) -> closure_box<'r> { closure_box {cl: x} } fn main() { let cl_box = { - let mut i = 3; - box_it(|| i += 1) //~ ERROR cannot infer + let mut i = 3i; + box_it(box || i += 1) //~ ERROR cannot infer }; - (cl_box.cl)(); + cl_box.cl.call_mut(()); } diff --git a/src/test/compile-fail/type-arg-out-of-scope.rs b/src/test/compile-fail/type-arg-out-of-scope.rs index ac2f9d0379f64..3249794e5c822 100644 --- a/src/test/compile-fail/type-arg-out-of-scope.rs +++ b/src/test/compile-fail/type-arg-out-of-scope.rs @@ -10,6 +10,6 @@ // error-pattern:can't use type parameters from outer function; try using fn foo(x: T) { - fn bar(f: |T| -> T) { } + fn bar(f: Box T>) { } } fn main() { foo(1); } From d6a948e8f40b1d32d4760e0dfdc0c86df654cae6 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Jan 2015 23:33:35 -0500 Subject: [PATCH 26/37] fix run-make test --- src/test/run-make/static-unwinding/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/static-unwinding/lib.rs b/src/test/run-make/static-unwinding/lib.rs index 5e75e1cd1cbdc..c3fa1a68e164c 100644 --- a/src/test/run-make/static-unwinding/lib.rs +++ b/src/test/run-make/static-unwinding/lib.rs @@ -19,7 +19,7 @@ impl Drop for A { } } -pub fn callback(f: ||) { +pub fn callback(f: F) where F: FnOnce() { let _a = A; f(); } From 1bbeb375821fe197342f1e22ab53b796bb0f0c70 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 08:22:04 -0500 Subject: [PATCH 27/37] fix pretty tests --- src/test/pretty/closure-reform-pretty.rs | 4 ++-- src/test/pretty/disamb-stmt-expr.rs | 2 +- src/test/pretty/do1.rs | 2 +- src/test/pretty/fn-types.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/pretty/closure-reform-pretty.rs b/src/test/pretty/closure-reform-pretty.rs index 328d4245eb610..094e3ce915686 100644 --- a/src/test/pretty/closure-reform-pretty.rs +++ b/src/test/pretty/closure-reform-pretty.rs @@ -15,9 +15,9 @@ fn call_it(f: Box String>) { } -fn call_this(f: |&str|: Send) { } +fn call_this(f: F) where F: Fn(&str) + Send { } -fn call_that(f: <'a>|&'a int, &'a int| -> int) { } +fn call_that(f: F) where F: for<'a>Fn(&'a int, &'a int) -> int { } fn call_extern(f: fn() -> int) { } diff --git a/src/test/pretty/disamb-stmt-expr.rs b/src/test/pretty/disamb-stmt-expr.rs index 78658a4c12169..0c4cd103b82ef 100644 --- a/src/test/pretty/disamb-stmt-expr.rs +++ b/src/test/pretty/disamb-stmt-expr.rs @@ -14,7 +14,7 @@ // preserved. They are needed to disambiguate `{return n+1}; - 0` from // `({return n+1}-0)`. -fn id(f: || -> int) -> int { f() } +fn id(f: F) -> int where F: Fn() -> int { f() } fn wsucc(_n: int) -> int { id(|| { 1 }) - 0 } fn main() { } diff --git a/src/test/pretty/do1.rs b/src/test/pretty/do1.rs index cd7a5b29a8af1..e0066053f3c5b 100644 --- a/src/test/pretty/do1.rs +++ b/src/test/pretty/do1.rs @@ -10,6 +10,6 @@ // pp-exact -fn f(f: |int|) { f(10) } +fn f(f: F) where F: Fn(int) { f(10) } fn main() { f(|i| { assert!(i == 10) }) } diff --git a/src/test/pretty/fn-types.rs b/src/test/pretty/fn-types.rs index 1313af2df3d88..31efb0c9ab1eb 100644 --- a/src/test/pretty/fn-types.rs +++ b/src/test/pretty/fn-types.rs @@ -11,5 +11,5 @@ // pp-exact fn from_foreign_fn(_x: fn()) { } -fn from_stack_closure(_x: ||) { } +fn from_stack_closure(_x: F) where F: Fn() { } fn main() { } From ef726591f81238f19bfd4cc3b48d812d20dbfcc2 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 08:23:17 -0500 Subject: [PATCH 28/37] fix debuginfo tests --- src/test/debuginfo/closure-in-generic-function.rs | 2 +- .../lexical-scope-in-parameterless-closure.rs | 2 +- src/test/debuginfo/lexical-scope-in-stack-closure.rs | 4 ++-- src/test/debuginfo/multi-byte-chars.rs | 2 +- src/test/debuginfo/recursive-enum.rs | 4 +--- src/test/debuginfo/type-names.rs | 12 ++++++------ src/test/debuginfo/var-captured-in-nested-closure.rs | 4 ++-- src/test/debuginfo/var-captured-in-stack-closure.rs | 8 ++++---- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/test/debuginfo/closure-in-generic-function.rs b/src/test/debuginfo/closure-in-generic-function.rs index 84366ae711465..e3cb190c3f2c4 100644 --- a/src/test/debuginfo/closure-in-generic-function.rs +++ b/src/test/debuginfo/closure-in-generic-function.rs @@ -50,7 +50,7 @@ fn some_generic_fun(a: T1, b: T2) -> (T2, T1) { - let closure = |x, y| { + let closure = |&: x, y| { zzz(); // #break (y, x) }; diff --git a/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs b/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs index b451f61d05e0e..b2617c5774252 100644 --- a/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs +++ b/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs @@ -18,7 +18,7 @@ // Nothing to do here really, just make sure it compiles. See issue #8513. fn main() { - let _ = ||(); + let _ = |&:|(); let _ = range(1u,3).map(|_| 5i); } diff --git a/src/test/debuginfo/lexical-scope-in-stack-closure.rs b/src/test/debuginfo/lexical-scope-in-stack-closure.rs index d6e3a43eea0a6..f2d092216697f 100644 --- a/src/test/debuginfo/lexical-scope-in-stack-closure.rs +++ b/src/test/debuginfo/lexical-scope-in-stack-closure.rs @@ -79,7 +79,7 @@ fn main() { zzz(); // #break sentinel(); - let stack_closure: |int| = |x| { + let closure = |&: x: int| { zzz(); // #break sentinel(); @@ -97,7 +97,7 @@ fn main() { zzz(); // #break sentinel(); - stack_closure(1000); + closure(1000); zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/multi-byte-chars.rs b/src/test/debuginfo/multi-byte-chars.rs index dd0d86bf742e6..cb7e26327c3de 100644 --- a/src/test/debuginfo/multi-byte-chars.rs +++ b/src/test/debuginfo/multi-byte-chars.rs @@ -24,5 +24,5 @@ struct C { θ: u8 } fn main() { let x = C { θ: 0 }; - (|c: C| c.θ )(x); + (|&: c: C| c.θ )(x); } diff --git a/src/test/debuginfo/recursive-enum.rs b/src/test/debuginfo/recursive-enum.rs index 93348e7b53e55..73a68893e933c 100644 --- a/src/test/debuginfo/recursive-enum.rs +++ b/src/test/debuginfo/recursive-enum.rs @@ -25,11 +25,9 @@ pub struct Window<'a> { } struct WindowCallbacks<'a> { - pos_callback: Option>, + pos_callback: Option>, } -pub type WindowPosCallback<'a> = |&Window, i32, i32|: 'a; - fn main() { let x = WindowCallbacks { pos_callback: None }; } diff --git a/src/test/debuginfo/type-names.rs b/src/test/debuginfo/type-names.rs index ddcbfdcceee01..aac5824af0050 100644 --- a/src/test/debuginfo/type-names.rs +++ b/src/test/debuginfo/type-names.rs @@ -167,11 +167,11 @@ // CLOSURES -// gdb-command:whatis stack_closure1 -// gdb-check:type = struct (&mut|int|, uint) +// gdb-command:whatis closure1 +// gdb-check:type = struct (closure, uint) -// gdb-command:whatis stack_closure2 -// gdb-check:type = struct (&mut|i8, f32| -> f32, uint) +// gdb-command:whatis closure2 +// gdb-check:type = struct (closure, uint) #![omit_gdb_pretty_printer_section] @@ -321,8 +321,8 @@ fn main() { // how that maps to rustc's internal representation of these forms. // Once closures have reached their 1.0 form, the tests below should // probably be expanded. - let stack_closure1 = (|x:int| {}, 0u); - let stack_closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0u); + let closure1 = (|&: x:int| {}, 0u); + let closure2 = (|&: x:i8, y: f32| { (x as f32) + y }, 0u); zzz(); // #break } diff --git a/src/test/debuginfo/var-captured-in-nested-closure.rs b/src/test/debuginfo/var-captured-in-nested-closure.rs index 99d67c60516b5..3a7fbb9a3a132 100644 --- a/src/test/debuginfo/var-captured-in-nested-closure.rs +++ b/src/test/debuginfo/var-captured-in-nested-closure.rs @@ -100,10 +100,10 @@ fn main() { let struct_ref = &a_struct; let owned = box 6; - let closure = || { + let mut closure = |&mut:| { let closure_local = 8; - let nested_closure = || { + let mut nested_closure = |&mut:| { zzz(); // #break variable = constant + a_struct.a + struct_ref.a + *owned + closure_local; }; diff --git a/src/test/debuginfo/var-captured-in-stack-closure.rs b/src/test/debuginfo/var-captured-in-stack-closure.rs index f474e8d131799..a743adae51e9c 100644 --- a/src/test/debuginfo/var-captured-in-stack-closure.rs +++ b/src/test/debuginfo/var-captured-in-stack-closure.rs @@ -94,20 +94,20 @@ fn main() { let owned = box 6; { - let closure = || { + let mut first_closure = |&mut:| { zzz(); // #break variable = constant + a_struct.a + struct_ref.a + *owned; }; - closure(); + first_closure(); } { - let mut unboxed_closure = |&mut:| { + let mut second_closure = |&mut:| { zzz(); // #break variable = constant + a_struct.a + struct_ref.a + *owned; }; - unboxed_closure(); + second_closure(); } } From a9ea4d0127baf913cd1831b2fa1d527aaadf6ba9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 08:23:55 -0500 Subject: [PATCH 29/37] fix benchmarks --- src/test/bench/core-set.rs | 11 +++++++---- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +++- src/test/bench/shootout-meteor.rs | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 491d910f3517d..1dcac9fe0742d 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -61,12 +61,14 @@ impl MutableSet for BitvSet { impl Results { pub fn bench_int, - R: rand::Rng>( + R:rand::Rng, + F:FnMut() -> T>( &mut self, rng: &mut R, num_keys: uint, rand_cap: uint, - f: || -> T) { { + mut f: F) { + { let mut set = f(); timed(&mut self.sequential_ints, || { for i in range(0u, num_keys) { @@ -103,11 +105,12 @@ impl Results { } pub fn bench_str, - R:rand::Rng>( + R:rand::Rng, + F:FnMut() -> T>( &mut self, rng: &mut R, num_keys: uint, - f: || -> T) { + mut f: F) { { let mut set = f(); timed(&mut self.sequential_strings, || { diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 8c0ec667332d3..e6ef6a8c8c9ec 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -94,7 +94,9 @@ fn update_freq(mm: &mut HashMap , uint>, key: &[u8]) { // given a Vec, for each window call a function // i.e., for "hello" and windows of size four, // run it("hell") and it("ello"), then return "llo" -fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec { +fn windows_with_carry(bb: &[u8], nn: uint, mut it: F) -> Vec where + F: FnMut(&[u8]), +{ let mut ii = 0u; let len = bb.len(); diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 438775d8ba0a4..cdc7617fec8b0 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -53,14 +53,14 @@ use std::thread::Thread; // returns an infinite iterator of repeated applications of f to x, // i.e. [x, f(x), f(f(x)), ...], as haskell iterate function. -fn iterate<'a, T>(x: T, f: |&T|: 'a -> T) -> Iterate<'a, T> { +fn iterate(x: T, f: F) -> Iterate where F: FnMut(&T) -> T { Iterate {f: f, next: x} } -struct Iterate<'a, T> { - f: |&T|: 'a -> T, +struct Iterate where F: FnMut(&T) -> T { + f: F, next: T } -impl<'a, T> Iterator for Iterate<'a, T> { +impl Iterator for Iterate where F: FnMut(&T) -> T { type Item = T; fn next(&mut self) -> Option { From ab0c7af376c612374226c83d82e6387eb7cc9666 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 08:25:55 -0500 Subject: [PATCH 30/37] ignore boxed closure doctests in the guide/reference --- src/doc/guide-testing.md | 4 ++-- src/doc/guide.md | 20 ++++++++++---------- src/doc/reference.md | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/doc/guide-testing.md b/src/doc/guide-testing.md index 682c89fcc53fc..dea861ad94604 100644 --- a/src/doc/guide-testing.md +++ b/src/doc/guide-testing.md @@ -536,7 +536,7 @@ optimizer to consider the result used and ensures it cannot remove the computation entirely. This could be done for the example above by adjusting the `b.iter` call to -```rust +```{rust,ignore} # struct X; impl X { fn iter(&self, _: || -> T) {} } let b = X; b.iter(|| { // note lack of `;` (could also use an explicit `return`). @@ -548,7 +548,7 @@ Or, the other option is to call the generic `test::black_box` function, which is an opaque "black box" to the optimizer and so forces it to consider any argument as used. -```rust +```{rust,ignore} extern crate test; # fn main() { diff --git a/src/doc/guide.md b/src/doc/guide.md index 2376a9cd2101c..9bd17ec333258 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -4231,7 +4231,7 @@ arguments, really powerful things are possible. Let's make a closure: -```{rust} +```{rust,ignore} let add_one = |x| { 1 + x }; println!("The sum of 5 plus 1 is {}.", add_one(5)); @@ -4243,7 +4243,7 @@ binding name and two parentheses, just like we would for a named function. Let's compare syntax. The two are pretty close: -```{rust} +```{rust,ignore} let add_one = |x: i32| -> i32 { 1 + x }; fn add_one (x: i32) -> i32 { 1 + x } ``` @@ -4256,7 +4256,7 @@ There's one big difference between a closure and named functions, and it's in the name: a closure "closes over its environment." What does that mean? It means this: -```{rust} +```{rust,ignore} fn main() { let x = 5; @@ -4297,7 +4297,7 @@ now. We'll talk about them more in the "Threads" section of the guide. Closures are most useful as an argument to another function. Here's an example: -```{rust} +```{rust,ignore} fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } @@ -4311,14 +4311,14 @@ fn main() { Let's break the example down, starting with `main`: -```{rust} +```{rust,ignore} let square = |x: i32| { x * x }; ``` We've seen this before. We make a closure that takes an integer, and returns its square. -```{rust} +```{rust,ignore} # fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } # let square = |x: i32| { x * x }; twice(5, square); // evaluates to 50 @@ -4342,7 +4342,7 @@ though, and that function takes an `i32` and returns an `i32`. Notice how the `|i32| -> i32` syntax looks a lot like our definition of `square` above, if we added the return type in: -```{rust} +```{rust,ignore} let square = |x: i32| -> i32 { x * x }; // |i32| -> i32 ``` @@ -4357,7 +4357,7 @@ Finally, `twice` returns an `i32` as well. Okay, let's look at the body of `twice`: -```{rust} +```{rust,ignore} fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } @@ -4375,7 +4375,7 @@ this technique a lot. If we didn't want to give `square` a name, we could just define it inline. This example is the same as the previous one: -```{rust} +```{rust,ignore} fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } @@ -4388,7 +4388,7 @@ fn main() { A named function's name can be used wherever you'd use a closure. Another way of writing the previous example: -```{rust} +```{rust,ignore} fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } diff --git a/src/doc/reference.md b/src/doc/reference.md index d793028526052..512081ac48f4d 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1559,7 +1559,7 @@ Type parameters can be specified for a trait to make it generic. These appear after the trait name, using the same syntax used in [generic functions](#generic-functions). -``` +``` ignore trait Seq { fn len(&self) -> uint; fn elt_at(&self, n: uint) -> T; @@ -3217,7 +3217,7 @@ expression's captured environment. In this example, we define a function `ten_times` that takes a higher-order function argument, and call it with a lambda expression as an argument. -``` +``` ignore fn ten_times(f: |int|) { let mut i = 0; while i < 10 { @@ -3821,7 +3821,7 @@ or `extern`), a sequence of input types and an output type. An example of a `fn` type: -``` +``` ignore fn add(x: int, y: int) -> int { return x + y; } @@ -3849,7 +3849,7 @@ The type of a closure mapping an input of type `A` to an output of type `B` is An example of creating and calling a closure: -```rust +``` ignore let captured_var = 10i; let closure_no_args = || println!("captured_var={}", captured_var); From 79af27762324f28ab13335864111071b8708ea39 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 12:07:49 -0500 Subject: [PATCH 31/37] address Niko's comments --- src/librustc_typeck/check/closure.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 7671ad36971ac..9945e264bfc2a 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -45,14 +45,14 @@ pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, // that, otherwise we'll fall back to boxed closures. match expected_sig_and_kind { None => { // don't have information about the kind, request explicit annotation - // HACK We still need to typeck the body, so assume `FnMut` kind just for that + // NB We still need to typeck the body, so assume `FnMut` kind just for that let kind = ty::FnMutUnboxedClosureKind; check_unboxed_closure(fcx, expr, kind, decl, body, None); fcx.ccx.tcx.sess.span_err( expr.span, - "Can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \ + "can't infer the \"kind\" of the closure, explicitly annotate it. e.g. \ `|&:| {}`"); }, Some((sig, kind)) => { From f97b124a44944feb41c39a4478eda55dbc5da44d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 5 Jan 2015 11:06:20 -0500 Subject: [PATCH 32/37] Fix ICE caused by forgotten bcx --- src/librustc_trans/trans/callee.rs | 2 +- src/test/run-pass/call-closure-from-overloaded-op.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index f598083c5e44a..9454de771389e 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -100,7 +100,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) -> Callee<'blk, 'tcx> { - let DatumBlock { datum, .. } = expr::trans(bcx, expr); + let DatumBlock { mut bcx, datum, .. } = expr::trans(bcx, expr); match datum.ty.sty { ty::ty_bare_fn(..) => { let llval = datum.to_llscalarish(bcx); diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs index 032bb83d3ab50..29fcdf504de6e 100644 --- a/src/test/run-pass/call-closure-from-overloaded-op.rs +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test FIXME(japaric) this ICEs - fn foo() -> int { 22 } pub fn main() { From c98814b1243ddde1f41fbc86815397b3091f2215 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 5 Jan 2015 13:53:39 -0500 Subject: [PATCH 33/37] Correctly "detuple" arguments when creating trait object shims for a trait method with rust-call ABI. --- src/librustc_trans/trans/callee.rs | 2 +- src/librustc_trans/trans/meth.rs | 22 ++++++++++++++++++- .../overloaded-calls-object-one-arg.rs | 21 ++++++++++++++++++ .../overloaded-calls-object-two-args.rs | 21 ++++++++++++++++++ .../overloaded-calls-object-zero-args.rs | 21 ++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/overloaded-calls-object-one-arg.rs create mode 100644 src/test/run-pass/overloaded-calls-object-two-args.rs create mode 100644 src/test/run-pass/overloaded-calls-object-zero-args.rs diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 9454de771389e..65e6d7e1924b6 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -100,7 +100,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) -> Callee<'blk, 'tcx> { - let DatumBlock { mut bcx, datum, .. } = expr::trans(bcx, expr); + let DatumBlock { bcx, datum, .. } = expr::trans(bcx, expr); match datum.ty.sty { ty::ty_bare_fn(..) => { let llval = datum.to_llscalarish(bcx); diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index c13516134c20c..e219b45d3d9f4 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -599,8 +599,27 @@ pub fn trans_object_shim<'a, 'tcx>( bcx.val_to_string(llobject)); // the remaining arguments will be, well, whatever they are + let input_tys = + match fty.abi { + RustCall => { + // unpack the tuple to extract the input type arguments: + match fty.sig.0.inputs[1].sty { + ty::ty_tup(ref tys) => tys.as_slice(), + _ => { + bcx.sess().bug( + format!("rust-call expects a tuple not {}", + fty.sig.0.inputs[1].repr(tcx)).as_slice()); + } + } + } + _ => { + // skip the self parameter: + fty.sig.0.inputs.slice_from(1) + } + }; + let llargs: Vec<_> = - fty.sig.0.inputs[1..].iter() + input_tys.iter() .enumerate() .map(|(i, _)| { let llarg = get_param(fcx.llfn, fcx.arg_pos(i+1) as u32); @@ -609,6 +628,7 @@ pub fn trans_object_shim<'a, 'tcx>( llarg }) .collect(); + assert!(!fcx.needs_ret_allocas); let dest = diff --git a/src/test/run-pass/overloaded-calls-object-one-arg.rs b/src/test/run-pass/overloaded-calls-object-one-arg.rs new file mode 100644 index 0000000000000..25b63cd14c435 --- /dev/null +++ b/src/test/run-pass/overloaded-calls-object-one-arg.rs @@ -0,0 +1,21 @@ +// Copyright 2014 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. + +// Tests calls to closure arguments where the closure takes 1 argument. +// This is a bit tricky due to rust-call ABI. + +fn foo(f: &mut FnMut(int) -> int) -> int { + f(22) +} + +fn main() { + let z = foo(&mut |x| x *100); + assert_eq!(z, 2200); +} diff --git a/src/test/run-pass/overloaded-calls-object-two-args.rs b/src/test/run-pass/overloaded-calls-object-two-args.rs new file mode 100644 index 0000000000000..026ebc308408f --- /dev/null +++ b/src/test/run-pass/overloaded-calls-object-two-args.rs @@ -0,0 +1,21 @@ +// Copyright 2014 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. + +// Tests calls to closure arguments where the closure takes 2 arguments. +// This is a bit tricky due to rust-call ABI. + +fn foo(f: &mut FnMut(int, int) -> int) -> int { + f(1, 2) +} + +fn main() { + let z = foo(&mut |x, y| x * 10 + y); + assert_eq!(z, 12); +} diff --git a/src/test/run-pass/overloaded-calls-object-zero-args.rs b/src/test/run-pass/overloaded-calls-object-zero-args.rs new file mode 100644 index 0000000000000..442df1e664cc3 --- /dev/null +++ b/src/test/run-pass/overloaded-calls-object-zero-args.rs @@ -0,0 +1,21 @@ +// Copyright 2014 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. + +// Tests calls to closure arguments where the closure takes 0 arguments. +// This is a bit tricky due to rust-call ABI. + +fn foo(f: &mut FnMut()) -> int { + f() +} + +fn main() { + let z = foo(|| 22); + assert_eq!(z, 22); +} From ec11f66dbf68c7d0a958b28e520f547c885a3fde Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 14:07:10 -0500 Subject: [PATCH 34/37] replace `f.call_mut(a, b, ..)` with `f(a, b, ..)` --- .../moves-based-on-type-no-recursive-stack-closure.rs | 2 +- src/test/compile-fail/unboxed-closures-type-mismatch.rs | 2 +- src/test/compile-fail/unboxed-closures-vtable-mismatch.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/issue-16668.rs | 4 ++-- src/test/run-pass/issue-3424.rs | 2 +- src/test/run-pass/overloaded-calls-simple.rs | 4 ++-- src/test/run-pass/trait-bounds-in-arc.rs | 6 +++--- src/test/run-pass/unboxed-closures-boxed.rs | 2 +- src/test/run-pass/unboxed-closures-extern-fn.rs | 6 +++--- .../run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs | 6 +++--- src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs | 4 ++-- src/test/run-pass/unboxed-closures-generic.rs | 2 +- src/test/run-pass/unboxed-closures-manual-impl.rs | 4 ++-- src/test/run-pass/unboxed-closures-prelude.rs | 4 ++-- src/test/run-pass/unboxed-closures-simple.rs | 2 +- src/test/run-pass/unboxed-closures-static-call-fn-once.rs | 2 +- 17 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs index 787e25ea31954..9053f97e8a7dd 100644 --- a/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs +++ b/src/test/compile-fail/moves-based-on-type-no-recursive-stack-closure.rs @@ -29,7 +29,7 @@ fn innocent_looking_victim() { } else { match x { Some(ref msg) => { - f.c.call_mut((f, true)); + (f.c)(f, true); //~^ ERROR: cannot borrow `*f` as mutable more than once at a time println!("{}", msg); }, diff --git a/src/test/compile-fail/unboxed-closures-type-mismatch.rs b/src/test/compile-fail/unboxed-closures-type-mismatch.rs index b3528f7abe719..a25d646486712 100644 --- a/src/test/compile-fail/unboxed-closures-type-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-type-mismatch.rs @@ -14,6 +14,6 @@ use std::ops::FnMut; pub fn main() { let mut f = |&mut: x: int, y: int| -> int { x + y }; - let z = f.call_mut((1u, 2)); //~ ERROR type mismatch + let z = f(1u, 2); //~ ERROR type mismatch println!("{}", z); } diff --git a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs index a96bde7cca4cd..85b33f73bbcb7 100644 --- a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs @@ -13,7 +13,7 @@ use std::ops::FnMut; fn call_it>(y: int, mut f: F) -> int { - f.call_mut((2, y)) + f(2, y) } pub fn main() { diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index a8ecc2decd08a..3bcce5388715d 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -18,7 +18,7 @@ */ pub fn map(filename: String, mut emit: map_reduce::putter) { - emit.call_mut((filename, "1".to_string(),)); + emit(filename, "1".to_string()); } mod map_reduce { diff --git a/src/test/run-pass/issue-16668.rs b/src/test/run-pass/issue-16668.rs index f36594cb40145..1febf33742974 100644 --- a/src/test/run-pass/issue-16668.rs +++ b/src/test/run-pass/issue-16668.rs @@ -20,8 +20,8 @@ impl<'a, I, O: 'a> Parser<'a, I, O> { fn compose(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> { Parser { parse: box move |&mut: x: I| { - match (*self.parse).call_mut((x,)) { - Ok(r) => (*rhs.parse).call_mut((r,)), + match (self.parse)(x) { + Ok(r) => (rhs.parse)(r), Err(e) => Err(e) } } diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index 651315ea64173..528870d033476 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -27,7 +27,7 @@ fn tester() }; let path = path::Path::new("blah"); - assert!(loader.call_mut((&path,)).is_ok()); + assert!(loader(&path).is_ok()); } pub fn main() {} diff --git a/src/test/run-pass/overloaded-calls-simple.rs b/src/test/run-pass/overloaded-calls-simple.rs index b0a40f74ff973..bb5b88d3674a1 100644 --- a/src/test/run-pass/overloaded-calls-simple.rs +++ b/src/test/run-pass/overloaded-calls-simple.rs @@ -50,7 +50,7 @@ fn main() { x: 3, y: 3, }; - let ans = s.call_mut((3,)); + let ans = s(3); assert_eq!(ans, 27); let s = S2 { @@ -64,7 +64,7 @@ fn main() { x: 3, y: 3, }; - let ans = s.call_once((3, 1)); + let ans = s(3, 1); assert_eq!(ans, 27); } diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index b193ad7892a6d..bc397bb63196e 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -42,19 +42,19 @@ struct Goldfyshe { } impl Pet for Catte { - fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } + fn name(&self, mut blk: Box) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 } } impl Pet for Dogge { - fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } + fn name(&self, mut blk: Box) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.bark_decibels < 70 || self.tricks_known > 20 } } impl Pet for Goldfyshe { - fn name(&self, mut blk: Box) { blk.call_mut((self.name.as_slice(),)) } + fn name(&self, mut blk: Box) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 0 } fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 } } diff --git a/src/test/run-pass/unboxed-closures-boxed.rs b/src/test/run-pass/unboxed-closures-boxed.rs index ab3faa16f948f..60e59400e1a09 100644 --- a/src/test/run-pass/unboxed-closures-boxed.rs +++ b/src/test/run-pass/unboxed-closures-boxed.rs @@ -19,7 +19,7 @@ use std::ops::FnMut; pub fn main() { let mut adder = make_adder(3); - let z = adder.call_mut((2,)); + let z = adder(2); println!("{}", z); assert_eq!(z, 5); } diff --git a/src/test/run-pass/unboxed-closures-extern-fn.rs b/src/test/run-pass/unboxed-closures-extern-fn.rs index 58657c2b71880..a25f5e265e814 100644 --- a/src/test/run-pass/unboxed-closures-extern-fn.rs +++ b/src/test/run-pass/unboxed-closures-extern-fn.rs @@ -18,15 +18,15 @@ use std::ops::{Fn,FnMut,FnOnce}; fn square(x: int) -> int { x * x } fn call_itint>(f: &F, x: int) -> int { - f.call((x,)) + f(x) } fn call_it_mutint>(f: &mut F, x: int) -> int { - f.call_mut((x,)) + f(x) } fn call_it_onceint>(f: F, x: int) -> int { - f.call_once((x,)) + f(x) } fn main() { diff --git a/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs b/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs index 77d41ae190778..8af0547e5e57f 100644 --- a/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs +++ b/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs @@ -25,15 +25,15 @@ impl Fn<(int,),int> for S { } fn call_itint>(f: &F, x: int) -> int { - f.call((x,)) + f(x) } fn call_it_mutint>(f: &mut F, x: int) -> int { - f.call_mut((x,)) + f(x) } fn call_it_onceint>(f: F, x: int) -> int { - f.call_once((x,)) + f(x) } fn main() { diff --git a/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs b/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs index 02395624cd123..068080e256dba 100644 --- a/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs +++ b/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs @@ -25,11 +25,11 @@ impl FnMut<(int,),int> for S { } fn call_it_mutint>(f: &mut F, x: int) -> int { - f.call_mut((x,)) + f(x) } fn call_it_onceint>(f: F, x: int) -> int { - f.call_once((x,)) + f(x) } fn main() { diff --git a/src/test/run-pass/unboxed-closures-generic.rs b/src/test/run-pass/unboxed-closures-generic.rs index 9d1d81fe259b3..0edeeb8d198da 100644 --- a/src/test/run-pass/unboxed-closures-generic.rs +++ b/src/test/run-pass/unboxed-closures-generic.rs @@ -13,7 +13,7 @@ use std::ops::FnMut; fn call_it>(y: int, mut f: F) -> int { - f.call_mut((2, y)) + f(2, y) } pub fn main() { diff --git a/src/test/run-pass/unboxed-closures-manual-impl.rs b/src/test/run-pass/unboxed-closures-manual-impl.rs index 3a750dadb911c..88c9ceae4a124 100644 --- a/src/test/run-pass/unboxed-closures-manual-impl.rs +++ b/src/test/run-pass/unboxed-closures-manual-impl.rs @@ -22,11 +22,11 @@ impl FnMut<(int,),int> for S { } fn call_itint>(mut f: F, x: int) -> int { - f.call_mut((x,)) + 3 + f(x) + 3 } fn call_box(f: &mut FnMut(int) -> int, x: int) -> int { - f.call_mut((x,)) + 3 + f(x) + 3 } fn main() { diff --git a/src/test/run-pass/unboxed-closures-prelude.rs b/src/test/run-pass/unboxed-closures-prelude.rs index e31ef169e16eb..d1bd7e908c826 100644 --- a/src/test/run-pass/unboxed-closures-prelude.rs +++ b/src/test/run-pass/unboxed-closures-prelude.rs @@ -17,12 +17,12 @@ fn main() { task.call((0i, )); let mut task: Box int> = box |&mut: x| x; - task.call_mut((0i, )); + task(0i); call(|:x| x, 22); } fn call int>(f: F, x: int) -> int { - f.call_once((x,)) + f(x) } diff --git a/src/test/run-pass/unboxed-closures-simple.rs b/src/test/run-pass/unboxed-closures-simple.rs index f11096ba5ffc6..c473db4586ff7 100644 --- a/src/test/run-pass/unboxed-closures-simple.rs +++ b/src/test/run-pass/unboxed-closures-simple.rs @@ -14,6 +14,6 @@ use std::ops::FnMut; pub fn main() { let mut f = |&mut: x: int, y: int| -> int { x + y }; - let z = f.call_mut((1, 2)); + let z = f(1, 2); assert_eq!(z, 3); } diff --git a/src/test/run-pass/unboxed-closures-static-call-fn-once.rs b/src/test/run-pass/unboxed-closures-static-call-fn-once.rs index beab82e804bf7..780a1e6cdf034 100644 --- a/src/test/run-pass/unboxed-closures-static-call-fn-once.rs +++ b/src/test/run-pass/unboxed-closures-static-call-fn-once.rs @@ -12,6 +12,6 @@ fn main() { let onetime = |: x| x; - onetime.call_once((0i,)); + onetime(0i); } From a55011e788e3523cc37c1fca47fc334a74682369 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 16:02:07 -0500 Subject: [PATCH 35/37] fix tests --- src/test/compile-fail/unboxed-closures-type-mismatch.rs | 2 +- src/test/run-pass/overloaded-calls-object-zero-args.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/compile-fail/unboxed-closures-type-mismatch.rs b/src/test/compile-fail/unboxed-closures-type-mismatch.rs index a25d646486712..61f1317283272 100644 --- a/src/test/compile-fail/unboxed-closures-type-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-type-mismatch.rs @@ -14,6 +14,6 @@ use std::ops::FnMut; pub fn main() { let mut f = |&mut: x: int, y: int| -> int { x + y }; - let z = f(1u, 2); //~ ERROR type mismatch + let z = f(1u, 2); //~ ERROR mismatched types println!("{}", z); } diff --git a/src/test/run-pass/overloaded-calls-object-zero-args.rs b/src/test/run-pass/overloaded-calls-object-zero-args.rs index 442df1e664cc3..b38f8213b4ab8 100644 --- a/src/test/run-pass/overloaded-calls-object-zero-args.rs +++ b/src/test/run-pass/overloaded-calls-object-zero-args.rs @@ -11,11 +11,11 @@ // Tests calls to closure arguments where the closure takes 0 arguments. // This is a bit tricky due to rust-call ABI. -fn foo(f: &mut FnMut()) -> int { +fn foo(f: &mut FnMut() -> int) -> int { f() } fn main() { - let z = foo(|| 22); + let z = foo(&mut || 22); assert_eq!(z, 22); } From 97f870a1fc24ecf3a432170c7040863d0399eb85 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 16:02:28 -0500 Subject: [PATCH 36/37] unignore and fix doctests in guide and reference --- src/doc/guide-testing.md | 10 ++++---- src/doc/guide.md | 52 ++++++++++++++++++++-------------------- src/doc/reference.md | 20 ++++++++-------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/doc/guide-testing.md b/src/doc/guide-testing.md index dea861ad94604..4606a1ba846ff 100644 --- a/src/doc/guide-testing.md +++ b/src/doc/guide-testing.md @@ -536,8 +536,9 @@ optimizer to consider the result used and ensures it cannot remove the computation entirely. This could be done for the example above by adjusting the `b.iter` call to -```{rust,ignore} -# struct X; impl X { fn iter(&self, _: || -> T) {} } let b = X; +```rust +# struct X; +# impl X { fn iter(&self, _: F) where F: FnMut() -> T {} } let b = X; b.iter(|| { // note lack of `;` (could also use an explicit `return`). range(0u, 1000).fold(0, |old, new| old ^ new) @@ -548,11 +549,12 @@ Or, the other option is to call the generic `test::black_box` function, which is an opaque "black box" to the optimizer and so forces it to consider any argument as used. -```{rust,ignore} +```rust extern crate test; # fn main() { -# struct X; impl X { fn iter(&self, _: || -> T) {} } let b = X; +# struct X; +# impl X { fn iter(&self, _: F) where F: FnMut() -> T {} } let b = X; b.iter(|| { test::black_box(range(0u, 1000).fold(0, |old, new| old ^ new)); }); diff --git a/src/doc/guide.md b/src/doc/guide.md index 9bd17ec333258..e60740db353bc 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -4231,8 +4231,8 @@ arguments, really powerful things are possible. Let's make a closure: -```{rust,ignore} -let add_one = |x| { 1 + x }; +```{rust} +let add_one = |&: x| { 1 + x }; println!("The sum of 5 plus 1 is {}.", add_one(5)); ``` @@ -4243,9 +4243,9 @@ binding name and two parentheses, just like we would for a named function. Let's compare syntax. The two are pretty close: -```{rust,ignore} -let add_one = |x: i32| -> i32 { 1 + x }; -fn add_one (x: i32) -> i32 { 1 + x } +```{rust} +let add_one = |&: x: i32| -> i32 { 1 + x }; +fn add_one (x: i32) -> i32 { 1 + x } ``` As you may have noticed, closures infer their argument and return types, so you @@ -4256,11 +4256,11 @@ There's one big difference between a closure and named functions, and it's in the name: a closure "closes over its environment." What does that mean? It means this: -```{rust,ignore} +```{rust} fn main() { - let x = 5; + let x: i32 = 5; - let printer = || { println!("x is: {}", x); }; + let printer = |&:| { println!("x is: {}", x); }; printer(); // prints "x is: 5" } @@ -4276,7 +4276,7 @@ defined. The closure borrows any variables it uses, so this will error: fn main() { let mut x = 5; - let printer = || { println!("x is: {}", x); }; + let printer = |&:| { println!("x is: {}", x); }; x = 6; // error: cannot assign to `x` because it is borrowed } @@ -4297,13 +4297,13 @@ now. We'll talk about them more in the "Threads" section of the guide. Closures are most useful as an argument to another function. Here's an example: -```{rust,ignore} -fn twice(x: i32, f: |i32| -> i32) -> i32 { +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } fn main() { - let square = |x: i32| { x * x }; + let square = |&: x: i32| { x * x }; twice(5, square); // evaluates to 50 } @@ -4311,16 +4311,16 @@ fn main() { Let's break the example down, starting with `main`: -```{rust,ignore} -let square = |x: i32| { x * x }; +```{rust} +let square = |&: x: i32| { x * x }; ``` We've seen this before. We make a closure that takes an integer, and returns its square. -```{rust,ignore} -# fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) } -# let square = |x: i32| { x * x }; +```{rust} +# fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } +# let square = |&: x: i32| { x * x }; twice(5, square); // evaluates to 50 ``` @@ -4342,9 +4342,9 @@ though, and that function takes an `i32` and returns an `i32`. Notice how the `|i32| -> i32` syntax looks a lot like our definition of `square` above, if we added the return type in: -```{rust,ignore} -let square = |x: i32| -> i32 { x * x }; -// |i32| -> i32 +```{rust} +let square = |&: x: i32| -> i32 { x * x }; +// |i32| -> i32 ``` This function takes an `i32` and returns an `i32`. @@ -4357,8 +4357,8 @@ Finally, `twice` returns an `i32` as well. Okay, let's look at the body of `twice`: -```{rust,ignore} -fn twice(x: i32, f: |i32| -> i32) -> i32 { +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } ``` @@ -4375,8 +4375,8 @@ this technique a lot. If we didn't want to give `square` a name, we could just define it inline. This example is the same as the previous one: -```{rust,ignore} -fn twice(x: i32, f: |i32| -> i32) -> i32 { +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } @@ -4388,8 +4388,8 @@ fn main() { A named function's name can be used wherever you'd use a closure. Another way of writing the previous example: -```{rust,ignore} -fn twice(x: i32, f: |i32| -> i32) -> i32 { +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } diff --git a/src/doc/reference.md b/src/doc/reference.md index 512081ac48f4d..5c00993d918d7 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1559,11 +1559,11 @@ Type parameters can be specified for a trait to make it generic. These appear after the trait name, using the same syntax used in [generic functions](#generic-functions). -``` ignore +``` trait Seq { fn len(&self) -> uint; fn elt_at(&self, n: uint) -> T; - fn iter(&self, |T|); + fn iter(&self, F) where F: Fn(T); } ``` @@ -3217,8 +3217,8 @@ expression's captured environment. In this example, we define a function `ten_times` that takes a higher-order function argument, and call it with a lambda expression as an argument. -``` ignore -fn ten_times(f: |int|) { +``` +fn ten_times(f: F) where F: Fn(int) { let mut i = 0; while i < 10 { f(i); @@ -3821,14 +3821,14 @@ or `extern`), a sequence of input types and an output type. An example of a `fn` type: -``` ignore +``` fn add(x: int, y: int) -> int { return x + y; } let mut x = add(5,7); -type Binop<'a> = |int,int|: 'a -> int; +type Binop = fn(int, int) -> int; let bo: Binop = add; x = bo(5,7); ``` @@ -3849,17 +3849,17 @@ The type of a closure mapping an input of type `A` to an output of type `B` is An example of creating and calling a closure: -``` ignore +```rust let captured_var = 10i; -let closure_no_args = || println!("captured_var={}", captured_var); +let closure_no_args = |&:| println!("captured_var={}", captured_var); -let closure_args = |arg: int| -> int { +let closure_args = |&: arg: int| -> int { println!("captured_var={}, arg={}", captured_var, arg); arg // Note lack of semicolon after 'arg' }; -fn call_closure(c1: ||, c2: |int| -> int) { +fn call_closure int>(c1: F, c2: G) { c1(); c2(2); } From eb2506cc1bcf2011d4e8ce99ff7cf74c2c1d1493 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 5 Jan 2015 16:19:15 -0500 Subject: [PATCH 37/37] remove more stage0 stuff --- src/libserialize/json_stage0.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/libserialize/json_stage0.rs b/src/libserialize/json_stage0.rs index 84180159c2be7..9932f8d0306b3 100644 --- a/src/libserialize/json_stage0.rs +++ b/src/libserialize/json_stage0.rs @@ -1123,15 +1123,6 @@ impl Json { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a> ops::Index<&'a str, Json> for Json { - fn index(&self, idx: & &str) -> &Json { - self.find(*idx).unwrap() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a> ops::Index<&'a str> for Json { type Output = Json; @@ -1140,18 +1131,6 @@ impl<'a> ops::Index<&'a str> for Json { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl ops::Index for Json { - fn index<'a>(&'a self, idx: &uint) -> &'a Json { - match self { - &Json::Array(ref v) => v.index(idx), - _ => panic!("can only index Json with uint if it is an array") - } - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl ops::Index for Json { type Output = Json;