Skip to content

Commit 27c228f

Browse files
committed
auto merge of #6357 : dotdash/rust/fixfmt, r=bstrie
fail!() used to require owned strings but can handle static strings now. Also, it can pass its arguments to fmt!() on its own, no need for the caller to call fmt!() itself.
2 parents 84745b4 + 04de8f8 commit 27c228f

File tree

178 files changed

+543
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+543
-573
lines changed

doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,9 +2386,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
23862386
let x: List<int> = Cons(10, @Cons(11, @Nil));
23872387
23882388
match x {
2389-
Cons(_, @Nil) => fail!(~"singleton list"),
2389+
Cons(_, @Nil) => fail!("singleton list"),
23902390
Cons(*) => return,
2391-
Nil => fail!(~"empty list")
2391+
Nil => fail!("empty list")
23922392
}
23932393
~~~~
23942394

doc/tutorial-macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ match x {
223223
// complicated stuff goes here
224224
return result + val;
225225
},
226-
_ => fail!(~"Didn't get good_2")
226+
_ => fail!("Didn't get good_2")
227227
}
228228
}
229229
_ => return 0 // default value
@@ -265,7 +265,7 @@ macro_rules! biased_match (
265265
biased_match!((x) ~ (good_1(g1, val)) else { return 0 };
266266
binds g1, val )
267267
biased_match!((g1.body) ~ (good_2(result) )
268-
else { fail!(~"Didn't get good_2") };
268+
else { fail!("Didn't get good_2") };
269269
binds result )
270270
// complicated stuff goes here
271271
return result + val;
@@ -366,7 +366,7 @@ macro_rules! biased_match (
366366
# fn f(x: t1) -> uint {
367367
biased_match!(
368368
(x) ~ (good_1(g1, val)) else { return 0 };
369-
(g1.body) ~ (good_2(result) ) else { fail!(~"Didn't get good_2") };
369+
(g1.body) ~ (good_2(result) ) else { fail!("Didn't get good_2") };
370370
binds val, result )
371371
// complicated stuff goes here
372372
return result + val;

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ let result: Result<int, ()> = do task::try {
325325
if some_condition() {
326326
calculate_result()
327327
} else {
328-
fail!(~"oops!");
328+
fail!("oops!");
329329
}
330330
};
331331
assert!(result.is_err());

src/compiletest/compiletest.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn str_mode(s: ~str) -> mode {
151151
~"run-pass" => mode_run_pass,
152152
~"pretty" => mode_pretty,
153153
~"debug-info" => mode_debug_info,
154-
_ => fail!(~"invalid mode")
154+
_ => fail!("invalid mode")
155155
}
156156
}
157157

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

175175
pub fn test_opts(config: config) -> test::TestOpts {

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
139139
match strs.len() {
140140
1u => (strs[0], ~""),
141141
2u => (strs[0], strs[1]),
142-
n => fail!(fmt!("Expected 1 or 2 strings, not %u", n))
142+
n => fail!("Expected 1 or 2 strings, not %u", n)
143143
}
144144
}
145145
}

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ fn compose_and_run_compiler(
561561
fn ensure_dir(path: &Path) {
562562
if os::path_is_dir(path) { return; }
563563
if !os::make_dir(path, 0x1c0i32) {
564-
fail!(fmt!("can't make dir %s", path.to_str()));
564+
fail!("can't make dir %s", path.to_str());
565565
}
566566
}
567567

src/libcore/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub impl<T> Cell<T> {
4646
fn take(&self) -> T {
4747
let this = unsafe { transmute_mut(self) };
4848
if this.is_empty() {
49-
fail!(~"attempt to take an empty cell");
49+
fail!("attempt to take an empty cell");
5050
}
5151

5252
replace(&mut this.value, None).unwrap()
@@ -56,7 +56,7 @@ pub impl<T> Cell<T> {
5656
fn put_back(&self, value: T) {
5757
let this = unsafe { transmute_mut(self) };
5858
if !this.is_empty() {
59-
fail!(~"attempt to put a value back into a full cell");
59+
fail!("attempt to put a value back into a full cell");
6060
}
6161
this.value = Some(value);
6262
}

src/libcore/char.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn is_digit_radix(c: char, radix: uint) -> bool {
145145
#[inline]
146146
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
147147
if radix > 36 {
148-
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
148+
fail!("to_digit: radix %? is to high (maximum 36)", radix);
149149
}
150150
let val = match c {
151151
'0' .. '9' => c as uint - ('0' as uint),
@@ -168,7 +168,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
168168
#[inline]
169169
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
170170
if radix > 36 {
171-
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
171+
fail!("from_digit: radix %? is to high (maximum 36)", num);
172172
}
173173
if num < radix {
174174
if num < 10 {
@@ -241,7 +241,7 @@ pub fn len_utf8_bytes(c: char) -> uint {
241241
else if code < max_two_b { 2u }
242242
else if code < max_three_b { 3u }
243243
else if code < max_four_b { 4u }
244-
else { fail!(~"invalid character!") }
244+
else { fail!("invalid character!") }
245245
}
246246

247247
#[cfg(not(test))]

src/libcore/comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
210210
let mut endp = replace(self_endp, None);
211211
let peek = match endp {
212212
Some(ref mut endp) => peek(endp),
213-
None => fail!(~"peeking empty stream")
213+
None => fail!("peeking empty stream")
214214
};
215215
*self_endp = endp;
216216
peek
@@ -222,7 +222,7 @@ impl<T: Owned> Selectable for Port<T> {
222222
fn header(&mut self) -> *mut PacketHeader {
223223
match self.endp {
224224
Some(ref mut endp) => endp.header(),
225-
None => fail!(~"peeking empty stream")
225+
None => fail!("peeking empty stream")
226226
}
227227
}
228228
}
@@ -522,7 +522,7 @@ pub fn select2i<A:Selectable, B:Selectable>(a: &mut A, b: &mut B)
522522
match wait_many(endpoints) {
523523
0 => Left(()),
524524
1 => Right(()),
525-
_ => fail!(~"wait returned unexpected index"),
525+
_ => fail!("wait returned unexpected index"),
526526
}
527527
}
528528

src/libcore/either.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
135135
136136
match eith {
137137
Left(x) => x,
138-
Right(_) => fail!(~"either::unwrap_left Right")
138+
Right(_) => fail!("either::unwrap_left Right")
139139
}
140140
}
141141

@@ -145,7 +145,7 @@ pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
145145
146146
match eith {
147147
Right(x) => x,
148-
Left(_) => fail!(~"either::unwrap_right Left")
148+
Left(_) => fail!("either::unwrap_right Left")
149149
}
150150
}
151151

src/libcore/hashmap.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
200200
fn value_for_bucket<'a>(&'a self, idx: uint) -> &'a V {
201201
match self.buckets[idx] {
202202
Some(ref bkt) => &bkt.value,
203-
None => fail!(~"HashMap::find: internal logic error"),
203+
None => fail!("HashMap::find: internal logic error"),
204204
}
205205
}
206206

@@ -217,7 +217,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
217217
/// True if there was no previous entry with that key
218218
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> Option<V> {
219219
match self.bucket_for_key_with_hash(hash, &k) {
220-
TableFull => { fail!(~"Internal logic error"); }
220+
TableFull => { fail!("Internal logic error"); }
221221
FoundHole(idx) => {
222222
debug!("insert fresh (%?->%?) at idx %?, hash %?",
223223
k, v, idx, hash);
@@ -230,7 +230,7 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
230230
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
231231
k, v, idx, hash);
232232
match self.buckets[idx] {
233-
None => { fail!(~"insert_internal: Internal logic error") }
233+
None => { fail!("insert_internal: Internal logic error") }
234234
Some(ref mut b) => {
235235
b.hash = hash;
236236
b.key = k;
@@ -500,7 +500,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
500500

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

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

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

593593
let hash = k.hash_keyed(self.k0, self.k1) as uint;
594594
let idx = match self.bucket_for_key_with_hash(hash, &k) {
595-
TableFull => fail!(~"Internal logic error"),
595+
TableFull => fail!("Internal logic error"),
596596
FoundEntry(idx) => idx,
597597
FoundHole(idx) => {
598598
let v = f(&k);
@@ -623,7 +623,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
623623
fn get<'a>(&'a self, k: &K) -> &'a V {
624624
match self.find(k) {
625625
Some(v) => v,
626-
None => fail!(fmt!("No entry found for key: %?", k)),
626+
None => fail!("No entry found for key: %?", k),
627627
}
628628
}
629629

src/libcore/local_data.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ fn test_tls_modify() {
132132
fn my_key(_x: @~str) { }
133133
local_data_modify(my_key, |data| {
134134
match data {
135-
Some(@ref val) => fail!(~"unwelcome value: " + *val),
136-
None => Some(@~"first data")
135+
Some(@ref val) => fail!("unwelcome value: %s", *val),
136+
None => Some(@~"first data")
137137
}
138138
});
139139
local_data_modify(my_key, |data| {
140140
match data {
141141
Some(@~"first data") => Some(@~"next data"),
142-
Some(@ref val) => fail!(~"wrong value: " + *val),
143-
None => fail!(~"missing value")
142+
Some(@ref val) => fail!("wrong value: %s", *val),
143+
None => fail!("missing value")
144144
}
145145
});
146146
assert!(*(local_data_pop(my_key).get()) == ~"next data");
@@ -223,4 +223,4 @@ fn test_static_pointer() {
223223
static VALUE: int = 0;
224224
local_data_set(key, @&VALUE);
225225
}
226-
}
226+
}

src/libcore/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ pub fn to_str_hex(num: f32) -> ~str {
772772
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
773773
let (r, special) = strconv::to_str_common(
774774
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
775-
if special { fail!(~"number has a special value, \
775+
if special { fail!("number has a special value, \
776776
try to_str_radix_special() if those are expected") }
777777
r
778778
}

src/libcore/num/f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ pub fn to_str_hex(num: f64) -> ~str {
814814
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
815815
let (r, special) = strconv::to_str_common(
816816
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
817-
if special { fail!(~"number has a special value, \
817+
if special { fail!("number has a special value, \
818818
try to_str_radix_special() if those are expected") }
819819
r
820820
}

src/libcore/num/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn to_str_hex(num: float) -> ~str {
133133
pub fn to_str_radix(num: float, radix: uint) -> ~str {
134134
let (r, special) = strconv::to_str_common(
135135
&num, radix, true, strconv::SignNeg, strconv::DigAll);
136-
if special { fail!(~"number has a special value, \
136+
if special { fail!("number has a special value, \
137137
try to_str_radix_special() if those are expected") }
138138
r
139139
}

src/libcore/num/int-template.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn gt(x: T, y: T) -> bool { x > y }
8989
pub fn _range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) -> bool {
9090
let mut i = start;
9191
if step == 0 {
92-
fail!(~"range_step called with step == 0");
92+
fail!("range_step called with step == 0");
9393
} else if step > 0 { // ascending
9494
while i < stop {
9595
if !it(i) { return false; }
@@ -923,16 +923,16 @@ mod tests {
923923
924924
// None of the `fail`s should execute.
925925
for range(10,0) |_i| {
926-
fail!(~"unreachable");
926+
fail!("unreachable");
927927
}
928928
for range_rev(0,10) |_i| {
929-
fail!(~"unreachable");
929+
fail!("unreachable");
930930
}
931931
for range_step(10,0,1) |_i| {
932-
fail!(~"unreachable");
932+
fail!("unreachable");
933933
}
934934
for range_step(0,10,-1) |_i| {
935-
fail!(~"unreachable");
935+
fail!("unreachable");
936936
}
937937
}
938938

src/libcore/num/strconv.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,9 @@ pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
178178
num: &T, radix: uint, negative_zero: bool,
179179
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
180180
if (radix as int) < 2 {
181-
fail!(fmt!("to_str_bytes_common: radix %? to low, \
182-
must lie in the range [2, 36]", radix));
181+
fail!("to_str_bytes_common: radix %? to low, must lie in the range [2, 36]", radix);
183182
} else if radix as int > 36 {
184-
fail!(fmt!("to_str_bytes_common: radix %? to high, \
185-
must lie in the range [2, 36]", radix));
183+
fail!("to_str_bytes_common: radix %? to high, must lie in the range [2, 36]", radix);
186184
}
187185

188186
let _0: T = Zero::zero();
@@ -444,20 +442,20 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
444442
) -> Option<T> {
445443
match exponent {
446444
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
447-
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
448-
use of 'e' as decimal exponent", radix)),
445+
=> fail!("from_str_bytes_common: radix %? incompatible with \
446+
use of 'e' as decimal exponent", radix),
449447
ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p'
450-
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
451-
use of 'p' as binary exponent", radix)),
448+
=> fail!("from_str_bytes_common: radix %? incompatible with \
449+
use of 'p' as binary exponent", radix),
452450
_ if special && radix >= DIGIT_I_RADIX // first digit of 'inf'
453-
=> fail!(fmt!("from_str_bytes_common: radix %? incompatible with \
454-
special values 'inf' and 'NaN'", radix)),
451+
=> fail!("from_str_bytes_common: radix %? incompatible with \
452+
special values 'inf' and 'NaN'", radix),
455453
_ if (radix as int) < 2
456-
=> fail!(fmt!("from_str_bytes_common: radix %? to low, \
457-
must lie in the range [2, 36]", radix)),
454+
=> fail!("from_str_bytes_common: radix %? to low, \
455+
must lie in the range [2, 36]", radix),
458456
_ if (radix as int) > 36
459-
=> fail!(fmt!("from_str_bytes_common: radix %? to high, \
460-
must lie in the range [2, 36]", radix)),
457+
=> fail!("from_str_bytes_common: radix %? to high, \
458+
must lie in the range [2, 36]", radix),
461459
_ => ()
462460
}
463461

0 commit comments

Comments
 (0)