]> git.lizzy.rs Git - rust.git/commitdiff
Fix fallout from changes. In cases where stage0 compiler is needed, we
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 26 Nov 2014 10:52:16 +0000 (05:52 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 22 Dec 2014 17:27:07 +0000 (12:27 -0500)
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).

19 files changed:
src/libcore/str.rs
src/librustdoc/html/markdown.rs
src/libstd/path/windows.rs
src/libstd/thread_local/mod.rs
src/libsyntax/ext/base.rs
src/test/compile-fail/borrowck-autoref-3261.rs
src/test/compile-fail/cast-to-bare-fn.rs
src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs
src/test/compile-fail/issue-10764.rs
src/test/compile-fail/issue-9575.rs
src/test/compile-fail/regions-lifetime-bounds-on-fns.rs
src/test/compile-fail/regions-nested-fns.rs
src/test/compile-fail/static-reference-to-fn-1.rs
src/test/compile-fail/static-reference-to-fn-2.rs
src/test/pretty/issue-4264.pp
src/test/run-pass/const-extern-function.rs
src/test/run-pass/extern-compare-with-return-type.rs
src/test/run-pass/issue-10767.rs
src/test/run-pass/issue-15444.rs

index a89a7970ae9c43eaeba429fc3cb500806771cdf6..1cd58aee0612f5a1370f0b43bdafc7c814c7b7da 100644 (file)
@@ -30,6 +30,7 @@
 use kinds::Sized;
 use mem;
 use num::Int;
+use ops::FnMut;
 use option::Option;
 use option::Option::{None, Some};
 use ops::{Fn, FnMut};
index 8b2f644dfe33bd2a57b2647336bf86289a265fbc..009079bd21453fca3e420d862701a93ac1ea1080 100644 (file)
 
 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);
index c2c17103554ce608e1abba4cfa9d8c2ef0d99c2c..9e4a66e0e5e06122a1682f90d853121b081a2fca 100644 (file)
@@ -829,8 +829,12 @@ fn update_sepidx(&mut self) {
         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_two_comps(mut path: &str, f: fn(char) -> bool) -> Option<(uint, uint)>
 
 // 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_ };
index 4c33d1c418d962d0e22ab7a58c67c8a449387773..04718dcc6ae3bb8435437dc817256cb0317f6897 100644 (file)
@@ -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 @@ unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
         // *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),
index aefbb2a1feab365e0d0629a76fb24feecf7731fe..f76c350902d7df4e37ef336e53d67cbd1605a4f4 100644 (file)
@@ -50,14 +50,16 @@ fn expand(&self,
               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 @@ fn expand(&self,
               -> 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 @@ fn expand<'cx>(&self,
 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 @@ fn expand<'cx>(&self,
 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)
     }
 }
 
index 8c6e76e7746193f295c4630c0314310690779cc9..1b4e5891f941de493f284cf808da66326a7b88ea 100644 (file)
@@ -20,7 +20,7 @@ pub fn with(&self, blk: |x: &Either<(uint,uint), fn()>|) {
 }
 
 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 {
index 10a829fd794556ce2a985fca91971f4010bac975..1db813292b01241b79535116219a01fa6f2b93c5 100644 (file)
@@ -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());
index 27e339180a6cffe2b4f4c26bf088ad7d584fcc61..52f4c4749e224f90e1455befddc899c5cf7557a6 100644 (file)
@@ -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() { }
index 0733744b65210d724ed498d24abf969b69b27dfb..cd4ec495556c562303249997f20c36d31f7b3694 100644 (file)
@@ -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
index aa3d9d9fef080691385ff4cf10650d1c12c035b0..6e8f7ffb68da4285549855b1da38623942474616 100644 (file)
@@ -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
 }
index 773d6e2c703655433b6afa9355de737a2e225ae5..4a42728da6f580f0aab75f13891ba84b9eb8b670 100644 (file)
@@ -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) {
index cf0b615bb01abbd6dd7e5b82f14207f00da98026..f4654367970d11d052b16a23f73f54b8933e3113 100644 (file)
@@ -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;
     });
index c0d430908a137a32dad184070512f61bbadba296..bce397c47932f453baa83c8deffb871c1a593b04 100644 (file)
@@ -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
     }
 }
 
index 3a0f0a193cfe11f11ed7364ec9afc2278ed5fb3b..d7255c3ba0694ff96f10149795d439cb22bba3c7 100644 (file)
@@ -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 @@ fn next(&mut self) -> Option<&'static str> {
 }
 
 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
     }
 }
 
index 974af1e6f3e108992f2a04178062ea9a46be60dd..e4389cd69dd62f88ed6b53ca928abe3999b912a6 100644 (file)
@@ -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() { }
index be7c47dafc01746015183c331e0d4b1f4fb0fc79..069ca6ecf49dd4c3f1ef83212d7e7fef3beebfa0 100644 (file)
@@ -18,6 +18,6 @@ struct S {
 }
 
 pub fn main() {
-    assert!(foopy == f);
+    assert!(foopy as extern "C" fn() == f);
     assert!(f == s.f);
 }
index 057394b2624fecc5b78a66251dc2d8f261e1c18f..3febff18704deea2faf81c12c4d46e9966d6d09c 100644 (file)
 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);
 }
 
index a30eb8120eae1c63ace921f92d693d17066ddb69..d28950241874d2db112f1d5be09a2adc696933c5 100644 (file)
@@ -12,5 +12,5 @@
 pub fn main() {
     fn f() {
     };
-    let _: Box<fn()> = box f;
+    let _: Box<fn()> = box() (f as fn());
 }
index f5618c2c7a3c40a1d2aa075664a1a04499d2eafb..0f4978d78dd86700d0961236461cb6a7ca632250 100644 (file)
@@ -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);
 }