From: Yehuda Katz Date: Tue, 20 May 2014 06:14:49 +0000 (-0700) Subject: Remove traces of ~str X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1057 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ca668c66055f94dca177b6afd9fe7a5f849ba735;p=cargo.git Remove traces of ~str --- diff --git a/src/bin/cargo-compile.rs b/src/bin/cargo-compile.rs index 208b15792..bd4ca15c5 100644 --- a/src/bin/cargo-compile.rs +++ b/src/bin/cargo-compile.rs @@ -29,7 +29,7 @@ fn execute(options: Options) -> CLIResult> { 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) diff --git a/src/bin/cargo-read-manifest.rs b/src/bin/cargo-read-manifest.rs index 01c11dfdf..48e8f85b8 100644 --- a/src/bin/cargo-read-manifest.rs +++ b/src/bin/cargo-read-manifest.rs @@ -24,8 +24,8 @@ fn main() { fn execute(options: Options) -> CLIResult> { 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 }) } diff --git a/src/bin/cargo-verify-project.rs b/src/bin/cargo-verify-project.rs index 512ecc751..c04287cff 100644 --- a/src/bin/cargo-verify-project.rs +++ b/src/bin/cargo-verify-project.rs @@ -14,11 +14,11 @@ use getopts::{reqopt,getopts}; fn main() { let arguments: Vec = 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"); diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index d2e1c46e8..800c84864 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -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)> { + let args: Vec = 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> { 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> { 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> { } fn locate_project(_: NoFlags) -> CLIResult> { - 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() })) } diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index c2ec45890..2e0109e16 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -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 { 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()) } } } diff --git a/src/cargo/core/errors.rs b/src/cargo/core/errors.rs index a0c8ffe15..8e3fc9184 100644 --- a/src/cargo/core/errors.rs +++ b/src/cargo/core/errors.rs @@ -24,14 +24,15 @@ impl Show for CargoError { } pub struct CLIError { - pub msg: ~str, - pub detail: Option<~str>, + pub msg: StrBuf, + pub detail: Option, pub exit_code: uint } impl CLIError { - pub fn new(msg: T, detail: Option<~str>, exit_code: uint) -> CLIError { - CLIError { msg: msg.to_str(), detail: detail, exit_code: exit_code } + pub fn new(msg: T, detail: Option, 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, exit_code: uint) -> CargoError { CargoCLIError(CLIError::new(msg, detail, exit_code)) } @@ -79,8 +80,8 @@ impl CargoError { CargoInternalError(error) } - pub fn described(description: T) -> CargoError { - CargoInternalError(Described(description.to_str())) + pub fn described(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 } } diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 25174c5b1..b054f8b7c 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -23,12 +23,12 @@ pub struct Package { #[deriving(Encodable)] struct SerializedPackage { - name: ~str, - version: ~str, + name: StrBuf, + version: StrBuf, dependencies: Vec, authors: Vec, targets: Vec, - root: ~str + root: StrBuf } impl> Encodable for Package { @@ -38,12 +38,12 @@ impl> Encodable 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) } } diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index 78059427c..de86b39e9 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -36,14 +36,14 @@ impl Summary { } pub trait SummaryVec { - fn names(&self) -> Vec<~str>; + fn names(&self) -> Vec; fn deps(&self) -> Vec; } impl SummaryVec for Vec { // 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 { + self.iter().map(|summary| summary.name_ver.get_name().to_strbuf()).collect() } // TODO: Delete diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 44d26a9ac..76fd07636 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -89,15 +89,15 @@ fn args() -> Vec { fn flags_from_args() -> CLIResult { let mut decoder = FlagDecoder::new::(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() -> CLIResult { 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)) } diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 0fae527c1..cf44be3a1 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -6,10 +6,10 @@ use util::{toml_error,human_error,CargoResult,CargoError}; pub fn read_manifest(path: &str) -> CargoResult { 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) } diff --git a/src/cargo/ops/cargo_rustc.rs b/src/cargo/ops/cargo_rustc.rs index 53344a284..510031582 100644 --- a/src/cargo/ops/cargo_rustc.rs +++ b/src/cargo/ops/cargo_rustc.rs @@ -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) } diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index ec53e41f4..8238309dc 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,6 +1,6 @@ use util::{other_error,CargoResult,CargoError}; -pub fn find_project(pwd: Path, file: ~str) -> CargoResult { +pub fn find_project(pwd: Path, file: &str) -> CargoResult { let mut current = pwd.clone(); loop { diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 5ba79f121..54116aba5 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -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))) } } diff --git a/src/cargo/util/result.rs b/src/cargo/util/result.rs index c57562fa5..a2600fbf3 100644 --- a/src/cargo/util/result.rs +++ b/src/cargo/util/result.rs @@ -33,7 +33,7 @@ pub fn io_error(err: IoError) -> CargoError { } } -pub fn process_error(detail: ~str, exit: ProcessExit, output: Option) -> CargoError { +pub fn process_error(detail: StrBuf, exit: ProcessExit, output: Option) -> CargoError { CargoError { kind: ProcessError(exit, output), desc: BoxedDescription(detail), @@ -42,7 +42,7 @@ pub fn process_error(detail: ~str, exit: ProcessExit, output: Option 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, cause: Option> } #[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(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, cause: Option }