Skip to content

Commit e656aff

Browse files
committed
Guide: Fix inconsistency in 'Marcos' section
The old version switched in between examples from the value `5i` to `"Hello"` and back. Additionally, the code generated by `rustc print.rs --pretty=expanded` is not as verbose anymore.
1 parent e62ef37 commit e656aff

File tree

1 file changed

+13
-55
lines changed

1 file changed

+13
-55
lines changed

src/doc/guide.md

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5201,8 +5201,8 @@ We can check this out using a special flag to `rustc`. This code, in a file
52015201

52025202
```{rust}
52035203
fn main() {
5204-
let x = "Hello";
5205-
println!("x is: {:s}", x);
5204+
let x = 5i;
5205+
println!("x is: {}", x);
52065206
}
52075207
```
52085208

@@ -5214,32 +5214,19 @@ give us this huge result:
52145214
#![no_std]
52155215
#![feature(globs)]
52165216
#[phase(plugin, link)]
5217-
extern crate std = "std";
5218-
extern crate rt = "native";
5217+
extern crate "std" as std;
5218+
extern crate "native" as rt;
5219+
#[prelude_import]
52195220
use std::prelude::*;
52205221
fn main() {
5221-
let x = "Hello";
5222+
let x = 5i;
52225223
match (&x,) {
52235224
(__arg0,) => {
52245225
#[inline]
52255226
#[allow(dead_code)]
5226-
static __STATIC_FMTSTR: [::std::fmt::rt::Piece<'static>, ..2u] =
5227-
[::std::fmt::rt::String("x is: "),
5228-
::std::fmt::rt::Argument(::std::fmt::rt::Argument{position:
5229-
::std::fmt::rt::ArgumentNext,
5230-
format:
5231-
::std::fmt::rt::FormatSpec{fill:
5232-
' ',
5233-
align:
5234-
::std::fmt::rt::AlignUnknown,
5235-
flags:
5236-
0u,
5237-
precision:
5238-
::std::fmt::rt::CountImplied,
5239-
width:
5240-
::std::fmt::rt::CountImplied,},})];
5227+
static __STATIC_FMTSTR: [&'static str, ..1u] = ["x is: "];
52415228
let __args_vec =
5242-
&[::std::fmt::argument(::std::fmt::secret_string, __arg0)];
5229+
&[::std::fmt::argument(::std::fmt::secret_show, __arg0)];
52435230
let __args =
52445231
unsafe {
52455232
::std::fmt::Arguments::new(__STATIC_FMTSTR, __args_vec)
@@ -5250,45 +5237,16 @@ fn main() {
52505237
}
52515238
```
52525239

5253-
Intense. Here's a trimmed down version that's a bit easier to read:
5254-
5255-
```{rust,ignore}
5256-
fn main() {
5257-
let x = 5i;
5258-
match (&x,) {
5259-
(__arg0,) => {
5260-
static __STATIC_FMTSTR: =
5261-
[String("x is: "),
5262-
Argument(Argument {
5263-
position: ArgumentNext,
5264-
format: FormatSpec {
5265-
fill: ' ',
5266-
align: AlignUnknown,
5267-
flags: 0u,
5268-
precision: CountImplied,
5269-
width: CountImplied,
5270-
},
5271-
},
5272-
];
5273-
let __args_vec = &[argument(secret_string, __arg0)];
5274-
let __args = unsafe { Arguments::new(__STATIC_FMTSTR, __args_vec) };
5275-
5276-
println_args(&__args)
5277-
}
5278-
};
5279-
}
5280-
```
5281-
52825240
Whew! This isn't too terrible. You can see that we still `let x = 5i`,
52835241
but then things get a little bit hairy. Three more bindings get set: a
52845242
static format string, an argument vector, and the arguments. We then
52855243
invoke the `println_args` function with the generated arguments.
52865244

5287-
This is the code (well, the full version) that Rust actually compiles. You can
5288-
see all of the extra information that's here. We get all of the type safety and
5289-
options that it provides, but at compile time, and without needing to type all
5290-
of this out. This is how macros are powerful. Without them, you would need to
5291-
type all of this by hand to get a type checked `println`.
5245+
This is the code that Rust actually compiles. You can see all of the extra
5246+
information that's here. We get all of the type safety and options that it
5247+
provides, but at compile time, and without needing to type all of this out.
5248+
This is how macros are powerful. Without them, you would need to type all of
5249+
this by hand to get a type checked `println`.
52925250

52935251
For more on macros, please consult [the Macros Guide](guide-macros.html).
52945252
Macros are a very advanced and still slightly experimental feature, but don't

0 commit comments

Comments
 (0)