use kinds::Sized;
use mem;
use num::Int;
+use ops::FnMut;
use option::Option;
use option::Option::{None, Some};
use ops::{Fn, FnMut};
type hoedown_document = libc::c_void; // this is opaque to us
+type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
+ *const hoedown_buffer, *mut libc::c_void);
+
+type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
+ libc::c_int, *mut libc::c_void);
+
#[repr(C)]
struct hoedown_renderer {
opaque: *mut hoedown_html_renderer_state,
- blockcode: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
- *const hoedown_buffer, *mut libc::c_void)>,
+ blockcode: Option<blockcodefn>,
blockquote: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void)>,
blockhtml: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void)>,
- header: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
- libc::c_int, *mut libc::c_void)>,
+ header: Option<headerfn>,
other: [libc::size_t, ..28],
}
toc_builder: if print_toc {Some(TocBuilder::new())} else {None}
};
(*(*renderer).opaque).opaque = &mut opaque as *mut _ as *mut libc::c_void;
- (*renderer).blockcode = Some(block);
- (*renderer).header = Some(header);
+ (*renderer).blockcode = Some(block as blockcodefn);
+ (*renderer).header = Some(header as headerfn);
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
hoedown_document_render(document, ob, s.as_ptr(),
unsafe {
let ob = hoedown_buffer_new(DEF_OUNIT);
let renderer = hoedown_html_renderer_new(0, 0);
- (*renderer).blockcode = Some(block);
- (*renderer).header = Some(header);
+ (*renderer).blockcode = Some(block as blockcodefn);
+ (*renderer).header = Some(header as headerfn);
(*(*renderer).opaque).opaque = tests as *mut _ as *mut libc::c_void;
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
let s = if self.has_nonsemantic_trailing_slash() {
self.repr.slice_to(self.repr.len()-1)
} else { self.repr.as_slice() };
- let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep }
- else { is_sep_verbatim });
+ let sep_test: fn(char) -> bool = if !prefix_is_verbatim(self.prefix) {
+ is_sep
+ } else {
+ is_sep_verbatim
+ };
+ let idx = s.rfind(sep_test);
let prefixlen = self.prefix_len();
self.sepidx = idx.and_then(|x| if x < prefixlen { None } else { Some(x) });
}
// None result means the string didn't need normalizing
fn normalize_helper<'a>(s: &'a str, prefix: Option<PathPrefix>) -> (bool, Option<Vec<&'a str>>) {
- let f = if !prefix_is_verbatim(prefix) { is_sep } else { is_sep_verbatim };
+ let f: fn(char) -> bool = if !prefix_is_verbatim(prefix) {
+ is_sep
+ } else {
+ is_sep_verbatim
+ };
let is_abs = s.len() > prefix_len(prefix) && f(s.char_at(prefix_len(prefix)));
let s_ = s.slice_from(prefix_len(prefix));
let s_ = if is_abs { s_.slice_from(1) } else { s_ };
}
};
- #[cfg(not(any(target_os = "macos", target_os = "linux")))]
+ #[cfg(all(stage0, not(any(target_os = "macos", target_os = "linux"))))]
const INIT: ::std::thread_local::KeyInner<$t> = {
unsafe extern fn __destroy(ptr: *mut u8) {
::std::thread_local::destroy_value::<$t>(ptr);
}
+
::std::thread_local::KeyInner {
inner: ::std::cell::UnsafeCell { value: $init },
os: ::std::thread_local::OsStaticKey {
}
};
+ #[cfg(all(not(stage0), not(any(target_os = "macos", target_os = "linux"))))]
+ const INIT: ::std::thread_local::KeyInner<$t> = {
+ unsafe extern fn __destroy(ptr: *mut u8) {
+ ::std::thread_local::destroy_value::<$t>(ptr);
+ }
+
+ ::std::thread_local::KeyInner {
+ inner: ::std::cell::UnsafeCell { value: $init },
+ os: ::std::thread_local::OsStaticKey {
+ inner: ::std::thread_local::OS_INIT_INNER,
+ dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)),
+ },
+ }
+ };
+
INIT
});
}
// *should* be the case that this loop always terminates because we
// provide the guarantee that a TLS key cannot be set after it is
// flagged for destruction.
+ #[cfg(not(stage0))]
+ static DTORS: os::StaticKey = os::StaticKey {
+ inner: os::INIT_INNER,
+ dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)),
+ };
+ #[cfg(stage0)]
static DTORS: os::StaticKey = os::StaticKey {
inner: os::INIT_INNER,
dtor: Some(run_dtors),
push: |P<ast::Item>|);
}
-impl ItemDecorator for fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P<ast::Item>|) {
+impl<F> ItemDecorator for F
+ where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P<ast::Item>|)
+{
fn expand(&self,
ecx: &mut ExtCtxt,
sp: Span,
meta_item: &ast::MetaItem,
item: &ast::Item,
push: |P<ast::Item>|) {
- self.clone()(ecx, sp, meta_item, item, push)
+ (*self)(ecx, sp, meta_item, item, push)
}
}
-> P<ast::Item>;
}
-impl ItemModifier for fn(&mut ExtCtxt, Span, &ast::MetaItem, P<ast::Item>) -> P<ast::Item> {
+impl<F> ItemModifier for F
+ where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, P<ast::Item>) -> P<ast::Item>
+{
fn expand(&self,
ecx: &mut ExtCtxt,
span: Span,
meta_item: &ast::MetaItem,
item: P<ast::Item>)
-> P<ast::Item> {
- self.clone()(ecx, span, meta_item, item)
+ (*self)(ecx, span, meta_item, item)
}
}
pub type MacroExpanderFn =
for<'cx> fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box<MacResult+'cx>;
-impl TTMacroExpander for MacroExpanderFn {
+impl<F> TTMacroExpander for F
+ where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box<MacResult+'cx>
+{
fn expand<'cx>(&self,
ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[ast::TokenTree])
-> Box<MacResult+'cx> {
- self.clone()(ecx, span, token_tree)
+ (*self)(ecx, span, token_tree)
}
}
pub type IdentMacroExpanderFn =
for<'cx> fn(&'cx mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult+'cx>;
-impl IdentMacroExpander for IdentMacroExpanderFn {
+impl<F> IdentMacroExpander for F
+ where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident,
+ Vec<ast::TokenTree>) -> Box<MacResult+'cx>
+{
fn expand<'cx>(&self,
cx: &'cx mut ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: Vec<ast::TokenTree> )
- -> Box<MacResult+'cx> {
- self.clone()(cx, sp, ident, token_tree)
+ -> Box<MacResult+'cx>
+ {
+ (*self)(cx, sp, ident, token_tree)
}
}
}
fn main() {
- let mut x = X(Either::Right(main));
+ let mut x = X(Either::Right(main as fn()));
(&mut x).with(
|opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
match opt {
fn main() {
let v: u64 = 5;
let x = foo as extern "C" fn() -> int;
- //~^ ERROR non-scalar cast
+ //~^ ERROR mismatched types
let y = v as extern "Rust" fn(int) -> (int, int);
//~^ ERROR non-scalar cast
y(x());
// 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 main() {
+fn fn_item_type() {
let f = foo;
let f_closure: || = f;
- //~^ ERROR: cannot coerce non-statically resolved bare fn to closure
- //~^^ HELP: consider embedding the function in a closure
}
+
+fn fn_pointer_type() {
+ let f = foo as fn();
+ let f_closure: || = f;
+ //~^ ERROR: mismatched types
+}
+
+fn main() { }
extern fn bar() {}
fn main() { f(bar) }
-//~^ ERROR: expected `fn()`, found `extern "C" fn()`
+//~^ ERROR mismatched types
#[start]
fn start(argc: int, argv: *const *const u8, crate_map: *const u8) -> int {
- //~^ ERROR start function expects type: `fn(int, *const *const u8) -> int`
+ //~^ ERROR incorrect number of function parameters
0
}
fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) {
// Illegal now because there is no `'b:'a` declaration.
- *x = *y; //~ ERROR mismatched types
+ *x = *y; //~ ERROR cannot infer
}
fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) {
fn nested<'x>(x: &'x int) {
let y = 3;
- let mut ay = &y; //~ ERROR cannot infer
+ let mut ay = &y;
ignore::< for<'z>|&'z int|>(|z| {
- ay = x;
+ ay = x; //~ ERROR cannot infer
ay = &y;
ay = z;
});
fn create() -> A<'static> {
A {
- func: &foo, //~ ERROR borrowed value does not live long enough
+ func: &foo, //~ ERROR mismatched types
}
}
// except according to those terms.
struct StateMachineIter<'a> {
- statefn: &'a fn(&mut StateMachineIter<'a>) -> Option<&'static str>
+ statefn: &'a StateMachineFunc<'a>
}
+type StateMachineFunc<'a> = fn(&mut StateMachineIter<'a>) -> Option<&'static str>;
+
impl<'a> Iterator<&'static str> for StateMachineIter<'a> {
fn next(&mut self) -> Option<&'static str> {
return (*self.statefn)(self);
}
fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
- self_.statefn = &state2;
+ self_.statefn = &(state2 as StateMachineFunc);
//~^ ERROR borrowed value does not live long enough
return Some("state1");
}
fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
- self_.statefn = &state3;
+ self_.statefn = &(state3 as StateMachineFunc);
//~^ ERROR borrowed value does not live long enough
return Some("state2");
}
fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
- self_.statefn = &finished;
+ self_.statefn = &(finished as StateMachineFunc);
//~^ ERROR borrowed value does not live long enough
return Some("state3");
}
fn state_iter() -> StateMachineIter<'static> {
StateMachineIter {
- statefn: &state1 //~ ERROR borrowed value does not live long enough
+ statefn: &(state1 as StateMachineFunc) //~ ERROR borrowed value does not live long enough
}
}
((::std::fmt::format as
- fn(&core::fmt::Arguments<'_>) -> collections::string::String)((&((::std::fmt::Arguments::new
- as
- fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_>)((__STATIC_FMTSTR
- as
- &'static [&'static str]),
- (&([]
- as
- [core::fmt::Argument<'_>; 0])
- as
- &[core::fmt::Argument<'_>; 0]))
- as
- core::fmt::Arguments<'_>)
- as
- &core::fmt::Arguments<'_>))
+ fn(&core::fmt::Arguments<'_>) -> collections::string::String {std::fmt::format})((&((::std::fmt::Arguments::new
+ as
+ fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new})((__STATIC_FMTSTR
+ as
+ &'static [&'static str]),
+ (&([]
+ as
+ [core::fmt::Argument<'_>; 0])
+ as
+ &[core::fmt::Argument<'_>; 0]))
+ as
+ core::fmt::Arguments<'_>)
+ as
+ &core::fmt::Arguments<'_>))
as collections::string::String)
}
} as collections::string::String);
pub fn use_id() {
let _ =
((id::<[int; (3u as uint)]> as
- fn([int; 3]) -> [int; 3])(([(1 as int), (2 as int), (3 as int)]
- as [int; 3])) as [int; 3]);
+ fn([int; 3]) -> [int; 3] {id})(([(1 as int), (2 as int),
+ (3 as int)] as [int; 3])) as
+ [int; 3]);
}
fn main() { }
}
pub fn main() {
- assert!(foopy == f);
+ assert!(foopy as extern "C" fn() == f);
assert!(f == s.f);
}
extern fn uintvoidret(_x: uint) {}
extern fn uintuintuintuintret(x: uint, y: uint, z: uint) -> uint { x+y+z }
+type uintuintuintuintret = extern fn(uint,uint,uint) -> uint;
pub fn main() {
- assert!(voidret1 == voidret1);
- assert!(voidret1 != voidret2);
+ assert!(voidret1 as extern fn() == voidret1 as extern fn());
+ assert!(voidret1 as extern fn() != voidret2 as extern fn());
- assert!(uintret == uintret);
+ assert!(uintret as extern fn() -> uint == uintret as extern fn() -> uint);
- assert!(uintvoidret == uintvoidret);
+ assert!(uintvoidret as extern fn(uint) == uintvoidret as extern fn(uint));
- assert!(uintuintuintuintret == uintuintuintuintret);
+ assert!(uintuintuintuintret as uintuintuintuintret ==
+ uintuintuintuintret as uintuintuintuintret);
}
pub fn main() {
fn f() {
};
- let _: Box<fn()> = box f;
+ let _: Box<fn()> = box() (f as fn());
}
}
fn main() {
+ let thing: fn(int, int) -> int = thing; // coerce to fn type
bar(&thing);
}