Skip to content

Commit 8bb48cc

Browse files
committed
auto merge of #9599 : alexcrichton/rust/less-fmt, r=huonw
This also prevents future fmt! usage from leaking into the compiler, but it's still turned on by default for everyone else.
2 parents f6df7ab + dec3705 commit 8bb48cc

File tree

817 files changed

+4793
-4781
lines changed

Some content is hidden

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

817 files changed

+4793
-4781
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
8888
CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
8989
endif
9090

91-
CFG_RUSTC_FLAGS := $(RUSTFLAGS)
91+
CFG_RUSTC_FLAGS := $(RUSTFLAGS) --cfg nofmt
9292
CFG_GCCISH_CFLAGS :=
9393
CFG_GCCISH_LINK_FLAGS :=
9494

doc/rust.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,15 @@ mod math {
683683
type complex = (f64, f64);
684684
fn sin(f: f64) -> f64 {
685685
...
686-
# fail!();
686+
# fail2!();
687687
}
688688
fn cos(f: f64) -> f64 {
689689
...
690-
# fail!();
690+
# fail2!();
691691
}
692692
fn tan(f: f64) -> f64 {
693693
...
694-
# fail!();
694+
# fail2!();
695695
}
696696
}
697697
~~~~~~~~
@@ -817,12 +817,14 @@ An example of `use` declarations:
817817
use std::num::sin;
818818
use std::option::{Some, None};
819819
820+
# fn foo<T>(_: T){}
821+
820822
fn main() {
821-
// Equivalent to 'info!(std::num::sin(1.0));'
822-
info!(sin(1.0));
823+
// Equivalent to 'std::num::sin(1.0);'
824+
sin(1.0);
823825
824-
// Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);'
825-
info!(~[Some(1.0), None]);
826+
// Equivalent to 'foo(~[std::option::Some(1.0), std::option::None]);'
827+
foo(~[Some(1.0), None]);
826828
}
827829
~~~~
828830

@@ -1040,8 +1042,8 @@ output slot type would normally be. For example:
10401042

10411043
~~~~
10421044
fn my_err(s: &str) -> ! {
1043-
info!(s);
1044-
fail!();
1045+
info2!("{}", s);
1046+
fail2!();
10451047
}
10461048
~~~~
10471049

@@ -1059,7 +1061,7 @@ were declared without the `!` annotation, the following code would not
10591061
typecheck:
10601062

10611063
~~~~
1062-
# fn my_err(s: &str) -> ! { fail!() }
1064+
# fn my_err(s: &str) -> ! { fail2!() }
10631065
10641066
fn f(i: int) -> int {
10651067
if i == 42 {
@@ -2382,7 +2384,7 @@ fn ten_times(f: &fn(int)) {
23822384
}
23832385
}
23842386
2385-
ten_times(|j| println(fmt!("hello, %d", j)));
2387+
ten_times(|j| println!("hello, {}", j));
23862388
23872389
~~~~
23882390

@@ -2594,9 +2596,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
25942596
let x: List<int> = Cons(10, @Cons(11, @Nil));
25952597
25962598
match x {
2597-
Cons(_, @Nil) => fail!("singleton list"),
2599+
Cons(_, @Nil) => fail2!("singleton list"),
25982600
Cons(*) => return,
2599-
Nil => fail!("empty list")
2601+
Nil => fail2!("empty list")
26002602
}
26012603
~~~~
26022604

@@ -2633,7 +2635,7 @@ match x {
26332635
return;
26342636
}
26352637
_ => {
2636-
fail!();
2638+
fail2!();
26372639
}
26382640
}
26392641
~~~~
@@ -2687,7 +2689,7 @@ guard may refer to the variables bound within the pattern they follow.
26872689
let message = match maybe_digit {
26882690
Some(x) if x < 10 => process_digit(x),
26892691
Some(x) => process_other(x),
2690-
None => fail!()
2692+
None => fail2!()
26912693
};
26922694
~~~~
26932695

@@ -3472,20 +3474,20 @@ that demonstrates all four of them:
34723474

34733475
```rust
34743476
fn main() {
3475-
error!("This is an error log")
3476-
warn!("This is a warn log")
3477-
info!("this is an info log")
3478-
debug!("This is a debug log")
3477+
error2!("This is an error log")
3478+
warn2!("This is a warn log")
3479+
info2!("this is an info log")
3480+
debug2!("This is a debug log")
34793481
}
34803482
```
34813483

34823484
These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`:
34833485

34843486
```bash
34853487
$ RUST_LOG=rust=3 ./rust
3486-
rust: ~"\"This is an error log\""
3487-
rust: ~"\"This is a warn log\""
3488-
rust: ~"\"this is an info log\""
3488+
This is an error log
3489+
This is a warn log
3490+
this is an info log
34893491
```
34903492

34913493
# Appendix: Rationales and design tradeoffs

doc/tutorial-conditions.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use std::int;
6666
fn main() {
6767
let pairs = read_int_pairs();
6868
for &(a,b) in pairs.iter() {
69-
println(fmt!("%4.4d, %4.4d", a, b));
69+
println!("{:4.4d}, {:4.4d}", a, b);
7070
}
7171
}
7272
@@ -281,7 +281,7 @@ fn main() {
281281
// The protected logic.
282282
let pairs = read_int_pairs();
283283
for &(a,b) in pairs.iter() {
284-
println(fmt!("%4.4d, %4.4d", a, b));
284+
println!("{:4.4d}, {:4.4d}", a, b);
285285
}
286286
287287
};
@@ -387,7 +387,7 @@ condition! {
387387
fn main() {
388388
let pairs = read_int_pairs();
389389
for &(a,b) in pairs.iter() {
390-
println(fmt!("%4.4d, %4.4d", a, b));
390+
println!("{:4.4d}, {:4.4d}", a, b);
391391
}
392392
}
393393
@@ -462,7 +462,7 @@ fn main() {
462462
// The protected logic.
463463
let pairs = read_int_pairs();
464464
for &(a,b) in pairs.iter() {
465-
println(fmt!("%4.4d, %4.4d", a, b));
465+
println!("{:4.4d}, {:4.4d}", a, b);
466466
}
467467
468468
}
@@ -540,7 +540,7 @@ fn main() {
540540
// The protected logic.
541541
let pairs = read_int_pairs();
542542
for &(a,b) in pairs.iter() {
543-
println(fmt!("%4.4d, %4.4d", a, b));
543+
println!("{:4.4d}, {:4.4d}", a, b);
544544
}
545545
546546
}
@@ -636,7 +636,7 @@ fn main() {
636636
// The protected logic.
637637
let pairs = read_int_pairs();
638638
for &(a,b) in pairs.iter() {
639-
println(fmt!("%4.4d, %4.4d", a, b));
639+
println!("{:4.4d}, {:4.4d}", a, b);
640640
}
641641
642642
}
@@ -766,7 +766,7 @@ fn main() {
766766
// The protected logic.
767767
let pairs = read_int_pairs();
768768
for &(a,b) in pairs.iter() {
769-
println(fmt!("%4.4d, %4.4d", a, b));
769+
println!("{:4.4d}, {:4.4d}", a, b);
770770
}
771771
772772
}

doc/tutorial-macros.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ match x {
226226
// complicated stuff goes here
227227
return result + val;
228228
},
229-
_ => fail!("Didn't get good_2")
229+
_ => fail2!("Didn't get good_2")
230230
}
231231
}
232232
_ => return 0 // default value
@@ -268,7 +268,7 @@ macro_rules! biased_match (
268268
biased_match!((x) ~ (good_1(g1, val)) else { return 0 };
269269
binds g1, val )
270270
biased_match!((g1.body) ~ (good_2(result) )
271-
else { fail!("Didn't get good_2") };
271+
else { fail2!("Didn't get good_2") };
272272
binds result )
273273
// complicated stuff goes here
274274
return result + val;
@@ -369,7 +369,7 @@ macro_rules! biased_match (
369369
# fn f(x: t1) -> uint {
370370
biased_match!(
371371
(x) ~ (good_1(g1, val)) else { return 0 };
372-
(g1.body) ~ (good_2(result) ) else { fail!("Didn't get good_2") };
372+
(g1.body) ~ (good_2(result) ) else { fail2!("Didn't get good_2") };
373373
binds val, result )
374374
// complicated stuff goes here
375375
return result + val;

doc/tutorial-tasks.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ execution. Like any closure, the function passed to `spawn` may capture
9999
an environment that it carries across tasks.
100100

101101
~~~
102-
# use std::io::println;
103102
# use std::task::spawn;
104103
# fn generate_task_number() -> int { 0 }
105104
// Generate some state locally
106105
let child_task_number = generate_task_number();
107106
108107
do spawn {
109108
// Capture it in the remote task
110-
println(fmt!("I am child number %d", child_task_number));
109+
println!("I am child number {}", child_task_number);
111110
}
112111
~~~
113112

@@ -282,7 +281,7 @@ fn fib(n: uint) -> uint {
282281
283282
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
284283
make_a_sandwich();
285-
println(fmt!("fib(50) = %?", delayed_fib.get()))
284+
println!("fib(50) = {:?}", delayed_fib.get())
286285
~~~
287286

288287
The call to `future::spawn` returns immediately a `future` object regardless of how long it
@@ -310,7 +309,7 @@ fn main() {
310309
for ft in futures.mut_iter() {
311310
final_res += ft.get();
312311
}
313-
println(fmt!("π^2/6 is not far from : %?", final_res));
312+
println!("π^2/6 is not far from : {}", final_res);
314313
}
315314
~~~
316315

@@ -338,7 +337,7 @@ fn pnorm(nums: &~[float], p: uint) -> float {
338337
339338
fn main() {
340339
let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
341-
println(fmt!("Inf-norm = %?", *numbers.iter().max().unwrap()));
340+
println!("Inf-norm = {}", *numbers.iter().max().unwrap());
342341
343342
let numbers_arc = Arc::new(numbers);
344343
@@ -349,7 +348,7 @@ fn main() {
349348
do spawn {
350349
let local_arc : Arc<~[float]> = port.recv();
351350
let task_numbers = local_arc.get();
352-
println(fmt!("%u-norm = %?", num, pnorm(task_numbers, num)));
351+
println!("{}-norm = {}", num, pnorm(task_numbers, num));
353352
}
354353
}
355354
}

doc/tutorial.md

+20-17
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ let hi = "hi";
225225
let mut count = 0;
226226
227227
while count < 10 {
228-
println(fmt!("count: %?", count));
228+
println!("count: {}", count);
229229
count += 1;
230230
}
231231
~~~~
@@ -388,23 +388,26 @@ assert!(y == 4u);
388388
but are instead provided by the libraries. To make it clear to the reader when
389389
a name refers to a syntax extension, the names of all syntax extensions end
390390
with `!`. The standard library defines a few syntax extensions, the most
391-
useful of which is `fmt!`, a `sprintf`-style text formatter that you will
392-
often see in examples.
391+
useful of which is [`format!`][fmt], a `sprintf`-like text formatter that you
392+
will often see in examples, and its related family of macros: `print!`,
393+
`println!`, and `write!`.
393394

394-
`fmt!` supports most of the directives that [printf][pf] supports, but unlike
395-
printf, will give you a compile-time error when the types of the directives
396-
don't match the types of the arguments.
395+
`format!` draws syntax from python, but contains many of the same principles
396+
that [printf][pf] has. Unlike printf, `format!` will give you a compile-time
397+
error when the types of the directives don't match the types of the arguments.
397398

398399
~~~~
399400
# let mystery_object = ();
400401
401-
println(fmt!("%s is %d", "the answer", 43));
402+
// {} will print the "default format" of a type
403+
println!("{} is {}", "the answer", 43);
402404
403-
// %? will conveniently print any type
404-
println(fmt!("what is this thing: %?", mystery_object));
405+
// {:?} will conveniently print any type
406+
println!("what is this thing: {:?}", mystery_object);
405407
~~~~
406408

407409
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
410+
[fmt]: http://static.rust-lang.org/doc/master/std/fmt/index.html
408411

409412
You can define your own syntax extensions with the macro system. For details, see the [macro tutorial][macros].
410413

@@ -737,7 +740,7 @@ fn area(sh: Shape) -> float {
737740
match sh {
738741
Circle { radius: radius, _ } => float::consts::pi * square(radius),
739742
Rectangle { top_left: top_left, bottom_right: bottom_right } => {
740-
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y)
743+
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y)
741744
}
742745
}
743746
}
@@ -753,7 +756,7 @@ unit, `()`, as the empty tuple if you like).
753756
~~~~
754757
let mytup: (int, int, float) = (10, 20, 30.0);
755758
match mytup {
756-
(a, b, c) => info!(a + b + (c as int))
759+
(a, b, c) => info2!("{}", a + b + (c as int))
757760
}
758761
~~~~
759762

@@ -769,7 +772,7 @@ For example:
769772
struct MyTup(int, int, float);
770773
let mytup: MyTup = MyTup(10, 20, 30.0);
771774
match mytup {
772-
MyTup(a, b, c) => info!(a + b + (c as int))
775+
MyTup(a, b, c) => info2!("{}", a + b + (c as int))
773776
}
774777
~~~~
775778

@@ -1238,7 +1241,7 @@ something silly like
12381241
~~~
12391242
# struct Point { x: float, y: float }
12401243
let point = &@~Point { x: 10f, y: 20f };
1241-
println(fmt!("%f", point.x));
1244+
println!("{:f}", point.x);
12421245
~~~
12431246
12441247
The indexing operator (`[]`) also auto-dereferences.
@@ -1443,7 +1446,7 @@ the enclosing scope.
14431446
fn call_closure_with_ten(b: &fn(int)) { b(10); }
14441447
14451448
let captured_var = 20;
1446-
let closure = |arg| println(fmt!("captured_var=%d, arg=%d", captured_var, arg));
1449+
let closure = |arg| println!("captured_var={}, arg={}", captured_var, arg);
14471450
14481451
call_closure_with_ten(closure);
14491452
~~~~
@@ -1566,7 +1569,7 @@ arguments.
15661569
use std::task::spawn;
15671570
15681571
do spawn() || {
1569-
debug!("I'm a task, whatever");
1572+
debug2!("I'm a task, whatever");
15701573
}
15711574
~~~~
15721575

@@ -1578,7 +1581,7 @@ may be omitted from `do` expressions.
15781581
use std::task::spawn;
15791582
15801583
do spawn {
1581-
debug!("Kablam!");
1584+
debug2!("Kablam!");
15821585
}
15831586
~~~~
15841587

@@ -1916,7 +1919,7 @@ and `~str`.
19161919
~~~~
19171920
# trait Printable { fn print(&self); }
19181921
impl Printable for int {
1919-
fn print(&self) { println(fmt!("%d", *self)) }
1922+
fn print(&self) { println!("{}", *self) }
19201923
}
19211924
19221925
impl Printable for ~str {

0 commit comments

Comments
 (0)