Skip to content

Commit

Permalink
Auto merge of #3283 - saschagrunert:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Changed try! macros to ? operator

Since the stabilization of the ? operator (release 1.13.0)
the ? operator should be used to use idiomatic Rust.
  • Loading branch information
bors authored Nov 15, 2016
2 parents a3d86dd + c313ed5 commit 8b5aec1
Show file tree
Hide file tree
Showing 91 changed files with 1,365 additions and 1,366 deletions.
16 changes: 8 additions & 8 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ 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()));
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let ops = ops::TestOptions {
no_run: options.flag_no_run,
no_fail_fast: false,
Expand All @@ -102,8 +102,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let ws = try!(Workspace::new(&root, config));
let err = try!(ops::run_benches(&ws, &ops, &options.arg_args));
let ws = Workspace::new(&root, config)?;
let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
match err {
None => Ok(None),
Some(err) => {
Expand Down
16 changes: 8 additions & 8 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ the --release flag will use the `release` profile instead.
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-build; args={:?}",
env::args().collect::<Vec<_>>());
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

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 @@ -97,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
target_rustc_args: None,
};

let ws = try!(Workspace::new(&root, config));
try!(ops::compile(&ws, &opts));
let ws = Workspace::new(&root, config)?;
ops::compile(&ws, &opts)?;
Ok(None)
}
20 changes: 10 additions & 10 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ each_subcommand!(declare_mod);
on this top-level information.
*/
fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(flags.flag_verbose,
flags.flag_quiet,
&flags.flag_color,
flags.flag_frozen,
flags.flag_locked));
config.configure(flags.flag_verbose,
flags.flag_quiet,
&flags.flag_color,
flags.flag_frozen,
flags.flag_locked)?;

init_git_transports(config);
let _token = cargo::util::job::setup();
Expand All @@ -139,8 +139,8 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
}

if let Some(ref code) = flags.flag_explain {
let mut procss = try!(config.rustc()).process();
try!(procss.arg("--explain").arg(code).exec().map_err(human));
let mut procss = config.rustc()?.process();
procss.arg("--explain").arg(code).exec().map_err(human)?;
return Ok(None)
}

Expand Down Expand Up @@ -189,7 +189,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
return Ok(None)
}

let alias_list = try!(aliased_command(&config, &args[1]));
let alias_list = aliased_command(&config, &args[1])?;
let args = match alias_list {
Some(alias_command) => {
let chain = args.iter().take(1)
Expand All @@ -205,7 +205,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
}
None => args,
};
try!(execute_subcommand(config, &args[1], &args));
execute_subcommand(config, &args[1], &args)?;
Ok(None)
}

Expand Down Expand Up @@ -239,7 +239,7 @@ fn aliased_command(config: &Config, command: &String) -> CargoResult<Option<Vec<
}
},
Err(_) => {
let value = try!(config.get_list(&alias_name));
let value = config.get_list(&alias_name)?;
if let Some(record) = value {
let alias_commands: Vec<String> = record.val.iter()
.map(|s| s.0.to_string()).collect();
Expand Down
16 changes: 8 additions & 8 deletions src/bin/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ and its format, see the `cargo help pkgid` command.

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

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,
};
let ws = try!(Workspace::new(&root, config));
try!(ops::clean(&ws, &opts));
let ws = Workspace::new(&root, config)?;
ops::clean(&ws, &opts)?;
Ok(None)
}
16 changes: 8 additions & 8 deletions src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

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 empty = Vec::new();
let doc_opts = ops::DocOptions {
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
},
};

let ws = try!(Workspace::new(&root, config));
try!(ops::doc(&ws, &doc_opts));
let ws = Workspace::new(&root, config)?;
ops::doc(&ws, &doc_opts)?;
Ok(None)
}
16 changes: 8 additions & 8 deletions src/bin/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ all updated.
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let ws = try!(Workspace::new(&root, config));
try!(ops::fetch(&ws));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
ops::fetch(&ws)?;
Ok(None)
}

16 changes: 8 additions & 8 deletions src/bin/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Options:

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

let ws = try!(Workspace::new(&root, config));
try!(ops::generate_lockfile(&ws));
let ws = Workspace::new(&root, config)?;
ops::generate_lockfile(&ws)?;
Ok(None)
}
14 changes: 7 additions & 7 deletions src/bin/git_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ Options:
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let Options { flag_url: url, flag_reference: reference, .. } = options;

let url = try!(url.to_url());
let url = url.to_url()?;

let reference = GitReference::Branch(reference.clone());
let source_id = SourceId::for_git(&url, reference);

let mut source = GitSource::new(&source_id, config);

try!(source.update());
source.update()?;

Ok(None)
}
18 changes: 9 additions & 9 deletions src/bin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Options:

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>());
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;

Expand All @@ -57,11 +57,11 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
flag_name.as_ref().map(|s| s.as_ref()));

let opts_lib = opts.lib;
try!(ops::init(opts, config));
ops::init(opts, config)?;

try!(config.shell().status("Created", format!("{} project",
if opts_lib { "library" }
else {"binary (application)"})));
config.shell().status("Created", format!("{} project",
if opts_lib { "library" }
else {"binary (application)"}))?;

Ok(None)
}
Expand Down
22 changes: 11 additions & 11 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ The `--list` option will list all installed packages (and their versions).
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;

let compile_opts = ops::CompileOptions {
config: config,
Expand All @@ -119,7 +119,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());
let url = url.to_url()?;
let gitref = if let Some(branch) = options.flag_branch {
GitReference::Branch(branch)
} else if let Some(tag) = options.flag_tag {
Expand All @@ -131,21 +131,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::crates_io(config))
SourceId::crates_io(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, options.flag_force));
ops::install(root, krate, &source, vers, &compile_opts, options.flag_force)?;
}
Ok(None)
}
6 changes: 3 additions & 3 deletions src/bin/locate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ 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()
let string = root.to_str()
.chain_error(|| human("Your project path contains \
characters not representable in \
Unicode"))
.map_err(|e| CliError::new(e, 1)));
.map_err(|e| CliError::new(e, 1))?;

Ok(Some(ProjectLocation { root: string.to_string() }))
}
22 changes: 11 additions & 11 deletions src/bin/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ Options:
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked));
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked)?;
let token = match options.arg_token.clone() {
Some(token) => token,
None => {
let src = try!(SourceId::crates_io(config));
let src = SourceId::crates_io(config)?;
let mut src = RegistrySource::remote(&src, config);
try!(src.update());
let config = try!(src.config()).unwrap();
src.update()?;
let config = src.config()?.unwrap();
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();
let input = io::stdin();
try!(input.lock().read_line(&mut line).chain_error(|| {
input.lock().read_line(&mut line).chain_error(|| {
human("failed to read stdin")
}));
})?;
line
}
};

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

Loading

0 comments on commit 8b5aec1

Please sign in to comment.