mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Fix fallout from changes. In cases where stage0 compiler is needed, we
cannot use an `as` expression to coerce, so I used a one-off function instead (this is a no-op in stage0, but in stage1+ it triggers coercion from the fn pointer to the fn item type).
This commit is contained in:
parent
211782fef5
commit
7f6177e646
@ -30,6 +30,7 @@ use iter::range;
|
||||
use kinds::Sized;
|
||||
use mem;
|
||||
use num::Int;
|
||||
use ops::FnMut;
|
||||
use option::Option;
|
||||
use option::Option::{None, Some};
|
||||
use ops::{Fn, FnMut};
|
||||
|
@ -65,17 +65,21 @@ const HOEDOWN_EXTENSIONS: libc::c_uint =
|
||||
|
||||
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],
|
||||
}
|
||||
|
||||
@ -281,8 +285,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
|
||||
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(),
|
||||
@ -354,8 +358,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
|
||||
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);
|
||||
|
@ -829,8 +829,12 @@ impl Path {
|
||||
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) });
|
||||
}
|
||||
@ -1048,7 +1052,11 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
|
||||
|
||||
// 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_ };
|
||||
|
@ -189,11 +189,12 @@ macro_rules! __thread_local_inner {
|
||||
}
|
||||
};
|
||||
|
||||
#[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 {
|
||||
@ -203,6 +204,21 @@ macro_rules! __thread_local_inner {
|
||||
}
|
||||
};
|
||||
|
||||
#[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
|
||||
});
|
||||
}
|
||||
@ -323,6 +339,12 @@ mod imp {
|
||||
// *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),
|
||||
|
@ -50,14 +50,16 @@ pub trait ItemDecorator {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,14 +72,16 @@ pub trait ItemModifier {
|
||||
-> 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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,13 +97,15 @@ pub trait TTMacroExpander {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,14 +121,18 @@ pub trait IdentMacroExpander {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ impl X {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -13,7 +13,7 @@ fn foo(_x: int) { }
|
||||
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());
|
||||
|
@ -8,12 +8,21 @@
|
||||
// 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() { }
|
||||
|
@ -12,4 +12,4 @@ fn f(_: extern "Rust" fn()) {}
|
||||
extern fn bar() {}
|
||||
|
||||
fn main() { f(bar) }
|
||||
//~^ ERROR: expected `fn()`, found `extern "C" fn()`
|
||||
//~^ ERROR mismatched types
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
#[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
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ fn a<'a, 'b:'a>(x: &mut &'a int, y: &mut &'b int) {
|
||||
|
||||
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) {
|
||||
|
@ -12,10 +12,10 @@ fn ignore<T>(t: T) {}
|
||||
|
||||
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;
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ fn foo() -> Option<int> {
|
||||
|
||||
fn create() -> A<'static> {
|
||||
A {
|
||||
func: &foo, //~ ERROR borrowed value does not live long enough
|
||||
func: &foo, //~ ERROR mismatched types
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,11 @@
|
||||
// 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);
|
||||
@ -19,19 +21,19 @@ impl<'a> Iterator<&'static str> for StateMachineIter<'a> {
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@ -42,7 +44,7 @@ fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,20 +50,20 @@ pub fn bar() {
|
||||
|
||||
|
||||
((::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);
|
||||
@ -78,7 +78,8 @@ pub fn id<T>(x: T) -> T { (x as T) }
|
||||
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() { }
|
||||
|
@ -18,6 +18,6 @@ struct S {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert!(foopy == f);
|
||||
assert!(foopy as extern "C" fn() == f);
|
||||
assert!(f == s.f);
|
||||
}
|
||||
|
@ -18,15 +18,17 @@ extern fn uintret() -> uint { 22 }
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -12,5 +12,5 @@
|
||||
pub fn main() {
|
||||
fn f() {
|
||||
};
|
||||
let _: Box<fn()> = box f;
|
||||
let _: Box<fn()> = box() (f as fn());
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ fn thing(a: int, b: int) -> int {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let thing: fn(int, int) -> int = thing; // coerce to fn type
|
||||
bar(&thing);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user