Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JustForShow] try!() -> ? #2497

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Compilation can be customized with the `bench` profile in the manifest.
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let err = try!(ops::run_benches(&root, &ops, &options.arg_args));
let err = ops::run_benches(&root, &ops, &options.arg_args)?;
match err {
None => Ok(None),
Some(err) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let opts = CompileOptions {
config: config,
Expand All @@ -86,6 +86,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: None,
};

try!(ops::compile(&root, &opts));
ops::compile(&root, &opts)?;
Ok(None)
}
4 changes: 3 additions & 1 deletion src/bin/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(question_mark)]

extern crate cargo;
extern crate url;
extern crate env_logger;
Expand Down Expand Up @@ -171,7 +173,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
}
each_subcommand!(cmd);

try!(execute_subcommand(config, &args[1], &args));
execute_subcommand(config, &args[1], &args)?;
Ok(None)
}

Expand Down
4 changes: 2 additions & 2 deletions src/bin/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let opts = ops::CleanOptions {
config: config,
spec: &options.flag_package,
target: options.flag_target.as_ref().map(|s| &s[..]),
release: options.flag_release,
};
try!(ops::clean(&root, &opts));
ops::clean(&root, &opts)?;
Ok(None)
}
4 changes: 2 additions & 2 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let doc_opts = ops::DocOptions {
open_result: options.flag_open,
Expand All @@ -75,6 +75,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

try!(ops::doc(&root, &doc_opts));
ops::doc(&root, &doc_opts)?;
Ok(None)
}
4 changes: 2 additions & 2 deletions src/bin/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(ops::fetch(&root, config));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
ops::fetch(&root, config)?;
Ok(None)
}

4 changes: 2 additions & 2 deletions src/bin/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

try!(ops::generate_lockfile(&root, config));
ops::generate_lockfile(&root, config)?;
Ok(None)
}
2 changes: 1 addition & 1 deletion src/bin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
name: flag_name.as_ref().map(|s| s.as_ref()),
};

try!(ops::init(opts, config));
ops::init(opts, config)?;
Ok(None)
}

12 changes: 6 additions & 6 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
};

let source = if let Some(url) = options.flag_git {
let url = try!(url.to_url().map_err(human));
let url = url.to_url().map_err(human)?;
let gitref = if let Some(branch) = options.flag_branch {
GitReference::Branch(branch)
} else if let Some(tag) = options.flag_tag {
Expand All @@ -116,21 +116,21 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
};
SourceId::for_git(&url, gitref)
} else if let Some(path) = options.flag_path {
try!(SourceId::for_path(&config.cwd().join(path)))
SourceId::for_path(&config.cwd().join(path))?
} else if options.arg_crate == None {
try!(SourceId::for_path(&config.cwd()))
SourceId::for_path(&config.cwd())?
} else {
try!(SourceId::for_central(config))
SourceId::for_central(config)?
};

let krate = options.arg_crate.as_ref().map(|s| &s[..]);
let vers = options.flag_vers.as_ref().map(|s| &s[..]);
let root = options.flag_root.as_ref().map(|s| &s[..]);

if options.flag_list {
try!(ops::install_list(root, config));
ops::install_list(root, config)?;
} else {
try!(ops::install(root, krate, &source, vers, &compile_opts));
ops::install(root, krate, &source, vers, &compile_opts)?;
}
Ok(None)
}
2 changes: 1 addition & 1 deletion src/bin/locate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct ProjectLocation {

pub fn execute(flags: LocateProjectFlags,
config: &Config) -> CliResult<Option<ProjectLocation>> {
let root = try!(find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())?;

let string = try!(root.to_str()
.chain_error(|| human("Your project path contains \
Expand Down
8 changes: 4 additions & 4 deletions src/bin/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
let token = match options.arg_token.clone() {
Some(token) => token,
None => {
let src = try!(SourceId::for_central(config));
let src = SourceId::for_central(config)?;
let mut src = RegistrySource::new(&src, config);
try!(src.update());
let config = try!(src.config());
src.update()?;
let config = src.config()?;
let host = options.flag_host.clone().unwrap_or(config.api);
println!("please visit {}me and paste the API Token below", host);
let mut line = String::new();
Expand All @@ -53,7 +53,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
};

let token = token.trim().to_string();
try!(ops::registry_login(config, token));
ops::registry_login(config, token)?;
Ok(None)
}

4 changes: 2 additions & 2 deletions src/bin/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let manifest = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let manifest = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let options = OutputMetadataOptions {
features: options.flag_features,
Expand All @@ -54,6 +54,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo
version: options.flag_format_version,
};

let result = try!(output_metadata(options, config));
let result = output_metadata(options, config)?;
Ok(Some(result))
}
2 changes: 1 addition & 1 deletion src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
name: flag_name.as_ref().map(|s| s.as_ref()),
};

try!(ops::new(opts, config));
ops::new(opts, config)?;
Ok(None)
}

2 changes: 1 addition & 1 deletion src/bin/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
to_remove: options.flag_remove,
list: options.flag_list,
};
try!(ops::modify_owners(config, &opts));
ops::modify_owners(config, &opts)?;
Ok(None)
}

2 changes: 1 addition & 1 deletion src/bin/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
try!(ops::package(&root, config,
!options.flag_no_verify,
options.flag_list,
Expand Down
4 changes: 2 additions & 2 deletions src/bin/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ pub fn execute(options: Options,
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd())?;

let spec = options.arg_spec.as_ref().map(|s| &s[..]);
let spec = try!(ops::pkgid(&root, spec, config));
let spec = ops::pkgid(&root, spec, config)?;
println!("{}", spec);
Ok(None)
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
..
} = options;

let root = try!(find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd()));
try!(ops::publish(&root, config, token, host, !no_verify));
let root = find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd())?;
ops::publish(&root, config, token, host, !no_verify)?;
Ok(None)
}
6 changes: 3 additions & 3 deletions src/bin/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Options:
pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>> {
debug!("executing; cmd=cargo-read-manifest; args={:?}",
env::args().collect::<Vec<_>>());
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))?;

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let pkg = try!(Package::for_path(&root, config));
let pkg = Package::for_path(&root, config)?;
Ok(Some(pkg))
}
4 changes: 2 additions & 2 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
options.flag_quiet,
&options.flag_color));

let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let (mut examples, mut bins) = (Vec::new(), Vec::new());
if let Some(s) = options.flag_bin {
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: None,
};

match try!(ops::run(&root, &compile_opts, &options.arg_args)) {
match ops::run(&root, &compile_opts, &options.arg_args)? {
None => Ok(None),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
};

try!(ops::compile(&root, &opts));
ops::compile(&root, &opts)?;
Ok(None)
}

2 changes: 1 addition & 1 deletion src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

try!(ops::doc(&root, &doc_opts));
ops::doc(&root, &doc_opts)?;

Ok(None)
}
2 changes: 1 addition & 1 deletion src/bin/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
..
} = options;

try!(ops::search(&query.join("+"), config, host, cmp::min(100, limit.unwrap_or(10)) as u8));
ops::search(&query.join("+"), config, host, cmp::min(100, limit.unwrap_or(10)) as u8)?;
Ok(None)
}
4 changes: 2 additions & 2 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let ops = ops::TestOptions {
no_run: options.flag_no_run,
Expand All @@ -102,7 +102,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let err = try!(ops::run_tests(&root, &ops, &options.arg_args));
let err = ops::run_tests(&root, &ops, &options.arg_args)?;
match err {
None => Ok(None),
Some(err) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
&options.flag_color));

let root = options.flag_root.as_ref().map(|s| &s[..]);
try!(ops::uninstall(root, &options.arg_spec, &options.flag_bin, config));
ops::uninstall(root, &options.arg_spec, &options.flag_bin, config)?;
Ok(None)
}

4 changes: 2 additions & 2 deletions src/bin/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure_shell(options.flag_verbose,
options.flag_quiet,
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let update_opts = ops::UpdateOptions {
aggressive: options.flag_aggressive,
Expand All @@ -66,6 +66,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
config: config,
};

try!(ops::update_lockfile(&root, &update_opts));
ops::update_lockfile(&root, &update_opts)?;
Ok(None)
}
2 changes: 1 addition & 1 deletion src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DependencyInner {
version: Option<&str>,
source_id: &SourceId) -> CargoResult<DependencyInner> {
let version_req = match version {
Some(v) => try!(VersionReq::parse(v)),
Some(v) => VersionReq::parse(v)?,
None => VersionReq::any()
};

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Package {

pub fn for_path(manifest_path: &Path, config: &Config) -> CargoResult<Package> {
let path = manifest_path.parent().unwrap();
let source_id = try!(SourceId::for_path(path));
let source_id = SourceId::for_path(path)?;
let (pkg, _) = try!(ops::read_package(&manifest_path, &source_id,
config));
Ok(pkg)
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Encodable for PackageId {

impl Decodable for PackageId {
fn decode<D: Decoder>(d: &mut D) -> Result<PackageId, D::Error> {
let string: String = try!(Decodable::decode(d));
let string: String = Decodable::decode(d)?;
let regex = Regex::new(r"^([^ ]+) ([^ ]+) \(([^\)]+)\)$").unwrap();
let captures = regex.captures(&string).expect("invalid serialized PackageId");

Expand Down Expand Up @@ -121,7 +121,7 @@ pub struct Metadata {
impl PackageId {
pub fn new<T: ToSemver>(name: &str, version: T,
sid: &SourceId) -> CargoResult<PackageId> {
let v = try!(version.to_semver().map_err(PackageIdError::InvalidVersion));
let v = version.to_semver().map_err(PackageIdError::InvalidVersion)?;
Ok(PackageId {
inner: Arc::new(PackageIdInner {
name: name.to_string(),
Expand Down Expand Up @@ -163,10 +163,10 @@ impl Metadata {

impl fmt::Display for PackageId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
try!(write!(f, "{} v{}", self.inner.name, self.inner.version));
write!(f, "{} v{}", self.inner.name, self.inner.version)?;

if !self.inner.source_id.is_default_registry() {
try!(write!(f, " ({})", self.inner.source_id));
write!(f, " ({})", self.inner.source_id)?;
}

Ok(())
Expand Down
Loading