Skip to content

Commit e2fa53e

Browse files
committed
Auto merge of #23512 - oli-obk:result_ok_unwrap, r=alexcrichton
because then the call to `unwrap()` will not print the error object.
2 parents 68d6941 + b4a1e59 commit e2fa53e

File tree

21 files changed

+62
-53
lines changed

21 files changed

+62
-53
lines changed

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
//! let bad_result: Result<int, int> = bad_result.or_else(|i| Ok(11));
7979
//!
8080
//! // Consume the result and return the contents with `unwrap`.
81-
//! let final_awesome_result = good_result.ok().unwrap();
81+
//! let final_awesome_result = good_result.unwrap();
8282
//! ```
8383
//!
8484
//! # Results must be used
@@ -460,7 +460,7 @@ impl<T, E> Result<T, E> {
460460
/// line.trim_right().parse::<int>().unwrap_or(0)
461461
/// });
462462
/// // Add the value if there were no errors, otherwise add 0
463-
/// sum += val.ok().unwrap_or(0);
463+
/// sum += val.unwrap_or(0);
464464
/// }
465465
///
466466
/// assert!(sum == 10);

src/librustc/middle/astencode.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use std::io::SeekFrom;
4343
use std::io::prelude::*;
4444
use std::num::FromPrimitive;
4545
use std::rc::Rc;
46+
use std::fmt::Debug;
4647

4748
use rbml::reader;
4849
use rbml::writer::Encoder;
@@ -313,9 +314,11 @@ trait def_id_encoder_helpers {
313314
fn emit_def_id(&mut self, did: ast::DefId);
314315
}
315316

316-
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
317+
impl<S:serialize::Encoder> def_id_encoder_helpers for S
318+
where <S as serialize::serialize::Encoder>::Error: Debug
319+
{
317320
fn emit_def_id(&mut self, did: ast::DefId) {
318-
did.encode(self).ok().unwrap()
321+
did.encode(self).unwrap()
319322
}
320323
}
321324

@@ -325,15 +328,18 @@ trait def_id_decoder_helpers {
325328
cdata: &cstore::crate_metadata) -> ast::DefId;
326329
}
327330

328-
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
331+
impl<D:serialize::Decoder> def_id_decoder_helpers for D
332+
where <D as serialize::serialize::Decoder>::Error: Debug
333+
{
329334
fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
330-
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
335+
let did: ast::DefId = Decodable::decode(self).unwrap();
331336
did.tr(dcx)
332337
}
333338

334339
fn read_def_id_nodcx(&mut self,
335-
cdata: &cstore::crate_metadata) -> ast::DefId {
336-
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
340+
cdata: &cstore::crate_metadata)
341+
-> ast::DefId {
342+
let did: ast::DefId = Decodable::decode(self).unwrap();
337343
decoder::translate_def_id(cdata, did)
338344
}
339345
}
@@ -1784,7 +1790,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
17841790
fn read_closure_kind<'b, 'c>(&mut self, _dcx: &DecodeContext<'b, 'c, 'tcx>)
17851791
-> ty::ClosureKind
17861792
{
1787-
Decodable::decode(self).ok().unwrap()
1793+
Decodable::decode(self).unwrap()
17881794
}
17891795

17901796
fn read_closure_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)

src/librustc/middle/cfg/graphviz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ fn replace_newline_with_backslash_l(s: String) -> String {
5454
}
5555

5656
impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> {
57-
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).ok().unwrap() }
57+
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).unwrap() }
5858

5959
fn node_id(&'a self, &(i,_): &Node<'a>) -> dot::Id<'a> {
60-
dot::Id::new(format!("N{}", i.node_id())).ok().unwrap()
60+
dot::Id::new(format!("N{}", i.node_id())).unwrap()
6161
}
6262

6363
fn node_label(&'a self, &(i, n): &Node<'a>) -> dot::LabelText<'a> {

src/librustc/middle/infer/region_inference/graphviz.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
6969
return;
7070
}
7171

72-
let requested_output = env::var("RUST_REGION_GRAPH").ok();
72+
let requested_output = env::var("RUST_REGION_GRAPH");
7373
debug!("requested_output: {:?} requested_node: {:?}",
7474
requested_output, requested_node);
7575

7676
let output_path = {
7777
let output_template = match requested_output {
78-
Some(ref s) if &**s == "help" => {
78+
Ok(ref s) if &**s == "help" => {
7979
static PRINTED_YET: AtomicBool = ATOMIC_BOOL_INIT;
8080
if !PRINTED_YET.load(Ordering::SeqCst) {
8181
print_help_message();
@@ -84,8 +84,8 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
8484
return;
8585
}
8686

87-
Some(other_path) => other_path,
88-
None => "/tmp/constraints.node%.dot".to_string(),
87+
Ok(other_path) => other_path,
88+
Err(_) => "/tmp/constraints.node%.dot".to_string(),
8989
};
9090

9191
if output_template.len() == 0 {
@@ -171,7 +171,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
171171

172172
impl<'a, 'tcx> dot::Labeller<'a, Node, Edge> for ConstraintGraph<'a, 'tcx> {
173173
fn graph_id(&self) -> dot::Id {
174-
dot::Id::new(&*self.graph_name).ok().unwrap()
174+
dot::Id::new(&*self.graph_name).unwrap()
175175
}
176176
fn node_id(&self, n: &Node) -> dot::Id {
177177
let node_id = match self.node_ids.get(n) {

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
491491
if let ast::ExprAddrOf(mutbl, ref base) = ex.node {
492492
let param_env = ty::empty_parameter_environment(self.bccx.tcx);
493493
let mc = mc::MemCategorizationContext::new(&param_env);
494-
let base_cmt = mc.cat_expr(&**base).ok().unwrap();
494+
let base_cmt = mc.cat_expr(&**base).unwrap();
495495
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
496496
// Check that we don't allow borrows of unsafe static items.
497497
if check_aliasability(self.bccx, ex.span, euv::AddrOf,

src/libstd/fs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ mod tests {
15371537
#[test]
15381538
fn binary_file() {
15391539
let mut bytes = [0; 1024];
1540-
StdRng::new().ok().unwrap().fill_bytes(&mut bytes);
1540+
StdRng::new().unwrap().fill_bytes(&mut bytes);
15411541

15421542
let tmpdir = tmpdir();
15431543

src/libstd/io/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ mod tests {
277277
fn read_to_end() {
278278
let mut reader = Cursor::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
279279
let mut v = Vec::new();
280-
reader.read_to_end(&mut v).ok().unwrap();
280+
reader.read_to_end(&mut v).unwrap();
281281
assert_eq!(v, [0, 1, 2, 3, 4, 5, 6, 7]);
282282
}
283283

src/libstd/net/addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ mod tests {
617617
unique_local: bool, global: bool,
618618
u_link_local: bool, u_site_local: bool, u_global: bool,
619619
m_scope: Option<Ipv6MulticastScope>) {
620-
let ip: Ipv6Addr = str_addr.parse().ok().unwrap();
620+
let ip: Ipv6Addr = str_addr.parse().unwrap();
621621
assert_eq!(str_addr, ip.to_string());
622622

623623
assert_eq!(ip.is_unspecified(), unspec);

src/libstd/old_io/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ mod test {
16081608
use rand::{StdRng, Rng};
16091609

16101610
let mut bytes = [0; 1024];
1611-
StdRng::new().ok().unwrap().fill_bytes(&mut bytes);
1611+
StdRng::new().unwrap().fill_bytes(&mut bytes);
16121612

16131613
let tmpdir = tmpdir();
16141614

src/libstd/sync/mpsc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl<T: Send> Sender<T> {
592592
// asleep (we're looking at it), so the receiver
593593
// can't go away.
594594
(*a.get()).send(t).ok().unwrap();
595-
token.signal();
595+
token.signal();
596596
(a, Ok(()))
597597
}
598598
}

0 commit comments

Comments
 (0)