Remove traces of ~str
authorYehuda Katz <wycats@gmail.com>
Tue, 20 May 2014 06:14:49 +0000 (23:14 -0700)
committerYehuda Katz <wycats@gmail.com>
Tue, 20 May 2014 06:14:49 +0000 (23:14 -0700)
14 files changed:
src/bin/cargo-compile.rs
src/bin/cargo-read-manifest.rs
src/bin/cargo-verify-project.rs
src/bin/cargo.rs
src/cargo/core/dependency.rs
src/cargo/core/errors.rs
src/cargo/core/package.rs
src/cargo/core/summary.rs
src/cargo/lib.rs
src/cargo/ops/cargo_read_manifest.rs
src/cargo/ops/cargo_rustc.rs
src/cargo/util/important_paths.rs
src/cargo/util/process_builder.rs
src/cargo/util/result.rs

index 208b157920dfc54290b7b6b05d2004b7e8ad1300..bd4ca15c5053ce5c43e78dd390f6e5afa211ea13 100644 (file)
@@ -29,7 +29,7 @@ fn execute(options: Options) -> CLIResult<Option<()>> {
         None => try!(find_project(os::getcwd(), "Cargo.toml".to_owned())
                     .map(|path| path.join("Cargo.toml"))
                     .to_result(|err|
-                        CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err.to_str()), 102)))
+                        CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err), 102)))
     };
 
     compile(root.as_str().unwrap().as_slice()).map(|_| None).to_cli(101)
index 01c11dfdf4761f28a71d608a7f015c620f9826f1..48e8f85b89b68e0baa00ef3e4d4f54105e316ebc 100644 (file)
@@ -24,8 +24,8 @@ fn main() {
 fn execute(options: Options) -> CLIResult<Option<Package>> {
     read_manifest(options.manifest_path.as_slice()).map(|m| Some(m))
         .map_err(|err| CLIError {
-            msg: err.get_desc().to_owned(),
-            detail: err.get_detail().map(|s| s.to_owned()),
+            msg: err.get_desc().to_strbuf(),
+            detail: err.get_detail().map(|s| s.to_strbuf()),
             exit_code: 1
         })
 }
index 512ecc75126d7337e9c4244737fa90451f85e708..c04287cffdaa09aa118996edfc8af3bd0fbdb28f 100644 (file)
@@ -14,11 +14,11 @@ use getopts::{reqopt,getopts};
 fn main() {
     let arguments: Vec<StrBuf> = args().iter().map(|a| a.to_strbuf()).collect();
 
-    let opts = ~[
+    let opts = vec!(
         reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
-    ];
+    );
 
-    let matches = match getopts(arguments.tail(), opts) {
+    let matches = match getopts(arguments.tail(), opts.as_slice()) {
         Ok(m) => m,
         Err(_) => {
             fail("missing-argument", "manifest");
index d2e1c46e8fddffd661feae590c5e706556de0307..800c848645c01c147b28437c2a581a7c103bde52 100644 (file)
@@ -18,7 +18,7 @@ fn main() {
 
 #[deriving(Encodable)]
 struct ProjectLocation {
-    root: ~str
+    root: StrBuf
 }
 
 /**
@@ -32,17 +32,17 @@ fn execute() {
         Err(err) => return handle_error(err)
     };
 
-    if cmd == "config-for-key".to_owned() { execute_main_without_stdin(config_for_key) }
-    else if cmd == "config-list".to_owned() { execute_main_without_stdin(config_list) }
-    else if cmd == "locate-project".to_owned() { execute_main_without_stdin(locate_project) }
+    if cmd == "config-for-key".to_strbuf() { execute_main_without_stdin(config_for_key) }
+    else if cmd == "config-list".to_strbuf() { execute_main_without_stdin(config_list) }
+    else if cmd == "locate-project".to_strbuf() { execute_main_without_stdin(locate_project) }
 }
 
-fn process(mut args: Vec<~str>) -> CLIResult<(~str, Vec<~str>)> {
-    args = Vec::from_slice(args.tail());
-    let head = try!(args.iter().nth(0).to_result(|_| CLIError::new("No subcommand found", None, 1))).to_owned();
+fn process(args: Vec<~str>) -> CLIResult<(StrBuf, Vec<StrBuf>)> {
+    let args: Vec<StrBuf> = args.tail().iter().map(|a| a.to_strbuf()).collect();
+    let head = try!(args.iter().nth(0).to_result(|_| CLIError::new("No subcommand found", None::<&str>, 1))).to_owned();
     let tail = Vec::from_slice(args.tail());
 
-    Ok((head, tail))
+    Ok((head.to_strbuf(), tail))
 }
 
 #[deriving(Encodable)]
@@ -64,7 +64,7 @@ impl FlagConfig for ConfigForKeyFlags {
 
 fn config_for_key(args: ConfigForKeyFlags) -> CLIResult<Option<ConfigOut>> {
     let value = try!(config::get_config(os::getcwd(), args.key.as_slice()).to_result(|err|
-        CLIError::new("Couldn't load configuration", Some(err.to_str()), 1)));
+        CLIError::new("Couldn't load configuration", Some(err), 1)));
 
     if args.human {
         println!("{}", value);
@@ -89,7 +89,7 @@ impl FlagConfig for ConfigListFlags {
 
 fn config_list(args: ConfigListFlags) -> CLIResult<Option<ConfigOut>> {
     let configs = try!(config::all_configs(os::getcwd()).to_result(|err|
-        CLIError::new("Couldn't load conifguration", Some(err.to_str()), 1)));
+        CLIError::new("Couldn't load conifguration", Some(err), 1)));
 
     if args.human {
         for (key, value) in configs.iter() {
@@ -102,11 +102,11 @@ fn config_list(args: ConfigListFlags) -> CLIResult<Option<ConfigOut>> {
 }
 
 fn locate_project(_: NoFlags) -> CLIResult<Option<ProjectLocation>> {
-    let root = try!(find_project(os::getcwd(), "Cargo.toml".to_owned()).to_result(|err|
-        CLIError::new(err.to_str(), None, 1)));
+    let root = try!(find_project(os::getcwd(), "Cargo.toml").to_result(|err|
+        CLIError::new(err.to_str(), None::<&str>, 1)));
 
     let string = try!(root.as_str().to_result(|_|
-        CLIError::new(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), None, 1)));
+        CLIError::new(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), None::<&str>, 1)));
 
-    Ok(Some(ProjectLocation { root: string.to_owned() }))
+    Ok(Some(ProjectLocation { root: string.to_strbuf() }))
 }
index c2ec45890ff0eb0f5baab5e62ebe15b124943aaf..2e0109e1638a347e2531e0efdaa282a8cfc1be32 100644 (file)
@@ -4,28 +4,28 @@ use util::CargoResult;
 
 #[deriving(Eq,Clone,Show)]
 pub struct Dependency {
-    name: ~str,
+    name: StrBuf,
     req: VersionReq
 }
 
 impl Dependency {
     pub fn new(name: &str, req: &VersionReq) -> Dependency {
         Dependency {
-            name: name.to_owned(),
+            name: name.to_strbuf(),
             req: req.clone()
         }
     }
 
     pub fn parse(name: &str, version: &str) -> CargoResult<Dependency> {
         Ok(Dependency {
-            name: name.to_owned(),
+            name: name.to_strbuf(),
             req: try!(VersionReq::parse(version))
         })
     }
 
     pub fn exact(name: &str, version: &Version) -> Dependency {
         Dependency {
-            name: name.to_owned(),
+            name: name.to_strbuf(),
             req: VersionReq::exact(version)
         }
     }
@@ -41,15 +41,15 @@ impl Dependency {
 
 #[deriving(Eq,Clone,Encodable)]
 pub struct SerializedDependency {
-    name: ~str,
-    req: ~str
+    name: StrBuf,
+    req: StrBuf
 }
 
 impl SerializedDependency {
     pub fn from_dependency(dep: &Dependency) -> SerializedDependency {
         SerializedDependency {
-            name: dep.get_name().to_owned(),
-            req: dep.get_version_req().to_str()
+            name: dep.get_name().to_strbuf(),
+            req: format_strbuf!("{}", dep.get_version_req())
         }
     }
 }
index a0c8ffe15cb6621fe58c72efe00d4d6c6236733b..8e3fc9184173e077312e9c562628f84db6b9eb02 100644 (file)
@@ -24,14 +24,15 @@ impl Show for CargoError {
 }
 
 pub struct CLIError {
-    pub msg: ~str,
-    pub detail: Option<~str>,
+    pub msg: StrBuf,
+    pub detail: Option<StrBuf>,
     pub exit_code: uint
 }
 
 impl CLIError {
-    pub fn new<T: ToStr>(msg: T, detail: Option<~str>, exit_code: uint) -> CLIError {
-        CLIError { msg: msg.to_str(), detail: detail, exit_code: exit_code }
+    pub fn new<T: Show, U: Show>(msg: T, detail: Option<U>, exit_code: uint) -> CLIError {
+        let detail = detail.map(|d| format_strbuf!("{}", d));
+        CLIError { msg: format_strbuf!("{}", msg), detail: detail, exit_code: exit_code }
     }
 }
 
@@ -42,11 +43,11 @@ impl Show for CLIError {
 }
 
 pub enum InternalError {
-    StringConversionError(~str, &'static str),
-    MissingManifest(Path, ~str),
+    StringConversionError(StrBuf, &'static str),
+    MissingManifest(Path, StrBuf),
     WrappedIoError(IoError),
-    PathError(~str),
-    Described(~str),
+    PathError(StrBuf),
+    Described(StrBuf),
     Other
 }
 
@@ -71,7 +72,7 @@ impl Show for InternalError {
 }
 
 impl CargoError {
-    pub fn cli(msg: ~str, detail: Option<~str>, exit_code: uint) -> CargoError {
+    pub fn cli(msg: StrBuf, detail: Option<StrBuf>, exit_code: uint) -> CargoError {
         CargoCLIError(CLIError::new(msg, detail, exit_code))
     }
 
@@ -79,8 +80,8 @@ impl CargoError {
         CargoInternalError(error)
     }
 
-    pub fn described<T: ToStr>(description: T) -> CargoError {
-        CargoInternalError(Described(description.to_str()))
+    pub fn described<T: Show>(description: T) -> CargoError {
+        CargoInternalError(Described(format_strbuf!("{}", description)))
     }
 
     pub fn other() -> CargoError {
@@ -90,7 +91,7 @@ impl CargoError {
     pub fn cli_error(self) -> CLIError {
         match self {
             CargoInternalError(err) =>
-                CLIError::new("An unexpected error occurred", Some(err.to_str()), 100),
+                CLIError::new("An unexpected error occurred", Some(err), 100),
             CargoCLIError(err) => err
         }
     }
index 25174c5b16de7fac5277cb64576534d55fcb4e97..b054f8b7cf4b152297cf75ba5d4135597f144545 100644 (file)
@@ -23,12 +23,12 @@ pub struct Package {
 
 #[deriving(Encodable)]
 struct SerializedPackage {
-    name: ~str,
-    version: ~str,
+    name: StrBuf,
+    version: StrBuf,
     dependencies: Vec<SerializedDependency>,
     authors: Vec<StrBuf>,
     targets: Vec<Target>,
-    root: ~str
+    root: StrBuf
 }
 
 impl<E, S: Encoder<E>> Encodable<S, E> for Package {
@@ -38,12 +38,12 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Package {
         let name_ver = summary.get_name_ver();
 
         SerializedPackage {
-            name: name_ver.get_name().to_owned(),
-            version: name_ver.get_version().to_str(),
+            name: name_ver.get_name().to_strbuf(),
+            version: format_strbuf!("{}", name_ver.get_version()),
             dependencies: summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(),
             authors: Vec::from_slice(manifest.get_authors()),
             targets: Vec::from_slice(manifest.get_targets()),
-            root: self.root.as_str().unwrap().to_owned()
+            root: self.root.as_str().unwrap().to_strbuf()
         }.encode(s)
     }
 }
index 78059427c0cd2ee5db1fecac7bdd184b290c3974..de86b39e96fdbc8e89239804f87475bec51e66e3 100644 (file)
@@ -36,14 +36,14 @@ impl Summary {
 }
 
 pub trait SummaryVec {
-    fn names(&self) -> Vec<~str>;
+    fn names(&self) -> Vec<StrBuf>;
     fn deps(&self) -> Vec<Dependency>;
 }
 
 impl SummaryVec for Vec<Summary> {
     // TODO: Move to Registery
-    fn names(&self) -> Vec<~str> {
-        self.iter().map(|summary| summary.name_ver.get_name().to_owned()).collect()
+    fn names(&self) -> Vec<StrBuf> {
+        self.iter().map(|summary| summary.name_ver.get_name().to_strbuf()).collect()
     }
 
     // TODO: Delete
index 44d26a9ac760839df15e5f624d01daed42ba43f9..76fd076364e9835cb6e8f5f68978746d0c1eb6a9 100644 (file)
@@ -89,15 +89,15 @@ fn args() -> Vec<StrBuf> {
 
 fn flags_from_args<T: RepresentsFlags>() -> CLIResult<T> {
     let mut decoder = FlagDecoder::new::<T>(args().tail());
-    Decodable::decode(&mut decoder).to_result(|e: HammerError| CLIError::new(e.message, None, 1))
+    Decodable::decode(&mut decoder).to_result(|e: HammerError| CLIError::new(e.message, None::<&str>, 1))
 }
 
 fn json_from_stdin<T: RepresentsJSON>() -> CLIResult<T> {
     let mut reader = io::stdin();
-    let input = try!(reader.read_to_str().to_result(|_| CLIError::new("Standard in did not exist or was not UTF-8", None, 1)));
+    let input = try!(reader.read_to_str().to_result(|_| CLIError::new("Standard in did not exist or was not UTF-8", None::<&str>, 1)));
 
-    let json = try!(json::from_str(input).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.clone()), 1)));
+    let json = try!(json::from_str(input).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.to_strbuf()), 1)));
     let mut decoder = json::Decoder::new(json);
 
-    Decodable::decode(&mut decoder).to_result(|e: json::DecoderError| CLIError::new("Could not process standard in as input", Some(e.to_str()), 1))
+    Decodable::decode(&mut decoder).to_result(|e: json::DecoderError| CLIError::new("Could not process standard in as input", Some(e), 1))
 }
index 0fae527c1320096fec5711eef1f3e43b9a542f37..cf44be3a1f9ccd70469ff9363c7e7cf7b56740fc 100644 (file)
@@ -6,10 +6,10 @@ use util::{toml_error,human_error,CargoResult,CargoError};
 
 pub fn read_manifest(path: &str) -> CargoResult<Package> {
     let root = try!(parse_from_file(path).map_err(|err: CargoError|
-        human_error(format!("Cargo.toml is not valid Toml"), format!("path={}", path), err)));
+        human_error("Cargo.toml is not valid Toml".to_strbuf(), format_strbuf!("path={}", path), err)));
 
     let toml = try!(load_toml(root).map_err(|err: CargoError|
-        human_error(format!("Cargo.toml is not a valid Cargo manifest"), format!("path={}", path), err)));
+        human_error("Cargo.toml is not a valid Cargo manifest".to_strbuf(), format_strbuf!("path={}", path), err)));
 
     toml.to_package(path)
 }
index 53344a28439dfd23fd9c84ad49f9304671e12624..510031582313510981953fcc41a6a3282a91689d 100644 (file)
@@ -97,5 +97,5 @@ fn rustc_to_cargo_err(args: &[StrBuf], cwd: &Path, err: CargoError) -> CargoErro
         msg
     };
 
-    human_error(msg.to_owned(), format!("root={}", cwd.display()), err)
+    human_error(msg, format_strbuf!("root={}", cwd.display()), err)
 }
index ec53e41f4b9bd51a1f9e44c67583f5de2e536627..8238309dca4d40742fb4280706836b9a6355b6de 100644 (file)
@@ -1,6 +1,6 @@
 use util::{other_error,CargoResult,CargoError};
 
-pub fn find_project(pwd: Path, file: ~str) -> CargoResult<Path> {
+pub fn find_project(pwd: Path, file: &str) -> CargoResult<Path> {
     let mut current = pwd.clone();
 
     loop {
index 5ba79f121b6a63a2f207514a58a47cf92526d35b..54116aba5852c1472d367e9a353162de2684a10f 100644 (file)
@@ -64,7 +64,7 @@ impl ProcessBuilder {
         if exit.success() {
             Ok(())
         } else {
-            let msg = format!("Could not execute process `{}`", self.debug_string());
+            let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
             Err(process_error(msg, exit, None))
         }
     }
@@ -78,7 +78,7 @@ impl ProcessBuilder {
         if output.status.success() {
             Ok(output)
         } else {
-            let msg = format!("Could not execute process `{}`", self.debug_string());
+            let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
             Err(process_error(msg, output.status.clone(), Some(output)))
         }
     }
index c57562fa5ae6e5f295f185efa325c303516a4606..a2600fbf3f8e3117fab497e96dd7f75e8c02bafe 100644 (file)
@@ -33,7 +33,7 @@ pub fn io_error(err: IoError) -> CargoError {
     }
 }
 
-pub fn process_error(detail: ~str, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
+pub fn process_error(detail: StrBuf, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
     CargoError {
         kind: ProcessError(exit, output),
         desc: BoxedDescription(detail),
@@ -42,7 +42,7 @@ pub fn process_error(detail: ~str, exit: ProcessExit, output: Option<ProcessOutp
     }
 }
 
-pub fn human_error(desc: ~str, detail: ~str, cause: CargoError) -> CargoError {
+pub fn human_error(desc: StrBuf, detail: StrBuf, cause: CargoError) -> CargoError {
     CargoError {
         kind: HumanReadableError,
         desc: BoxedDescription(desc),
@@ -64,14 +64,14 @@ pub fn toml_error(desc: &'static str, error: toml::Error) -> CargoError {
 pub struct CargoError {
     pub kind: CargoErrorKind,
     desc: CargoErrorDescription,
-    detail: Option<~str>,
+    detail: Option<StrBuf>,
     cause: Option<Box<CargoError>>
 }
 
 #[deriving(Show,Clone)]
 enum CargoErrorDescription {
     StaticDescription(&'static str),
-    BoxedDescription(~str)
+    BoxedDescription(StrBuf)
 }
 
 impl CargoError {
@@ -86,24 +86,24 @@ impl CargoError {
         self.detail.as_ref().map(|s| s.as_slice())
     }
 
-    pub fn with_detail(mut self, detail: ~str) -> CargoError {
-        self.detail = Some(detail);
+    pub fn with_detail<T: Show>(mut self, detail: T) -> CargoError {
+        self.detail = Some(format_strbuf!("{}", detail));
         self
     }
 
     pub fn to_cli(self, exit_code: uint) -> CLIError {
         match self {
             CargoError { kind: HumanReadableError, desc: BoxedDescription(desc), detail: detail, .. } => {
-                CLIError::new(desc, detail, exit_code)
+                CLIError::new(desc, detail.map(|d| d.to_strbuf()), exit_code)
             },
             CargoError { kind: InternalError, desc: StaticDescription(desc), detail: None, .. } => {
-                CLIError::new("An unexpected error occurred", Some(desc.to_owned()), exit_code)
+                CLIError::new("An unexpected error occurred", Some(desc), exit_code)
             },
             CargoError { kind: InternalError, desc: StaticDescription(desc), detail: Some(detail), .. } => {
-                CLIError::new("An unexpected error occurred", Some(format!("{}\n{}", desc, detail)), exit_code)
+                CLIError::new("An unexpected error occurred", Some(format_strbuf!("{}\n{}", desc, detail)), exit_code)
             },
             _ => {
-                CLIError::new("An unexpected error occurred", None, exit_code)
+                CLIError::new("An unexpected error occurred", None::<&str>, exit_code)
             }
         }
     }
@@ -155,7 +155,7 @@ pub struct CargoCliError {
     kind: CargoCliErrorKind,
     exit_status: uint,
     desc: &'static str,
-    detail: Option<~str>,
+    detail: Option<StrBuf>,
     cause: Option<CargoError>
 }