Skip to content

Commit 8b5aec1

Browse files
authored
Auto merge of #3283 - saschagrunert:master, r=alexcrichton
Changed try! macros to ? operator Since the stabilization of the ? operator (release 1.13.0) the ? operator should be used to use idiomatic Rust.
2 parents a3d86dd + c313ed5 commit 8b5aec1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1365
-1366
lines changed

src/bin/bench.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ Compilation can be customized with the `bench` profile in the manifest.
7171
";
7272

7373
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
74-
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
75-
try!(config.configure(options.flag_verbose,
76-
options.flag_quiet,
77-
&options.flag_color,
78-
options.flag_frozen,
79-
options.flag_locked));
74+
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
75+
config.configure(options.flag_verbose,
76+
options.flag_quiet,
77+
&options.flag_color,
78+
options.flag_frozen,
79+
options.flag_locked)?;
8080
let ops = ops::TestOptions {
8181
no_run: options.flag_no_run,
8282
no_fail_fast: false,
@@ -102,8 +102,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
102102
},
103103
};
104104

105-
let ws = try!(Workspace::new(&root, config));
106-
let err = try!(ops::run_benches(&ws, &ops, &options.arg_args));
105+
let ws = Workspace::new(&root, config)?;
106+
let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
107107
match err {
108108
None => Ok(None),
109109
Some(err) => {

src/bin/build.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ the --release flag will use the `release` profile instead.
6969
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7070
debug!("executing; cmd=cargo-build; args={:?}",
7171
env::args().collect::<Vec<_>>());
72-
try!(config.configure(options.flag_verbose,
73-
options.flag_quiet,
74-
&options.flag_color,
75-
options.flag_frozen,
76-
options.flag_locked));
72+
config.configure(options.flag_verbose,
73+
options.flag_quiet,
74+
&options.flag_color,
75+
options.flag_frozen,
76+
options.flag_locked)?;
7777

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

8080
let opts = CompileOptions {
8181
config: config,
@@ -97,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9797
target_rustc_args: None,
9898
};
9999

100-
let ws = try!(Workspace::new(&root, config));
101-
try!(ops::compile(&ws, &opts));
100+
let ws = Workspace::new(&root, config)?;
101+
ops::compile(&ws, &opts)?;
102102
Ok(None)
103103
}

src/bin/cargo.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ each_subcommand!(declare_mod);
116116
on this top-level information.
117117
*/
118118
fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
119-
try!(config.configure(flags.flag_verbose,
120-
flags.flag_quiet,
121-
&flags.flag_color,
122-
flags.flag_frozen,
123-
flags.flag_locked));
119+
config.configure(flags.flag_verbose,
120+
flags.flag_quiet,
121+
&flags.flag_color,
122+
flags.flag_frozen,
123+
flags.flag_locked)?;
124124

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

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

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

192-
let alias_list = try!(aliased_command(&config, &args[1]));
192+
let alias_list = aliased_command(&config, &args[1])?;
193193
let args = match alias_list {
194194
Some(alias_command) => {
195195
let chain = args.iter().take(1)
@@ -205,7 +205,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
205205
}
206206
None => args,
207207
};
208-
try!(execute_subcommand(config, &args[1], &args));
208+
execute_subcommand(config, &args[1], &args)?;
209209
Ok(None)
210210
}
211211

@@ -239,7 +239,7 @@ fn aliased_command(config: &Config, command: &String) -> CargoResult<Option<Vec<
239239
}
240240
},
241241
Err(_) => {
242-
let value = try!(config.get_list(&alias_name));
242+
let value = config.get_list(&alias_name)?;
243243
if let Some(record) = value {
244244
let alias_commands: Vec<String> = record.val.iter()
245245
.map(|s| s.0.to_string()).collect();

src/bin/clean.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ and its format, see the `cargo help pkgid` command.
4444

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

53-
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
53+
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
5454
let opts = ops::CleanOptions {
5555
config: config,
5656
spec: &options.flag_package,
5757
target: options.flag_target.as_ref().map(|s| &s[..]),
5858
release: options.flag_release,
5959
};
60-
let ws = try!(Workspace::new(&root, config));
61-
try!(ops::clean(&ws, &opts));
60+
let ws = Workspace::new(&root, config)?;
61+
ops::clean(&ws, &opts)?;
6262
Ok(None)
6363
}

src/bin/doc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ the `cargo help pkgid` command.
6262
";
6363

6464
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
65-
try!(config.configure(options.flag_verbose,
66-
options.flag_quiet,
67-
&options.flag_color,
68-
options.flag_frozen,
69-
options.flag_locked));
65+
config.configure(options.flag_verbose,
66+
options.flag_quiet,
67+
&options.flag_color,
68+
options.flag_frozen,
69+
options.flag_locked)?;
7070

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

7373
let empty = Vec::new();
7474
let doc_opts = ops::DocOptions {
@@ -96,7 +96,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9696
},
9797
};
9898

99-
let ws = try!(Workspace::new(&root, config));
100-
try!(ops::doc(&ws, &doc_opts));
99+
let ws = Workspace::new(&root, config)?;
100+
ops::doc(&ws, &doc_opts)?;
101101
Ok(None)
102102
}

src/bin/fetch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ all updated.
3939
";
4040

4141
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
42-
try!(config.configure(options.flag_verbose,
43-
options.flag_quiet,
44-
&options.flag_color,
45-
options.flag_frozen,
46-
options.flag_locked));
47-
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
48-
let ws = try!(Workspace::new(&root, config));
49-
try!(ops::fetch(&ws));
42+
config.configure(options.flag_verbose,
43+
options.flag_quiet,
44+
&options.flag_color,
45+
options.flag_frozen,
46+
options.flag_locked)?;
47+
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
48+
let ws = Workspace::new(&root, config)?;
49+
ops::fetch(&ws)?;
5050
Ok(None)
5151
}
5252

src/bin/generate_lockfile.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ Options:
3333

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

43-
let ws = try!(Workspace::new(&root, config));
44-
try!(ops::generate_lockfile(&ws));
43+
let ws = Workspace::new(&root, config)?;
44+
ops::generate_lockfile(&ws)?;
4545
Ok(None)
4646
}

src/bin/git_checkout.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ Options:
3030
";
3131

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

40-
let url = try!(url.to_url());
40+
let url = url.to_url()?;
4141

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

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

47-
try!(source.update());
47+
source.update()?;
4848

4949
Ok(None)
5050
}

src/bin/init.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Options:
4141

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

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

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

5959
let opts_lib = opts.lib;
60-
try!(ops::init(opts, config));
60+
ops::init(opts, config)?;
6161

62-
try!(config.shell().status("Created", format!("{} project",
63-
if opts_lib { "library" }
64-
else {"binary (application)"})));
62+
config.shell().status("Created", format!("{} project",
63+
if opts_lib { "library" }
64+
else {"binary (application)"}))?;
6565

6666
Ok(None)
6767
}

src/bin/install.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ The `--list` option will list all installed packages (and their versions).
9595
";
9696

9797
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
98-
try!(config.configure(options.flag_verbose,
99-
options.flag_quiet,
100-
&options.flag_color,
101-
options.flag_frozen,
102-
options.flag_locked));
98+
config.configure(options.flag_verbose,
99+
options.flag_quiet,
100+
&options.flag_color,
101+
options.flag_frozen,
102+
options.flag_locked)?;
103103

104104
let compile_opts = ops::CompileOptions {
105105
config: config,
@@ -119,7 +119,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
119119
};
120120

121121
let source = if let Some(url) = options.flag_git {
122-
let url = try!(url.to_url());
122+
let url = url.to_url()?;
123123
let gitref = if let Some(branch) = options.flag_branch {
124124
GitReference::Branch(branch)
125125
} else if let Some(tag) = options.flag_tag {
@@ -131,21 +131,21 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
131131
};
132132
SourceId::for_git(&url, gitref)
133133
} else if let Some(path) = options.flag_path {
134-
try!(SourceId::for_path(&config.cwd().join(path)))
134+
SourceId::for_path(&config.cwd().join(path))?
135135
} else if options.arg_crate == None {
136-
try!(SourceId::for_path(&config.cwd()))
136+
SourceId::for_path(&config.cwd())?
137137
} else {
138-
try!(SourceId::crates_io(config))
138+
SourceId::crates_io(config)?
139139
};
140140

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

145145
if options.flag_list {
146-
try!(ops::install_list(root, config));
146+
ops::install_list(root, config)?;
147147
} else {
148-
try!(ops::install(root, krate, &source, vers, &compile_opts, options.flag_force));
148+
ops::install(root, krate, &source, vers, &compile_opts, options.flag_force)?;
149149
}
150150
Ok(None)
151151
}

src/bin/locate_project.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ pub struct ProjectLocation {
2424

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

29-
let string = try!(root.to_str()
29+
let string = root.to_str()
3030
.chain_error(|| human("Your project path contains \
3131
characters not representable in \
3232
Unicode"))
33-
.map_err(|e| CliError::new(e, 1)));
33+
.map_err(|e| CliError::new(e, 1))?;
3434

3535
Ok(Some(ProjectLocation { root: string.to_string() }))
3636
}

src/bin/login.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ Options:
3535
";
3636

3737
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
38-
try!(config.configure(options.flag_verbose,
39-
options.flag_quiet,
40-
&options.flag_color,
41-
options.flag_frozen,
42-
options.flag_locked));
38+
config.configure(options.flag_verbose,
39+
options.flag_quiet,
40+
&options.flag_color,
41+
options.flag_frozen,
42+
options.flag_locked)?;
4343
let token = match options.arg_token.clone() {
4444
Some(token) => token,
4545
None => {
46-
let src = try!(SourceId::crates_io(config));
46+
let src = SourceId::crates_io(config)?;
4747
let mut src = RegistrySource::remote(&src, config);
48-
try!(src.update());
49-
let config = try!(src.config()).unwrap();
48+
src.update()?;
49+
let config = src.config()?.unwrap();
5050
let host = options.flag_host.clone().unwrap_or(config.api);
5151
println!("please visit {}me and paste the API Token below", host);
5252
let mut line = String::new();
5353
let input = io::stdin();
54-
try!(input.lock().read_line(&mut line).chain_error(|| {
54+
input.lock().read_line(&mut line).chain_error(|| {
5555
human("failed to read stdin")
56-
}));
56+
})?;
5757
line
5858
}
5959
};
6060

6161
let token = token.trim().to_string();
62-
try!(ops::registry_login(config, token));
62+
ops::registry_login(config, token)?;
6363
Ok(None)
6464
}
6565

0 commit comments

Comments
 (0)