From f966f1a8ca3e349e9c468b38cb37da9d6f7e3c75 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 30 Oct 2014 00:26:30 -0400 Subject: [PATCH] fail -> panic --- src/lib/codegen.rs | 32 ++++++++++----------- src/lib/core.rs | 8 +++--- src/lib/descriptor.rs | 8 +++--- src/lib/hex.rs | 6 ++-- src/lib/reflect.rs | 48 ++++++++++++++++---------------- src/lib/rt.rs | 2 +- src/lib/shrug.rs | 4 +-- src/lib/singular.rs | 8 +++--- src/lib/stream.rs | 12 ++++---- src/lib/strx.rs | 4 +-- src/lib/test_nonunique_enum.rs | 4 +-- src/lib/text_format_test_data.rs | 2 +- src/perftest/perftest.rs | 4 +-- src/protobuf-bin-gen-rust.rs | 2 +- 14 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/lib/codegen.rs b/src/lib/codegen.rs index 013ddbda8..f54236309 100644 --- a/src/lib/codegen.rs +++ b/src/lib/codegen.rs @@ -69,14 +69,14 @@ impl RustType { fn ref_str(&self, lt: &str) -> String { match *self { RustRef(ref param) => format!("&'{} {}", lt, *param), - _ => fail!("not a ref: {}", *self), + _ => panic!("not a ref: {}", *self), } } fn mut_ref_str(&self, lt: &str) -> String { match *self { RustRef(ref param) => format!("&'{} mut {}", lt, *param), - _ => fail!("not a ref: {}", *self), + _ => panic!("not a ref: {}", *self), } } @@ -106,7 +106,7 @@ impl RustType { RustRef(box RustMessage(ref name)) => format!("{}::default_instance()", name), // TODO: use proper constant RustEnum(ref name) => format!("{}::new(0)", name), - _ => fail!("cannot create default value for: {}", *self), + _ => panic!("cannot create default value for: {}", *self), } } @@ -116,7 +116,7 @@ impl RustType { RustOption(..) => format!("Some({})", value), RustSingularField(..) => format!("::protobuf::SingularField::some({})", value), RustSingularPtrField(..) => format!("::protobuf::SingularPtrField::some({})", value), - _ => fail!("not a wrapper type: {}", *self), + _ => panic!("not a wrapper type: {}", *self), } } @@ -131,7 +131,7 @@ impl RustType { fn into(&self, target: &RustType, v: &str) -> String { match (self, target) { (x, y) if x == y => v.to_string(), - _ => fail!("internal error: cannot convert {} to {}", self, target), + _ => panic!("internal error: cannot convert {} to {}", self, target), } } @@ -141,7 +141,7 @@ impl RustType { &RustVec(ref p) | &RustRepeatedField(ref p) => box RustSlice(p.clone()), &RustMessage(ref p) => box RustMessage(p.clone()), - x => fail!("no ref type for {}", x), + x => panic!("no ref type for {}", x), }) } } @@ -166,7 +166,7 @@ fn rust_name(field_type: FieldDescriptorProto_Type) -> RustType { FieldDescriptorProto_TYPE_BYTES => RustVec(box RustUnsigned(8)), FieldDescriptorProto_TYPE_ENUM | FieldDescriptorProto_TYPE_GROUP | - FieldDescriptorProto_TYPE_MESSAGE => fail!() + FieldDescriptorProto_TYPE_MESSAGE => panic!() } } @@ -190,7 +190,7 @@ fn protobuf_name(field_type: FieldDescriptorProto_Type) -> &'static str { FieldDescriptorProto_TYPE_BYTES => "bytes", FieldDescriptorProto_TYPE_ENUM | FieldDescriptorProto_TYPE_GROUP | - FieldDescriptorProto_TYPE_MESSAGE => fail!() + FieldDescriptorProto_TYPE_MESSAGE => panic!() } } @@ -214,7 +214,7 @@ fn field_type_wire_type(field_type: FieldDescriptorProto_Type) -> wire_format::W FieldDescriptorProto_TYPE_STRING => WireTypeLengthDelimited, FieldDescriptorProto_TYPE_BYTES => WireTypeLengthDelimited, FieldDescriptorProto_TYPE_MESSAGE => WireTypeLengthDelimited, - FieldDescriptorProto_TYPE_GROUP => fail!() + FieldDescriptorProto_TYPE_GROUP => panic!() } } @@ -243,12 +243,12 @@ fn field_type_name(field: &FieldDescriptorProto, pkg: &str) -> RustType { match field.get_field_type() { FieldDescriptorProto_TYPE_MESSAGE => RustMessage(name), FieldDescriptorProto_TYPE_ENUM => RustEnum(name), - _ => fail!("unknown named type: {}", field.get_field_type()), + _ => panic!("unknown named type: {}", field.get_field_type()), } } else if field.has_field_type() { rust_name(field.get_field_type()) } else { - fail!("neither type_name, nor field_type specified for field: {}", field.get_name()); + panic!("neither type_name, nor field_type specified for field: {}", field.get_name()); } } @@ -420,7 +420,7 @@ impl Field { FieldDescriptorProto_TYPE_ENUM => format!("{}", proto_default), FieldDescriptorProto_TYPE_GROUP | FieldDescriptorProto_TYPE_MESSAGE => - fail!("default value is not implemented for type: {}", self.field_type) + panic!("default value is not implemented for type: {}", self.field_type) }) } else { None @@ -838,7 +838,7 @@ impl<'a> IndentWriter<'a> { #[allow(dead_code)] fn fail(&self, reason: S) { - self.write_line(format!("fail!({});", reason.as_slice())); + self.write_line(format!("panic!({});", reason.as_slice())); } #[allow(dead_code)] @@ -939,7 +939,7 @@ fn write_merge_from_field_message_string_bytes(w: &mut IndentWriter) { FieldDescriptorProto_TYPE_BYTES => w.write_line(format!("try!(is.read_bytes_into(tmp))")), _ => - fail!(), + panic!(), } } @@ -973,7 +973,7 @@ fn write_merge_from_field(w: &mut IndentWriter) { match repeat_mode { Single => w.self_field_assign_some("tmp"), RepeatRegular => w.self_field_push("tmp"), - _ => fail!() + _ => panic!() } }, RepeatPacked => { @@ -1548,7 +1548,7 @@ fn write_enum_impl(w: &mut IndentWriter) { for value in w.en().values.iter() { w.write_line(format!("{:d} => {:s},", value.number(), value.rust_name())); } - w.write_line(format!("_ => fail!()")); + w.write_line(format!("_ => panic!()")); }); }); }); diff --git a/src/lib/core.rs b/src/lib/core.rs index ea525701f..41474c45a 100644 --- a/src/lib/core.rs +++ b/src/lib/core.rs @@ -1,4 +1,4 @@ -// TODO: drop all fail! +// TODO: drop all panic! use std::mem; use std::raw; @@ -99,11 +99,11 @@ pub trait Message : PartialEq + Clone + Default + fmt::Show + Clear { // http://stackoverflow.com/q/20342436/15018 fn descriptor_static(_: Option) -> &'static MessageDescriptor { - fail!(); + panic!(); } fn type_id(&self) -> TypeId { - fail!(); + panic!(); } // Rust does not allow implementation of trait for trait: @@ -142,7 +142,7 @@ pub trait ProtobufEnum : Eq { // http://stackoverflow.com/q/20342436/15018 fn enum_descriptor_static(_: Option) -> &'static EnumDescriptor { - fail!(); + panic!(); } } diff --git a/src/lib/descriptor.rs b/src/lib/descriptor.rs index 9b7c353c2..dd1e6c7bf 100644 --- a/src/lib/descriptor.rs +++ b/src/lib/descriptor.rs @@ -2429,7 +2429,7 @@ impl FieldDescriptorProto_Type { 16 => FieldDescriptorProto_TYPE_SFIXED64, 17 => FieldDescriptorProto_TYPE_SINT32, 18 => FieldDescriptorProto_TYPE_SINT64, - _ => fail!() + _ => panic!() } } } @@ -2462,7 +2462,7 @@ impl FieldDescriptorProto_Label { 1 => FieldDescriptorProto_LABEL_OPTIONAL, 2 => FieldDescriptorProto_LABEL_REQUIRED, 3 => FieldDescriptorProto_LABEL_REPEATED, - _ => fail!() + _ => panic!() } } } @@ -4522,7 +4522,7 @@ impl FileOptions_OptimizeMode { 1 => FileOptions_SPEED, 2 => FileOptions_CODE_SIZE, 3 => FileOptions_LITE_RUNTIME, - _ => fail!() + _ => panic!() } } } @@ -5401,7 +5401,7 @@ impl FieldOptions_CType { 0 => FieldOptions_STRING, 1 => FieldOptions_CORD, 2 => FieldOptions_STRING_PIECE, - _ => fail!() + _ => panic!() } } } diff --git a/src/lib/hex.rs b/src/lib/hex.rs index 37cb0d7c3..fad9f9de4 100644 --- a/src/lib/hex.rs +++ b/src/lib/hex.rs @@ -7,7 +7,7 @@ use std::char; fn decode_hex_digit(digit: char) -> u8 { match char::to_digit(digit, 16) { Some(d) => d as u8, - _ => fail!() + _ => panic!() } } @@ -26,7 +26,7 @@ pub fn decode_hex(hex: &str) -> Vec { if pos == hex.char_len() { break; } - fail!("pos = {:u}d", pos); + panic!("pos = {:u}d", pos); } r } @@ -34,7 +34,7 @@ pub fn decode_hex(hex: &str) -> Vec { fn encode_hex_digit(digit: u8) -> char { match char::from_digit(digit as uint, 16) { Some(c) => c, - _ => fail!() + _ => panic!() } } diff --git a/src/lib/reflect.rs b/src/lib/reflect.rs index fa53bceac..a4642a935 100644 --- a/src/lib/reflect.rs +++ b/src/lib/reflect.rs @@ -18,99 +18,99 @@ pub trait FieldAccessor { fn name(&self) -> &'static str; fn has_field(&self, _m: &M) -> bool { - fail!(); + panic!(); } fn len_field(&self, _m: &M) -> uint { - fail!(); + panic!(); } fn get_message<'a>(&self, _m: &'a M) -> &'a Message { - fail!(); + panic!(); } fn get_rep_message_item<'a>(&self, _m: &'a M, _index: uint) -> &'a Message { - fail!(); + panic!(); } fn get_enum(&self, _m: &M) -> &'static EnumValueDescriptor { - fail!(); + panic!(); } fn get_rep_enum_item(&self, _m: &M, _index: uint) -> &'static EnumValueDescriptor { - fail!(); + panic!(); } fn get_str<'a>(&self, _m: &'a M) -> &'a str { - fail!(); + panic!(); } fn get_rep_str<'a>(&self, _m: &'a M) -> &'a [String] { - fail!(); + panic!(); } fn get_bytes<'a>(&self, _m: &'a M) -> &'a [u8] { - fail!(); + panic!(); } fn get_rep_bytes<'a>(&self, _m: &'a M) -> &'a [Vec] { - fail!(); + panic!(); } fn get_u32(&self, _m: &M) -> u32 { - fail!(); + panic!(); } fn get_rep_u32<'a>(&self, _m: &'a M) -> &'a [u32] { - fail!(); + panic!(); } fn get_u64(&self, _m: &M) -> u64 { - fail!(); + panic!(); } fn get_rep_u64<'a>(&self, _m: &'a M) -> &'a [u64] { - fail!(); + panic!(); } fn get_i32(&self, _m: &M) -> i32 { - fail!(); + panic!(); } fn get_rep_i32<'a>(&self, _m: &'a M) -> &'a [i32] { - fail!(); + panic!(); } fn get_i64(&self, _m: &M) -> i64 { - fail!(); + panic!(); } fn get_rep_i64<'a>(&self, _m: &'a M) -> &'a [i64] { - fail!(); + panic!(); } fn get_bool(&self, _m: &M) -> bool { - fail!(); + panic!(); } fn get_rep_bool<'a>(&self, _m: &'a M) -> &'a [bool] { - fail!(); + panic!(); } fn get_f32(&self, _m: &M) -> f32 { - fail!(); + panic!(); } fn get_rep_f32<'a>(&self, _m: &'a M) -> &'a [f32] { - fail!(); + panic!(); } fn get_f64(&self, _m: &M) -> f64 { - fail!(); + panic!(); } fn get_rep_f64<'a>(&self, _m: &'a M) -> &'a [f64] { - fail!(); + panic!(); } } diff --git a/src/lib/rt.rs b/src/lib/rt.rs index 1645085d7..cdc1d1d70 100644 --- a/src/lib/rt.rs +++ b/src/lib/rt.rs @@ -128,7 +128,7 @@ pub fn value_size_no_tag(value: T, wt: wire_format::WireType wire_format::WireTypeFixed64 => 8, wire_format::WireTypeFixed32 => 4, wire_format::WireTypeVarint => value.len_varint(), - _ => fail!() + _ => panic!() } } diff --git a/src/lib/shrug.rs b/src/lib/shrug.rs index d93bfbe1d..07ccea195 100644 --- a/src/lib/shrug.rs +++ b/src/lib/shrug.rs @@ -6595,7 +6595,7 @@ impl TestEnumDescriptor { 1 => RED, 2 => BLUE, 3 => GREEN, - _ => fail!() + _ => panic!() } } } @@ -6628,7 +6628,7 @@ impl EnumForDefaultValue { 1 => ONE, 2 => TWO, 3 => THREE, - _ => fail!() + _ => panic!() } } } diff --git a/src/lib/singular.rs b/src/lib/singular.rs index 3954b7b8a..1ce1b57af 100644 --- a/src/lib/singular.rs +++ b/src/lib/singular.rs @@ -87,7 +87,7 @@ impl SingularField { pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { match self.as_mut() { //Some(x) => slice::mut_ref_slice(x), // doesn't work I have no idea why - Some(_) => fail!(), + Some(_) => panic!(), None => &mut [] } } @@ -97,7 +97,7 @@ impl SingularField { if self.set { self.value } else { - fail!(); + panic!(); } } @@ -254,7 +254,7 @@ impl SingularPtrField { pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { match self.as_mut() { //Some(x) => slice::mut_ref_slice(x), // doesn't work I have no idea why - Some(_) => fail!(), + Some(_) => panic!(), None => &mut [] } } @@ -264,7 +264,7 @@ impl SingularPtrField { if self.set { *self.value.unwrap() } else { - fail!(); + panic!(); } } diff --git a/src/lib/stream.rs b/src/lib/stream.rs index 40656361a..e912c60fa 100644 --- a/src/lib/stream.rs +++ b/src/lib/stream.rs @@ -139,7 +139,7 @@ impl<'a> CodedInputStream<'a> { // Otherwize returns Ok(true). fn refill_buffer(&mut self) -> ProtobufResult { if self.buffer_pos < self.buffer_size { - fail!("called when buffer is not empty"); + panic!("called when buffer is not empty"); } if self.pos() == self.current_limit { return Ok(false); @@ -161,7 +161,7 @@ impl<'a> CodedInputStream<'a> { }; assert!(self.buffer_size > 0); }, - None => fail!(), + None => panic!(), } self.recompute_buffer_size_after_limit(); Ok(true) @@ -195,7 +195,7 @@ impl<'a> CodedInputStream<'a> { let old_limit = self.current_limit; let new_limit = self.pos() + limit; if new_limit > old_limit { - fail!("truncated message"); + panic!("truncated message"); } self.current_limit = new_limit; self.recompute_buffer_size_after_limit(); @@ -204,7 +204,7 @@ impl<'a> CodedInputStream<'a> { pub fn pop_limit(&mut self, old_limit: u32) { if self.bytes_until_limit() != 0 { - fail!("must pop only at current limit") + panic!("must pop only at current limit") } self.current_limit = old_limit; self.recompute_buffer_size_after_limit(); @@ -521,7 +521,7 @@ impl<'a> CodedOutputStream<'a> { try!(writer.write(self.buffer.slice(0, self.position as uint)) .map_err(|e| ProtobufIoError(e))); }, - None => fail!() + None => panic!() }; self.position = 0; Ok(()) @@ -548,7 +548,7 @@ impl<'a> CodedOutputStream<'a> { // TODO: write into buffer if enough capacity match self.writer { Some(ref mut writer) => try!(writer.write(bytes).map_err(|e| ProtobufIoError(e))), - None => fail!() + None => panic!() }; Ok(()) } diff --git a/src/lib/strx.rs b/src/lib/strx.rs index 1bbd0d925..b0978bb02 100644 --- a/src/lib/strx.rs +++ b/src/lib/strx.rs @@ -7,14 +7,14 @@ pub fn remove_to<'s>(s: &'s str, c: char) -> &'s str { pub fn remove_suffix<'s>(s: &'s str, suffix: &str) -> &'s str { if !s.ends_with(suffix) { - fail!(); + panic!(); } s.slice_to(s.len() - suffix.len()) } pub fn remove_prefix<'s>(s: &'s str, prefix: &str) -> &'s str { if !s.starts_with(prefix) { - fail!(); + panic!(); } s.slice_from(prefix.len()) } diff --git a/src/lib/test_nonunique_enum.rs b/src/lib/test_nonunique_enum.rs index 9cf4312ab..beb82170e 100644 --- a/src/lib/test_nonunique_enum.rs +++ b/src/lib/test_nonunique_enum.rs @@ -119,7 +119,7 @@ impl MessageA_EnumA { pub fn new(value: i32) -> MessageA_EnumA { match value { 0 => MessageA_FOO, - _ => fail!() + _ => panic!() } } } @@ -253,7 +253,7 @@ impl MessageB_EnumB { pub fn new(value: i32) -> MessageB_EnumB { match value { 0 => MessageB_FOO, - _ => fail!() + _ => panic!() } } } diff --git a/src/lib/text_format_test_data.rs b/src/lib/text_format_test_data.rs index 4fbede89b..dbf2ab3f1 100644 --- a/src/lib/text_format_test_data.rs +++ b/src/lib/text_format_test_data.rs @@ -2460,7 +2460,7 @@ impl TestEnum { match value { 1 => DARK, 2 => LIGHT, - _ => fail!() + _ => panic!() } } } diff --git a/src/perftest/perftest.rs b/src/perftest/perftest.rs index 857e371ca..551ddfa1d 100644 --- a/src/perftest/perftest.rs +++ b/src/perftest/perftest.rs @@ -94,7 +94,7 @@ impl TestRunner { fn check(&self) { if !self.any_matched { let name = self.selected.as_ref().map(|s| s.as_slice()).unwrap_or("bug"); - fail!("no tests found with name {}", name); + panic!("no tests found with name {}", name); } } } @@ -103,7 +103,7 @@ fn main() { let selected = match os::args().as_slice() { [_] => None, [_, ref test] => Some(test.to_string()), - v => fail!("usage: {} ", v[0]), + v => panic!("usage: {} ", v[0]), }; let mut runner = TestRunner { selected: selected, any_matched: false }; diff --git a/src/protobuf-bin-gen-rust.rs b/src/protobuf-bin-gen-rust.rs index d23fa8f5b..e0b4997bd 100644 --- a/src/protobuf-bin-gen-rust.rs +++ b/src/protobuf-bin-gen-rust.rs @@ -33,7 +33,7 @@ fn main() { let matches = getopts::getopts(args.tail(), opts.as_slice()).unwrap(); let pb_bin = match matches.free.as_slice() { [ref pb_bin] => pb_bin.to_string(), - _ => fail!("must have exactly one argument") + _ => panic!("must have exactly one argument") }; let gen_options = GenOptions { dummy: false,