//! let bad_result: Result<int, int> = bad_result.or_else(|i| Ok(11));
//!
//! // Consume the result and return the contents with `unwrap`.
-//! let final_awesome_result = good_result.ok().unwrap();
+//! let final_awesome_result = good_result.unwrap();
//! ```
//!
//! # Results must be used
/// line.trim_right().parse::<int>().unwrap_or(0)
/// });
/// // Add the value if there were no errors, otherwise add 0
- /// sum += val.ok().unwrap_or(0);
+ /// sum += val.unwrap_or(0);
/// }
///
/// assert!(sum == 10);
use std::io::prelude::*;
use std::num::FromPrimitive;
use std::rc::Rc;
+use std::fmt::Debug;
use rbml::reader;
use rbml::writer::Encoder;
fn emit_def_id(&mut self, did: ast::DefId);
}
-impl<S:serialize::Encoder> def_id_encoder_helpers for S {
+impl<S:serialize::Encoder> def_id_encoder_helpers for S
+ where <S as serialize::serialize::Encoder>::Error: Debug
+{
fn emit_def_id(&mut self, did: ast::DefId) {
- did.encode(self).ok().unwrap()
+ did.encode(self).unwrap()
}
}
cdata: &cstore::crate_metadata) -> ast::DefId;
}
-impl<D:serialize::Decoder> def_id_decoder_helpers for D {
+impl<D:serialize::Decoder> def_id_decoder_helpers for D
+ where <D as serialize::serialize::Decoder>::Error: Debug
+{
fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
- let did: ast::DefId = Decodable::decode(self).ok().unwrap();
+ let did: ast::DefId = Decodable::decode(self).unwrap();
did.tr(dcx)
}
fn read_def_id_nodcx(&mut self,
- cdata: &cstore::crate_metadata) -> ast::DefId {
- let did: ast::DefId = Decodable::decode(self).ok().unwrap();
+ cdata: &cstore::crate_metadata)
+ -> ast::DefId {
+ let did: ast::DefId = Decodable::decode(self).unwrap();
decoder::translate_def_id(cdata, did)
}
}
fn read_closure_kind<'b, 'c>(&mut self, _dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::ClosureKind
{
- Decodable::decode(self).ok().unwrap()
+ Decodable::decode(self).unwrap()
}
fn read_closure_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
}
impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> {
- fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).ok().unwrap() }
+ fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).unwrap() }
fn node_id(&'a self, &(i,_): &Node<'a>) -> dot::Id<'a> {
- dot::Id::new(format!("N{}", i.node_id())).ok().unwrap()
+ dot::Id::new(format!("N{}", i.node_id())).unwrap()
}
fn node_label(&'a self, &(i, n): &Node<'a>) -> dot::LabelText<'a> {
return;
}
- let requested_output = env::var("RUST_REGION_GRAPH").ok();
+ let requested_output = env::var("RUST_REGION_GRAPH");
debug!("requested_output: {:?} requested_node: {:?}",
requested_output, requested_node);
let output_path = {
let output_template = match requested_output {
- Some(ref s) if &**s == "help" => {
+ Ok(ref s) if &**s == "help" => {
static PRINTED_YET: AtomicBool = ATOMIC_BOOL_INIT;
if !PRINTED_YET.load(Ordering::SeqCst) {
print_help_message();
return;
}
- Some(other_path) => other_path,
- None => "/tmp/constraints.node%.dot".to_string(),
+ Ok(other_path) => other_path,
+ Err(_) => "/tmp/constraints.node%.dot".to_string(),
};
if output_template.len() == 0 {
impl<'a, 'tcx> dot::Labeller<'a, Node, Edge> for ConstraintGraph<'a, 'tcx> {
fn graph_id(&self) -> dot::Id {
- dot::Id::new(&*self.graph_name).ok().unwrap()
+ dot::Id::new(&*self.graph_name).unwrap()
}
fn node_id(&self, n: &Node) -> dot::Id {
let node_id = match self.node_ids.get(n) {
if let ast::ExprAddrOf(mutbl, ref base) = ex.node {
let param_env = ty::empty_parameter_environment(self.bccx.tcx);
let mc = mc::MemCategorizationContext::new(¶m_env);
- let base_cmt = mc.cat_expr(&**base).ok().unwrap();
+ let base_cmt = mc.cat_expr(&**base).unwrap();
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
// Check that we don't allow borrows of unsafe static items.
if check_aliasability(self.bccx, ex.span, euv::AddrOf,
#[test]
fn binary_file() {
let mut bytes = [0; 1024];
- StdRng::new().ok().unwrap().fill_bytes(&mut bytes);
+ StdRng::new().unwrap().fill_bytes(&mut bytes);
let tmpdir = tmpdir();
fn read_to_end() {
let mut reader = Cursor::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
let mut v = Vec::new();
- reader.read_to_end(&mut v).ok().unwrap();
+ reader.read_to_end(&mut v).unwrap();
assert_eq!(v, [0, 1, 2, 3, 4, 5, 6, 7]);
}
unique_local: bool, global: bool,
u_link_local: bool, u_site_local: bool, u_global: bool,
m_scope: Option<Ipv6MulticastScope>) {
- let ip: Ipv6Addr = str_addr.parse().ok().unwrap();
+ let ip: Ipv6Addr = str_addr.parse().unwrap();
assert_eq!(str_addr, ip.to_string());
assert_eq!(ip.is_unspecified(), unspec);
use rand::{StdRng, Rng};
let mut bytes = [0; 1024];
- StdRng::new().ok().unwrap().fill_bytes(&mut bytes);
+ StdRng::new().unwrap().fill_bytes(&mut bytes);
let tmpdir = tmpdir();
// asleep (we're looking at it), so the receiver
// can't go away.
(*a.get()).send(t).ok().unwrap();
- token.signal();
+ token.signal();
(a, Ok(()))
}
}
#[allow(dead_code)]
fn output_fileline(w: &mut Write, file: &[u8], line: libc::c_int,
more: bool) -> io::Result<()> {
- let file = str::from_utf8(file).ok().unwrap_or("<unknown>");
+ let file = str::from_utf8(file).unwrap_or("<unknown>");
// prior line: " ##: {:2$} - func"
try!(write!(w, " {:3$}at {}:{}", "", file, line, HEX_WIDTH));
if more {
let mut reader = FileDesc::new(reader, true);
let mut writer = FileDesc::new(writer, true);
- writer.write(b"test").ok().unwrap();
+ writer.write(b"test").unwrap();
let mut buf = [0; 4];
match reader.read(&mut buf) {
Ok(4) => {
}
pub fn signal(fd: libc::c_int) {
- FileDesc::new(fd, false).write(&[0]).ok().unwrap();
+ FileDesc::new(fd, false).write(&[0]).unwrap();
}
pub fn close(fd: libc::c_int) {
// drain the file descriptor
let mut buf = [0];
- assert_eq!(fd.read(&mut buf).ok().unwrap(), 1);
+ assert_eq!(fd.read(&mut buf).unwrap(), 1);
}
-1 if os::errno() == libc::EINTR as i32 => {}
impl Clone for UnixAcceptor {
fn clone(&self) -> UnixAcceptor {
- let name = to_utf16(&self.listener.name).ok().unwrap();
+ let name = to_utf16(&self.listener.name).unwrap();
UnixAcceptor {
inner: self.inner.clone(),
- event: Event::new(true, false).ok().unwrap(),
+ event: Event::new(true, false).unwrap(),
deadline: 0,
listener: UnixListener {
name: self.listener.name.clone(),
Err(e) => {
type T = &'static str;
assert!(e.is::<T>());
- assert_eq!(*e.downcast::<T>().ok().unwrap(), "static string");
+ assert_eq!(*e.downcast::<T>().unwrap(), "static string");
}
Ok(()) => panic!()
}
Err(e) => {
type T = String;
assert!(e.is::<T>());
- assert_eq!(*e.downcast::<T>().ok().unwrap(), "owned string".to_string());
+ assert_eq!(*e.downcast::<T>().unwrap(), "owned string".to_string());
}
Ok(()) => panic!()
}
Err(e) => {
type T = Box<Any + Send>;
assert!(e.is::<T>());
- let any = e.downcast::<T>().ok().unwrap();
+ let any = e.downcast::<T>().unwrap();
assert!(any.is::<u16>());
- assert_eq!(*any.downcast::<u16>().ok().unwrap(), 413);
+ assert_eq!(*any.downcast::<u16>().unwrap(), 413);
}
Ok(()) => panic!()
}
//! fn encode(&self, s: &mut S) -> Result<(), E> {
//! s.emit_struct("Spanned", 2, |this| {
//! this.emit_struct_field("node", 0, |this| self.node.encode(this))
-//! .ok().unwrap();
+//! .unwrap();
//! this.emit_struct_field("span", 1, |this| self.span.encode(this))
//! })
//! }
//! d.read_struct("Spanned", 2, |this| {
//! Ok(Spanned {
//! node: this.read_struct_field("node", 0, |this| Decodable::decode(this))
-//! .ok().unwrap(),
+//! .unwrap(),
//! span: this.read_struct_field("span", 1, |this| Decodable::decode(this))
-//! .ok().unwrap(),
+//! .unwrap(),
//! })
//! })
//! }
// find the integer representing the name
self.scan_digits(base);
let encoded_name : u32 = self.with_str_from(start_bpos, |s| {
- num::from_str_radix(s, 10).ok().unwrap_or_else(|| {
+ num::from_str_radix(s, 10).unwrap_or_else(|_| {
panic!("expected digits representing a name, got {:?}, {}, range [{:?},{:?}]",
s, whence, start_bpos, self.last_pos);
})
let start_bpos = self.last_pos;
self.scan_digits(base);
let encoded_ctxt : ast::SyntaxContext = self.with_str_from(start_bpos, |s| {
- num::from_str_radix(s, 10).ok().unwrap_or_else(|| {
+ num::from_str_radix(s, 10).unwrap_or_else(|_| {
panic!("expected digits representing a ctxt, got {:?}, {}", s, whence);
})
});
}
};
- let entry = open(&term[..]);
- if entry.is_err() {
- if env::var("MSYSCON").ok().map_or(false, |s| {
- "mintty.exe" == s
- }) {
- // msys terminal
- return Some(box TerminfoTerminal {out: out,
- ti: msys_terminfo(),
- num_colors: 8} as Box<Terminal<T>+Send>);
- }
- debug!("error finding terminfo entry: {:?}", entry.err().unwrap());
- return None;
- }
+ let mut file = match open(&term[..]) {
+ Ok(f) => f,
+ Err(err) => return match env::var("MSYSCON") {
+ Ok(ref val) if &val[..] == "mintty.exe" => {
+ // msys terminal
+ Some(box TerminfoTerminal{
+ out: out,
+ ti: msys_terminfo(),
+ num_colors: 8,
+ } as Box<Terminal<T>+Send>)
+ },
+ _ => {
+ debug!("error finding terminfo entry: {:?}", err);
+ None
+ },
+ },
+ };
- let mut file = entry.unwrap();
let ti = parse(&mut file, false);
if ti.is_err() {
debug!("error parsing terminfo entry: {:?}", ti.err().unwrap());
pub fn main() {
let t = thread::spawn(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) );
- t.join().ok().unwrap();
+ t.join().ok().unwrap(); // forget Err value, since it doesn't implement Debug
}
fn child(args: (int, int, int, int, int, int, int, int, int)) {
let _b = Foo;
}).join();
- let s = x.err().unwrap().downcast::<&'static str>().ok().unwrap();
+ let s = x.err().unwrap().downcast::<&'static str>().unwrap();
assert_eq!(&**s, "This panic should happen.");
}