Skip to content

Use static string with fail!() and remove fail!(fmt!()) #6357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2386,9 +2386,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
let x: List<int> = Cons(10, @Cons(11, @Nil));

match x {
Cons(_, @Nil) => fail!(~"singleton list"),
Cons(_, @Nil) => fail!("singleton list"),
Cons(*) => return,
Nil => fail!(~"empty list")
Nil => fail!("empty list")
}
~~~~

Expand Down
6 changes: 3 additions & 3 deletions doc/tutorial-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ match x {
// complicated stuff goes here
return result + val;
},
_ => fail!(~"Didn't get good_2")
_ => fail!("Didn't get good_2")
}
}
_ => return 0 // default value
Expand Down Expand Up @@ -265,7 +265,7 @@ macro_rules! biased_match (
biased_match!((x) ~ (good_1(g1, val)) else { return 0 };
binds g1, val )
biased_match!((g1.body) ~ (good_2(result) )
else { fail!(~"Didn't get good_2") };
else { fail!("Didn't get good_2") };
binds result )
// complicated stuff goes here
return result + val;
Expand Down Expand Up @@ -366,7 +366,7 @@ macro_rules! biased_match (
# fn f(x: t1) -> uint {
biased_match!(
(x) ~ (good_1(g1, val)) else { return 0 };
(g1.body) ~ (good_2(result) ) else { fail!(~"Didn't get good_2") };
(g1.body) ~ (good_2(result) ) else { fail!("Didn't get good_2") };
binds val, result )
// complicated stuff goes here
return result + val;
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ let result: Result<int, ()> = do task::try {
if some_condition() {
calculate_result()
} else {
fail!(~"oops!");
fail!("oops!");
}
};
assert!(result.is_err());
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub fn str_mode(s: ~str) -> mode {
~"run-pass" => mode_run_pass,
~"pretty" => mode_pretty,
~"debug-info" => mode_debug_info,
_ => fail!(~"invalid mode")
_ => fail!("invalid mode")
}
}

Expand All @@ -169,7 +169,7 @@ pub fn run_tests(config: config) {
let opts = test_opts(config);
let tests = make_tests(config);
let res = test::run_tests_console(&opts, tests);
if !res { fail!(~"Some tests failed"); }
if !res { fail!("Some tests failed"); }
}

pub fn test_opts(config: config) -> test::TestOpts {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
match strs.len() {
1u => (strs[0], ~""),
2u => (strs[0], strs[1]),
n => fail!(fmt!("Expected 1 or 2 strings, not %u", n))
n => fail!("Expected 1 or 2 strings, not %u", n)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ fn compose_and_run_compiler(
fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail!(fmt!("can't make dir %s", path.to_str()));
fail!("can't make dir %s", path.to_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub impl<T> Cell<T> {
fn take(&self) -> T {
let this = unsafe { transmute_mut(self) };
if this.is_empty() {
fail!(~"attempt to take an empty cell");
fail!("attempt to take an empty cell");
}

replace(&mut this.value, None).unwrap()
Expand All @@ -56,7 +56,7 @@ pub impl<T> Cell<T> {
fn put_back(&self, value: T) {
let this = unsafe { transmute_mut(self) };
if !this.is_empty() {
fail!(~"attempt to put a value back into a full cell");
fail!("attempt to put a value back into a full cell");
}
this.value = Some(value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn is_digit_radix(c: char, radix: uint) -> bool {
#[inline]
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
if radix > 36 {
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
fail!("to_digit: radix %? is to high (maximum 36)", radix);
}
let val = match c {
'0' .. '9' => c as uint - ('0' as uint),
Expand All @@ -168,7 +168,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
#[inline]
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
if radix > 36 {
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
fail!("from_digit: radix %? is to high (maximum 36)", num);
}
if num < radix {
if num < 10 {
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn len_utf8_bytes(c: char) -> uint {
else if code < max_two_b { 2u }
else if code < max_three_b { 3u }
else if code < max_four_b { 4u }
else { fail!(~"invalid character!") }
else { fail!("invalid character!") }
}

#[cfg(not(test))]
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
let mut endp = replace(self_endp, None);
let peek = match endp {
Some(ref mut endp) => peek(endp),
None => fail!(~"peeking empty stream")
None => fail!("peeking empty stream")
};
*self_endp = endp;
peek
Expand All @@ -222,7 +222,7 @@ impl<T: Owned> Selectable for Port<T> {
fn header(&mut self) -> *mut PacketHeader {
match self.endp {
Some(ref mut endp) => endp.header(),
None => fail!(~"peeking empty stream")
None => fail!("peeking empty stream")
}
}
}
Expand Down Expand Up @@ -522,7 +522,7 @@ pub fn select2i<A:Selectable, B:Selectable>(a: &mut A, b: &mut B)
match wait_many(endpoints) {
0 => Left(()),
1 => Right(()),
_ => fail!(~"wait returned unexpected index"),
_ => fail!("wait returned unexpected index"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {

match eith {
Left(x) => x,
Right(_) => fail!(~"either::unwrap_left Right")
Right(_) => fail!("either::unwrap_left Right")
}
}

Expand All @@ -145,7 +145,7 @@ pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {

match eith {
Right(x) => x,
Left(_) => fail!(~"either::unwrap_right Left")
Left(_) => fail!("either::unwrap_right Left")
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
fn value_for_bucket<'a>(&'a self, idx: uint) -> &'a V {
match self.buckets[idx] {
Some(ref bkt) => &bkt.value,
None => fail!(~"HashMap::find: internal logic error"),
None => fail!("HashMap::find: internal logic error"),
}
}

Expand All @@ -217,7 +217,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
/// True if there was no previous entry with that key
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> Option<V> {
match self.bucket_for_key_with_hash(hash, &k) {
TableFull => { fail!(~"Internal logic error"); }
TableFull => { fail!("Internal logic error"); }
FoundHole(idx) => {
debug!("insert fresh (%?->%?) at idx %?, hash %?",
k, v, idx, hash);
Expand All @@ -230,7 +230,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
k, v, idx, hash);
match self.buckets[idx] {
None => { fail!(~"insert_internal: Internal logic error") }
None => { fail!("insert_internal: Internal logic error") }
Some(ref mut b) => {
b.hash = hash;
b.key = k;
Expand Down Expand Up @@ -500,7 +500,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
TableFull => fail!("Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
Expand Down Expand Up @@ -531,7 +531,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
TableFull => fail!("Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
Expand Down Expand Up @@ -560,7 +560,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
TableFull => fail!("Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
let v = f(&k);
Expand Down Expand Up @@ -592,7 +592,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {

let hash = k.hash_keyed(self.k0, self.k1) as uint;
let idx = match self.bucket_for_key_with_hash(hash, &k) {
TableFull => fail!(~"Internal logic error"),
TableFull => fail!("Internal logic error"),
FoundEntry(idx) => idx,
FoundHole(idx) => {
let v = f(&k);
Expand Down Expand Up @@ -623,7 +623,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
fn get<'a>(&'a self, k: &K) -> &'a V {
match self.find(k) {
Some(v) => v,
None => fail!(fmt!("No entry found for key: %?", k)),
None => fail!("No entry found for key: %?", k),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ fn test_tls_modify() {
fn my_key(_x: @~str) { }
local_data_modify(my_key, |data| {
match data {
Some(@ref val) => fail!(~"unwelcome value: " + *val),
None => Some(@~"first data")
Some(@ref val) => fail!("unwelcome value: %s", *val),
None => Some(@~"first data")
}
});
local_data_modify(my_key, |data| {
match data {
Some(@~"first data") => Some(@~"next data"),
Some(@ref val) => fail!(~"wrong value: " + *val),
None => fail!(~"missing value")
Some(@ref val) => fail!("wrong value: %s", *val),
None => fail!("missing value")
}
});
assert!(*(local_data_pop(my_key).get()) == ~"next data");
Expand Down Expand Up @@ -223,4 +223,4 @@ fn test_static_pointer() {
static VALUE: int = 0;
local_data_set(key, @&VALUE);
}
}
}
2 changes: 1 addition & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ pub fn to_str_hex(num: f32) -> ~str {
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
if special { fail!("number has a special value, \
try to_str_radix_special() if those are expected") }
r
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ pub fn to_str_hex(num: f64) -> ~str {
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
if special { fail!("number has a special value, \
try to_str_radix_special() if those are expected") }
r
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn to_str_hex(num: float) -> ~str {
pub fn to_str_radix(num: float, radix: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, radix, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
if special { fail!("number has a special value, \
try to_str_radix_special() if those are expected") }
r
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn gt(x: T, y: T) -> bool { x > y }
pub fn _range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) -> bool {
let mut i = start;
if step == 0 {
fail!(~"range_step called with step == 0");
fail!("range_step called with step == 0");
} else if step > 0 { // ascending
while i < stop {
if !it(i) { return false; }
Expand Down Expand Up @@ -923,16 +923,16 @@ mod tests {

// None of the `fail`s should execute.
for range(10,0) |_i| {
fail!(~"unreachable");
fail!("unreachable");
}
for range_rev(0,10) |_i| {
fail!(~"unreachable");
fail!("unreachable");
}
for range_step(10,0,1) |_i| {
fail!(~"unreachable");
fail!("unreachable");
}
for range_step(0,10,-1) |_i| {
fail!(~"unreachable");
fail!("unreachable");
}
}

Expand Down
26 changes: 12 additions & 14 deletions src/libcore/num/strconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
if (radix as int) < 2 {
fail!(fmt!("to_str_bytes_common: radix %? to low, \
must lie in the range [2, 36]", radix));
fail!("to_str_bytes_common: radix %? to low, must lie in the range [2, 36]", radix);
} else if radix as int > 36 {
fail!(fmt!("to_str_bytes_common: radix %? to high, \
must lie in the range [2, 36]", radix));
fail!("to_str_bytes_common: radix %? to high, must lie in the range [2, 36]", radix);
}

let _0: T = Zero::zero();
Expand Down Expand Up @@ -444,20 +442,20 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
) -> Option<T> {
match exponent {
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
use of 'e' as decimal exponent", radix)),
=> fail!("from_str_bytes_common: radix %? incompatible with \
use of 'e' as decimal exponent", radix),
ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p'
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
use of 'p' as binary exponent", radix)),
=> fail!("from_str_bytes_common: radix %? incompatible with \
use of 'p' as binary exponent", radix),
_ if special && radix >= DIGIT_I_RADIX // first digit of 'inf'
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
special values 'inf' and 'NaN'", radix)),
=> fail!("from_str_bytes_common: radix %? incompatible with \
special values 'inf' and 'NaN'", radix),
_ if (radix as int) < 2
=> fail!(fmt!("from_str_bytes_common: radix %? to low, \
must lie in the range [2, 36]", radix)),
=> fail!("from_str_bytes_common: radix %? to low, \
must lie in the range [2, 36]", radix),
_ if (radix as int) > 36
=> fail!(fmt!("from_str_bytes_common: radix %? to high, \
must lie in the range [2, 36]", radix)),
=> fail!("from_str_bytes_common: radix %? to high, \
must lie in the range [2, 36]", radix),
_ => ()
}

Expand Down
Loading