Skip to content

Commit 739d571

Browse files
authored
Auto merge of #36041 - ahmedcharles:try, r=nrc
Replace try! with ?.
2 parents b1363a7 + 694d601 commit 739d571

File tree

28 files changed

+105
-109
lines changed

28 files changed

+105
-109
lines changed

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use util::{exe, mtime, libdir, add_lib_path};
4545
/// * The error itself
4646
///
4747
/// This is currently used judiciously throughout the build system rather than
48-
/// using a `Result` with `try!`, but this may change on day...
48+
/// using a `Result` with `try!`, but this may change one day...
4949
macro_rules! t {
5050
($e:expr) => (match $e {
5151
Ok(e) => e,

src/libcore/num/bignum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ macro_rules! define_bignum {
474474
let sz = if self.size < 1 {1} else {self.size};
475475
let digitlen = mem::size_of::<$ty>() * 2;
476476

477-
try!(write!(f, "{:#x}", self.base[sz-1]));
477+
write!(f, "{:#x}", self.base[sz-1])?;
478478
for &v in self.base[..sz-1].iter().rev() {
479-
try!(write!(f, "_{:01$x}", v, digitlen));
479+
write!(f, "_{:01$x}", v, digitlen)?;
480480
}
481481
::result::Result::Ok(())
482482
}

src/librustc/hir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1756,9 +1756,9 @@ impl<'a> State<'a> {
17561756
self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p))?;
17571757
}
17581758
} else {
1759-
try!(self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p)));
1759+
self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p))?;
17601760
}
1761-
try!(self.pclose());
1761+
self.pclose()?;
17621762
}
17631763
PatKind::Path(None, ref path) => {
17641764
self.print_path(path, true, 0)?;

src/librustc/infer/higher_ranked/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
130130
debug!("higher_ranked_match: skol_map={:?}", skol_map);
131131

132132
// Equate types now that bound regions have been replaced.
133-
try!(self.equate(a_is_expected).relate(&a_match, &b_match));
133+
self.equate(a_is_expected).relate(&a_match, &b_match)?;
134134

135135
// Map each skolemized region to a vector of other regions that it
136136
// must be equated with. (Note that this vector may include other

src/librustc/util/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
6868
let p = p.as_ref();
6969
let q = q.as_ref();
7070
if q.exists() {
71-
try!(fs::remove_file(&q));
71+
fs::remove_file(&q)?;
7272
}
7373

7474
match fs::hard_link(p, q) {

src/librustc_back/target/aarch64_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

1414
pub fn target() -> TargetResult {
15-
let base = try!(opts(Arch::Arm64));
15+
let base = opts(Arch::Arm64)?;
1616
Ok(Target {
1717
llvm_target: "arm64-apple-ios".to_string(),
1818
target_endian: "little".to_string(),

src/librustc_back/target/apple_ios_base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn build_pre_link_args(arch: Arch) -> Result<Vec<String>, String> {
6868

6969
let arch_name = arch.to_string();
7070

71-
let sdk_root = try!(get_sdk_root(sdk_name));
71+
let sdk_root = get_sdk_root(sdk_name)?;
7272

7373
Ok(vec!["-arch".to_string(), arch_name.to_string(),
7474
"-Wl,-syslibroot".to_string(), sdk_root])
@@ -85,7 +85,7 @@ fn target_cpu(arch: Arch) -> String {
8585
}
8686

8787
pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
88-
let pre_link_args = try!(build_pre_link_args(arch));
88+
let pre_link_args = build_pre_link_args(arch)?;
8989
Ok(TargetOptions {
9090
cpu: target_cpu(arch),
9191
dynamic_linking: false,

src/librustc_back/target/armv7_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

1414
pub fn target() -> TargetResult {
15-
let base = try!(opts(Arch::Armv7));
15+
let base = opts(Arch::Armv7)?;
1616
Ok(Target {
1717
llvm_target: "armv7-apple-ios".to_string(),
1818
target_endian: "little".to_string(),

src/librustc_back/target/armv7s_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

1414
pub fn target() -> TargetResult {
15-
let base = try!(opts(Arch::Armv7s));
15+
let base = opts(Arch::Armv7s)?;
1616
Ok(Target {
1717
llvm_target: "armv7s-apple-ios".to_string(),
1818
target_endian: "little".to_string(),

src/librustc_back/target/i386_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

1414
pub fn target() -> TargetResult {
15-
let base = try!(opts(Arch::I386));
15+
let base = opts(Arch::I386)?;
1616
Ok(Target {
1717
llvm_target: "i386-apple-ios".to_string(),
1818
target_endian: "little".to_string(),

src/librustc_back/target/i586_pc_windows_msvc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use target::TargetResult;
1212

1313
pub fn target() -> TargetResult {
14-
let mut base = try!(super::i686_pc_windows_msvc::target());
14+
let mut base = super::i686_pc_windows_msvc::target()?;
1515
base.options.cpu = "pentium".to_string();
1616
base.llvm_target = "i586-pc-windows-msvc".to_string();
1717
Ok(base)

src/librustc_back/target/i586_unknown_linux_gnu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use target::TargetResult;
1212

1313
pub fn target() -> TargetResult {
14-
let mut base = try!(super::i686_unknown_linux_gnu::target());
14+
let mut base = super::i686_unknown_linux_gnu::target()?;
1515
base.options.cpu = "pentium".to_string();
1616
base.llvm_target = "i586-unknown-linux-gnu".to_string();
1717
Ok(base)

src/librustc_back/target/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ macro_rules! supported_targets {
7777
match target {
7878
$(
7979
$triple => {
80-
let mut t = try!($module::target());
80+
let mut t = $module::target()?;
8181
t.options.is_builtin = true;
8282

8383
// round-trip through the JSON parser to ensure at
8484
// run-time that the parser works correctly
85-
t = try!(Target::from_json(t.to_json()));
85+
t = Target::from_json(t.to_json())?;
8686
debug!("Got builtin target: {:?}", t);
8787
Ok(t)
8888
},
@@ -438,12 +438,12 @@ impl Target {
438438
};
439439

440440
let mut base = Target {
441-
llvm_target: try!(get_req_field("llvm-target")),
442-
target_endian: try!(get_req_field("target-endian")),
443-
target_pointer_width: try!(get_req_field("target-pointer-width")),
444-
data_layout: try!(get_req_field("data-layout")),
445-
arch: try!(get_req_field("arch")),
446-
target_os: try!(get_req_field("os")),
441+
llvm_target: get_req_field("llvm-target")?,
442+
target_endian: get_req_field("target-endian")?,
443+
target_pointer_width: get_req_field("target-pointer-width")?,
444+
data_layout: get_req_field("data-layout")?,
445+
arch: get_req_field("arch")?,
446+
target_os: get_req_field("os")?,
447447
target_env: get_opt_field("env", ""),
448448
target_vendor: get_opt_field("vendor", "unknown"),
449449
options: Default::default(),

src/librustc_back/target/x86_64_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

1414
pub fn target() -> TargetResult {
15-
let base = try!(opts(Arch::X86_64));
15+
let base = opts(Arch::X86_64)?;
1616
Ok(Target {
1717
llvm_target: "x86_64-apple-ios".to_string(),
1818
target_endian: "little".to_string(),

src/librustc_const_eval/eval.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
278278
}
279279
let pat = match expr.node {
280280
hir::ExprTup(ref exprs) =>
281-
PatKind::Tuple(try!(exprs.iter()
282-
.map(|expr| const_expr_to_pat(tcx, &expr, pat_id, span))
283-
.collect()), None),
281+
PatKind::Tuple(exprs.iter()
282+
.map(|expr| const_expr_to_pat(tcx, &expr, pat_id, span))
283+
.collect::<Result<_, _>>()?, None),
284284

285285
hir::ExprCall(ref callee, ref args) => {
286286
let def = tcx.expect_def(callee.id);
@@ -297,34 +297,31 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
297297
})),
298298
_ => bug!()
299299
};
300-
let pats = try!(args.iter()
301-
.map(|expr| const_expr_to_pat(tcx, &**expr,
302-
pat_id, span))
303-
.collect());
300+
let pats = args.iter()
301+
.map(|expr| const_expr_to_pat(tcx, &**expr, pat_id, span))
302+
.collect::<Result<_, _>>()?;
304303
PatKind::TupleStruct(path, pats, None)
305304
}
306305

307306
hir::ExprStruct(ref path, ref fields, None) => {
308307
let field_pats =
309-
try!(fields.iter()
310-
.map(|field| Ok(codemap::Spanned {
311-
span: syntax_pos::DUMMY_SP,
312-
node: hir::FieldPat {
313-
name: field.name.node,
314-
pat: try!(const_expr_to_pat(tcx, &field.expr,
315-
pat_id, span)),
316-
is_shorthand: false,
317-
},
318-
}))
319-
.collect());
308+
fields.iter()
309+
.map(|field| Ok(codemap::Spanned {
310+
span: syntax_pos::DUMMY_SP,
311+
node: hir::FieldPat {
312+
name: field.name.node,
313+
pat: const_expr_to_pat(tcx, &field.expr, pat_id, span)?,
314+
is_shorthand: false,
315+
},
316+
}))
317+
.collect::<Result<_, _>>()?;
320318
PatKind::Struct(path.clone(), field_pats, false)
321319
}
322320

323321
hir::ExprVec(ref exprs) => {
324-
let pats = try!(exprs.iter()
325-
.map(|expr| const_expr_to_pat(tcx, &expr,
326-
pat_id, span))
327-
.collect());
322+
let pats = exprs.iter()
323+
.map(|expr| const_expr_to_pat(tcx, &expr, pat_id, span))
324+
.collect::<Result<_, _>>()?;
328325
PatKind::Vec(pats, None, hir::HirVec::new())
329326
}
330327

src/librustc_errors/emitter.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -882,45 +882,45 @@ impl Destination {
882882
match style {
883883
Style::FileNameStyle | Style::LineAndColumn => {}
884884
Style::LineNumber => {
885-
try!(self.start_attr(term::Attr::Bold));
885+
self.start_attr(term::Attr::Bold)?;
886886
if cfg!(windows) {
887-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_CYAN)));
887+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_CYAN))?;
888888
} else {
889-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_BLUE)));
889+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_BLUE))?;
890890
}
891891
}
892892
Style::ErrorCode => {
893-
try!(self.start_attr(term::Attr::Bold));
894-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA)));
893+
self.start_attr(term::Attr::Bold)?;
894+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA))?;
895895
}
896896
Style::Quotation => {}
897897
Style::OldSchoolNote => {
898-
try!(self.start_attr(term::Attr::Bold));
899-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_GREEN)));
898+
self.start_attr(term::Attr::Bold)?;
899+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_GREEN))?;
900900
}
901901
Style::OldSchoolNoteText | Style::HeaderMsg => {
902-
try!(self.start_attr(term::Attr::Bold));
902+
self.start_attr(term::Attr::Bold)?;
903903
if cfg!(windows) {
904-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_WHITE)));
904+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_WHITE))?;
905905
}
906906
}
907907
Style::UnderlinePrimary | Style::LabelPrimary => {
908-
try!(self.start_attr(term::Attr::Bold));
909-
try!(self.start_attr(term::Attr::ForegroundColor(lvl.color())));
908+
self.start_attr(term::Attr::Bold)?;
909+
self.start_attr(term::Attr::ForegroundColor(lvl.color()))?;
910910
}
911911
Style::UnderlineSecondary |
912912
Style::LabelSecondary => {
913-
try!(self.start_attr(term::Attr::Bold));
913+
self.start_attr(term::Attr::Bold)?;
914914
if cfg!(windows) {
915-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_CYAN)));
915+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_CYAN))?;
916916
} else {
917-
try!(self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_BLUE)));
917+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_BLUE))?;
918918
}
919919
}
920920
Style::NoStyle => {}
921921
Style::Level(l) => {
922-
try!(self.start_attr(term::Attr::Bold));
923-
try!(self.start_attr(term::Attr::ForegroundColor(l.color())));
922+
self.start_attr(term::Attr::Bold)?;
923+
self.start_attr(term::Attr::ForegroundColor(l.color()))?;
924924
}
925925
}
926926
Ok(())
@@ -960,4 +960,4 @@ impl Write for Destination {
960960
Raw(ref mut w) => w.flush(),
961961
}
962962
}
963-
}
963+
}

src/librustc_incremental/persist/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
194194

195195
// Load up the hashes for the def-ids from this crate.
196196
let mut decoder = Decoder::new(data, 0);
197-
let svh_in_hashes_file = try!(Svh::decode(&mut decoder));
197+
let svh_in_hashes_file = Svh::decode(&mut decoder)?;
198198

199199
if svh_in_hashes_file != expected_svh {
200200
// We should not be able to get here. If we do, then
201201
// `fs::find_metadata_hashes_for()` has messed up.
202202
bug!("mismatch between SVH in crate and SVH in incr. comp. hashes")
203203
}
204204

205-
let serialized_hashes = try!(SerializedMetadataHashes::decode(&mut decoder));
205+
let serialized_hashes = SerializedMetadataHashes::decode(&mut decoder)?;
206206
for serialized_hash in serialized_hashes.hashes {
207207
// the hashes are stored with just a def-index, which is
208208
// always relative to the old crate; convert that to use

src/librustc_incremental/persist/load.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
125125
{
126126
// Decode the list of work_products
127127
let mut work_product_decoder = Decoder::new(work_products_data, 0);
128-
let work_products = try!(<Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder));
128+
let work_products = <Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder)?;
129129

130130
// Deserialize the directory and dep-graph.
131131
let mut dep_graph_decoder = Decoder::new(dep_graph_data, 0);
132-
let prev_commandline_args_hash = try!(u64::decode(&mut dep_graph_decoder));
132+
let prev_commandline_args_hash = u64::decode(&mut dep_graph_decoder)?;
133133

134134
if prev_commandline_args_hash != tcx.sess.opts.dep_tracking_hash() {
135135
// We can't reuse the cache, purge it.
@@ -142,8 +142,8 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
142142
return Ok(());
143143
}
144144

145-
let directory = try!(DefIdDirectory::decode(&mut dep_graph_decoder));
146-
let serialized_dep_graph = try!(SerializedDepGraph::decode(&mut dep_graph_decoder));
145+
let directory = DefIdDirectory::decode(&mut dep_graph_decoder)?;
146+
let serialized_dep_graph = SerializedDepGraph::decode(&mut dep_graph_decoder)?;
147147

148148
// Retrace the paths in the directory to find their current location (if any).
149149
let retraced = directory.retrace(tcx);

src/librustc_incremental/persist/save.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn encode_dep_graph(preds: &Predecessors,
110110
-> io::Result<()> {
111111
// First encode the commandline arguments hash
112112
let tcx = builder.tcx();
113-
try!(tcx.sess.opts.dep_tracking_hash().encode(encoder));
113+
tcx.sess.opts.dep_tracking_hash().encode(encoder)?;
114114

115115
// Create a flat list of (Input, WorkProduct) edges for
116116
// serialization.
@@ -149,8 +149,8 @@ pub fn encode_dep_graph(preds: &Predecessors,
149149
debug!("graph = {:#?}", graph);
150150

151151
// Encode the directory and then the graph data.
152-
try!(builder.directory().encode(encoder));
153-
try!(graph.encode(encoder));
152+
builder.directory().encode(encoder)?;
153+
graph.encode(encoder)?;
154154

155155
Ok(())
156156
}
@@ -222,8 +222,8 @@ pub fn encode_metadata_hashes(tcx: TyCtxt,
222222
}
223223

224224
// Encode everything.
225-
try!(svh.encode(encoder));
226-
try!(serialized_hashes.encode(encoder));
225+
svh.encode(encoder)?;
226+
serialized_hashes.encode(encoder)?;
227227

228228
Ok(())
229229
}

src/librustc_metadata/loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ fn get_metadata_section_imp(target: &Target, flavor: CrateFlavor, filename: &Pat
809809
None => Err(format!("failed to read rlib metadata: '{}'",
810810
filename.display())),
811811
Some(blob) => {
812-
try!(verify_decompressed_encoding_version(&blob, filename));
812+
verify_decompressed_encoding_version(&blob, filename)?;
813813
Ok(blob)
814814
}
815815
};
@@ -858,7 +858,7 @@ fn get_metadata_section_imp(target: &Target, flavor: CrateFlavor, filename: &Pat
858858
match flate::inflate_bytes(bytes) {
859859
Ok(inflated) => {
860860
let blob = MetadataVec(inflated);
861-
try!(verify_decompressed_encoding_version(&blob, filename));
861+
verify_decompressed_encoding_version(&blob, filename)?;
862862
return Ok(blob);
863863
}
864864
Err(_) => {}

0 commit comments

Comments
 (0)