]> git.lizzy.rs Git - rust.git/blobdiff - src/librust/rust.rs
librust: Stop rust tool from crashing on macos.
[rust.git] / src / librust / rust.rs
index 63a0ef0842e0e9a5070f1386223fc4a1c130df9b..746b75292315aecc52766e843ad45371eccc98cc 100644 (file)
@@ -13,7 +13,7 @@
 // FIXME #2238 Make run only accept source that emits an executable
 
 #[link(name = "rust",
-       vers = "0.7",
+       vers = "0.8-pre",
        uuid = "4a24da33-5cc8-4037-9352-2cbe9bd9d27c",
        url = "https://github.com/mozilla/rust/tree/master/src/rust")];
 
@@ -43,24 +43,30 @@ fn is_valid(&self) -> bool {
     }
 }
 
-enum Action<'self> {
-    Call(&'self fn:Copy(args: &[~str]) -> ValidUsage),
-    CallMain(&'static str, &'self fn:Copy()),
+enum Action {
+    Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
+    CallMain(&'static str, extern "Rust" fn()),
 }
 
 enum UsageSource<'self> {
     UsgStr(&'self str),
-    UsgCall(&'self fn:Copy()),
+    UsgCall(extern "Rust" fn()),
 }
 
 struct Command<'self> {
     cmd: &'self str,
-    action: Action<'self>,
+    action: Action,
     usage_line: &'self str,
     usage_full: UsageSource<'self>,
 }
 
-static COMMANDS: &'static [Command<'static>] = &[
+static NUM_OF_COMMANDS: uint = 7;
+
+// FIXME(#7617): should just be &'static [Command<'static>]
+// but mac os doesn't seem to like that and tries to loop
+// past the end of COMMANDS in usage thus passing garbage
+// to str::repeat and eventually malloc and crashing.
+static COMMANDS: [Command<'static>, .. NUM_OF_COMMANDS] = [
     Command{
         cmd: "build",
         action: CallMain("rustc", rustc::main),
@@ -118,13 +124,13 @@ struct Command<'self> {
 ];
 
 fn rustc_help() {
-    rustc::usage(copy os::args()[0])
+    rustc::usage(os::args()[0].clone())
 }
 
 fn find_cmd(command_string: &str) -> Option<Command> {
     do COMMANDS.iter().find_ |command| {
         command.cmd == command_string
-    }.map_consume(|x| copy *x)
+    }.map_consume(|x| *x)
 }
 
 fn cmd_help(args: &[~str]) -> ValidUsage {
@@ -132,13 +138,13 @@ fn print_usage(command_string: ~str) -> ValidUsage {
         match find_cmd(command_string) {
             Some(command) => {
                 match command.action {
-                    CallMain(prog, _) => io::println(fmt!(
+                    CallMain(prog, _) => printfln!(
                         "The %s command is an alias for the %s program.",
-                        command.cmd, prog)),
+                        command.cmd, prog),
                     _       => ()
                 }
                 match command.usage_full {
-                    UsgStr(msg) => io::println(fmt!("%s\n", msg)),
+                    UsgStr(msg) => printfln!("%s\n", msg),
                     UsgCall(f)  => f(),
                 }
                 Valid(0)
@@ -148,7 +154,7 @@ fn print_usage(command_string: ~str) -> ValidUsage {
     }
 
     match args {
-        [ref command_string] => print_usage(copy *command_string),
+        [ref command_string] => print_usage((*command_string).clone()),
         _                    => Invalid
     }
 }
@@ -211,8 +217,7 @@ fn usage() {
 
     for COMMANDS.iter().advance |command| {
         let padding = " ".repeat(INDENT - command.cmd.len());
-        io::println(fmt!("    %s%s%s",
-                         command.cmd, padding, command.usage_line));
+        printfln!("    %s%s%s", command.cmd, padding, command.usage_line);
     }
 
     io::print(