Skip to content

Commit 89a77f5

Browse files
committed
---
yaml --- r: 35555 b: refs/heads/master c: d4daa78 h: refs/heads/master i: 35553: e0a541f 35551: cdd8804 v: v3
1 parent f2678c7 commit 89a77f5

File tree

16 files changed

+455
-178
lines changed

16 files changed

+455
-178
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2f3d4f61817fcfe48c03990f94175258bdbcc0cb
2+
refs/heads/master: d4daa78aa374c3f129e2fbff3ad57484e9d4b8e1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/RELEASES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Version 0.5 (December 2012)
2828
* `use` statements now take crate-relative paths
2929

3030
* Improved support for language features
31-
* Trait inheritance is much more complete
31+
* Trait constraints work in many scenarios
3232
* More support for explicit self arguments in methods - `self`, `&self`
3333
`@self`, and `~self` all generally work as expected
3434
* Static methods work in more situations

trunk/doc/manual.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Display the full TOC */
2+
3+
#TOC ul ul {
4+
display: block;
5+
padding-left: 2em;
6+
}

trunk/doc/rust.md

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -570,53 +570,29 @@ Semantic rules called "dynamic semantics" govern the behavior of programs at run
570570
A program that fails to compile due to violation of a compile-time rule has no defined dynamic semantics; the compiler should halt with an error report, and produce no executable artifact.
571571

572572
The compilation model centres on artifacts called _crates_.
573-
Each compilation processes a single crate in source form, and if successful, produces a single crate in binary form: either an executable or a library.
573+
Each compilation processes a single crate in source form, and if successful, produces a single crate in binary form: either an executable or a library.^[A crate is somewhat
574+
analogous to an *assembly* in the ECMA-335 CLI model, a *library* in the
575+
SML/NJ Compilation Manager, a *unit* in the Owens and Flatt module system,
576+
or a *configuration* in Mesa.]
574577

575578
A _crate_ is a unit of compilation and linking, as well as versioning, distribution and runtime loading.
576579
A crate contains a _tree_ of nested [module](#modules) scopes.
577580
The top level of this tree is a module that is anonymous (from the point of view of paths within the module) and any item within a crate has a canonical [module path](#paths) denoting its location within the crate's module tree.
578581

579-
Crates are provided to the Rust compiler through two kinds of file:
580-
581-
- _crate files_, that end in `.rc` and each define a `crate`.
582-
- _source files_, that end in `.rs` and each define a `module`.
583-
584-
> **Note:** The functionality of crate files will be merged into source files in future versions of Rust.
585-
> The separate processing of crate files, both their grammar and file extension, will be removed.
586-
587-
The Rust compiler is always invoked with a single crate file as input, and always produces a single output crate.
588-
589-
When the Rust compiler is invoked with a crate file, it reads the _explicit_
590-
definition of the crate it's compiling from that file, and populates the
591-
crate with modules derived from all the source files referenced by the
592-
crate, reading and processing all the referenced modules at once.
593-
594-
When the Rust compiler is invoked with a source file, it creates an _implicit_ crate and treats the source file as if it is the sole module populating this explicit crate.
595-
The module name is derived from the source file name, with the `.rs` extension removed.
596-
597-
## Crate files
582+
The Rust compiler is always invoked with a single source file as input, and always produces a single output crate.
583+
The processing of that source file may result in other source files being loaded as modules.
584+
Source files typically have the extension `.rs` but, by convention,
585+
source files that represent crates have the extension `.rc`, called *crate files*.
598586

599-
~~~~~~~~ {.ebnf .gram}
600-
crate : attribute [ ';' | attribute* directive ]
601-
| directive ;
602-
directive : view_item | dir_directive | source_directive ;
603-
~~~~~~~~
604-
605-
A crate file contains a crate definition, for which the production above
606-
defines the grammar. It is a declarative grammar that guides the compiler in
607-
assembling a crate from component source files.^[A crate is somewhat
608-
analogous to an *assembly* in the ECMA-335 CLI model, a *library* in the
609-
SML/NJ Compilation Manager, a *unit* in the Owens and Flatt module system,
610-
or a *configuration* in Mesa.] A crate file describes:
611-
612-
* [Attributes](#attributes) about the crate, such as author, name, version,
613-
and copyright. These are used for linking, versioning and distributing
614-
crates.
615-
* The source-file and directory modules that make up the crate.
616-
* Any `use` or `extern mod` [view items](#view-items) that apply to
617-
the anonymous module at the top-level of the crate's module tree.
587+
A Rust source file describes a module, the name and
588+
location of which -- in the module tree of the current crate -- are defined
589+
from outside the source file: either by an explicit `mod_item` in
590+
a referencing source file, or by the name of the crate ittself.
618591

619-
An example of a crate file:
592+
Each source file contains a sequence of zero or more `item` definitions,
593+
and may optionally begin with any number of `attributes` that apply to the containing module.
594+
Atributes on the anonymous crate module define important metadata that influences
595+
the behavior of the compiler.
620596

621597
~~~~~~~~{.xfail-test}
622598
// Linkage attributes
@@ -629,40 +605,17 @@ An example of a crate file:
629605
license = "BSD" ];
630606
author = "Jane Doe" ];
631607
632-
// Import a module.
633-
extern mod std (ver = "1.0");
608+
// Specify the output type
609+
#[ crate_type = "lib" ];
634610
635-
// Define some modules.
636-
#[path = "foo.rs"]
637-
mod foo;
638-
mod bar {
639-
#[path = "quux.rs"]
640-
mod quux;
641-
}
611+
// Turn on a warning
612+
#[ warn(non_camel_case_types) ];
642613
~~~~~~~~
643614

644-
### Dir directives
645-
646-
A `dir_directive` forms a module in the module tree making up the crate, as
647-
well as implicitly relating that module to a directory in the filesystem
648-
containing source files and/or further subdirectories. The filesystem
649-
directory associated with a `dir_directive` module can either be explicit,
650-
or if omitted, is implicitly the same name as the module.
651-
652-
A `source_directive` references a source file, either explicitly or implicitly, by combining the module name with the file extension `.rs`.
653-
The module contained in that source file is bound to the module path formed by the `dir_directive` modules containing the `source_directive`.
654-
655-
## Source files
656-
657-
A source file contains a `module`: that is, a sequence of zero or more
658-
`item` definitions. Each source file is an implicit module, the name and
659-
location of which -- in the module tree of the current crate -- is defined
660-
from outside the source file: either by an explicit `source_directive` in
661-
a referencing crate file, or by the filename of the source file itself.
662-
663-
A source file that contains a `main` function can be compiled to an executable.
615+
A crate that contains a `main` function can be compiled to an executable.
664616
If a `main` function is present, its return type must be [`unit`](#primitive-types) and it must take no arguments.
665617

618+
666619
# Items and attributes
667620

668621
Crates contain [items](#items),
@@ -719,7 +672,7 @@ That is, Rust has no notion of type abstraction: there are no first-class "foral
719672
### Modules
720673

721674
~~~~~~~~ {.ebnf .gram}
722-
mod_item : "mod" ident '{' mod '}' ;
675+
mod_item : "mod" ident ( ';' | '{' mod '}' );
723676
mod : [ view_item | item ] * ;
724677
~~~~~~~~
725678

@@ -757,6 +710,33 @@ Declaring a named type that has the same name as a module in scope is forbidden:
757710
that is, a type definition, trait, struct, enumeration, or type parameter
758711
can't shadow the name of a module in scope, or vice versa.
759712

713+
A module without a body is loaded from an external file, by default with the same
714+
name as the module, plus the `.rs` extension.
715+
When a nested submodule is loaded from an external file,
716+
it is loaded from a subdirectory path that mirrors the module hierarchy.
717+
718+
~~~ {.xfail-test}
719+
// Load the `vec` module from `vec.rs`
720+
mod vec;
721+
722+
mod task {
723+
// Load the `local_data` module from `task/local_data.rs`
724+
mod local_data;
725+
}
726+
~~~
727+
728+
The directories and files used for loading external file modules can be influenced
729+
with the `path` attribute.
730+
731+
~~~ {.xfail-test}
732+
#[path = "task_files"]
733+
mod task {
734+
// Load the `local_data` module from `task_files/tls.rs`
735+
#[path = "tls.rs"]
736+
mod local_data;
737+
}
738+
~~~
739+
760740
#### View items
761741

762742
~~~~~~~~ {.ebnf .gram}

trunk/doc/tutorial.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,22 +2252,46 @@ The unit of independent compilation in Rust is the crate: rustc
22522252
compiles a single crate at a time, from which it produces either a
22532253
library or executable.
22542254

2255-
When compiling a single `.rs` file, the file acts as the whole crate.
2255+
When compiling a single `.rs` source file, the file acts as the whole crate.
22562256
You can compile it with the `--lib` compiler switch to create a shared
22572257
library, or without, provided that your file contains a `fn main`
22582258
somewhere, to create an executable.
22592259

2260-
Larger crates typically span multiple files and are compiled from
2261-
a crate (.rc) file. Crate files contain their own syntax for loading
2262-
modules from .rs files and typically include metadata about the crate.
2260+
Larger crates typically span multiple files and are, by convention,
2261+
compiled from a source file with the `.rc` extension, called a *crate file*.
2262+
The crate file extension distinguishes source files that represent
2263+
crates from those that do not, but otherwise source files and crate files are identical.
2264+
2265+
A typical crate file declares attributes associated with the crate that
2266+
may affect how the compiler processes the source.
2267+
Crate attributes specify metadata used for locating and linking crates,
2268+
the type of crate (library or executable),
2269+
and control warning and error behavior,
2270+
among other things.
2271+
Crate files additionally declare the external crates they depend on
2272+
as well as any modules loaded from other files.
22632273

22642274
~~~~ { .xfail-test }
2275+
// Crate linkage metadata
22652276
#[link(name = "farm", vers = "2.5", author = "mjh")];
2277+
2278+
// Make a library ("bin" is the default)
22662279
#[crate_type = "lib"];
22672280
2281+
// Turn on a warning
2282+
#[warn(non_camel_case_types)]
2283+
2284+
// Link to the standard library
2285+
extern mod std;
2286+
2287+
// Load some modules from other files
22682288
mod cow;
22692289
mod chicken;
22702290
mod horse;
2291+
2292+
fn main() {
2293+
...
2294+
}
22712295
~~~~
22722296

22732297
Compiling this file will cause `rustc` to look for files named
@@ -2282,7 +2306,7 @@ module, which other crates can use to load the right module. More
22822306
about that later.
22832307

22842308
To have a nested directory structure for your source files, you can
2285-
nest mods in your `.rc` file:
2309+
nest mods:
22862310

22872311
~~~~ {.ignore}
22882312
mod poultry {
@@ -2296,30 +2320,6 @@ The compiler will now look for `poultry/chicken.rs` and
22962320
and `poultry::turkey`. You can also provide a `poultry.rs` to add
22972321
content to the `poultry` module itself.
22982322

2299-
When compiling .rc files, if rustc finds a .rs file with the same
2300-
name, then that .rs file provides the top-level content of the crate.
2301-
2302-
~~~ {.xfail-test}
2303-
// foo.rc
2304-
#[link(name = "foo", vers="1.0")];
2305-
2306-
mod bar;
2307-
~~~
2308-
2309-
~~~ {.xfail-test}
2310-
// foo.rs
2311-
fn main() { bar::baz(); }
2312-
~~~
2313-
2314-
> ***Note***: The way rustc looks for .rs files to pair with .rc
2315-
> files is a major source of confusion and will change. It's likely
2316-
> that the crate and source file grammars will merge.
2317-
2318-
> ***Note***: The way that directory modules are handled will also
2319-
> change. The code for directory modules currently lives in a .rs
2320-
> file with the same name as the directory, _next to_ the directory.
2321-
> A new scheme will make that file live _inside_ the directory.
2322-
23232323
## Using other crates
23242324

23252325
The `extern mod` directive lets you use a crate (once it's been

trunk/mk/docs.mk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ doc/rust.css: rust.css
3030
@$(call E, cp: $@)
3131
$(Q)cp -a $< $@ 2> /dev/null
3232

33+
doc/manual.css: manual.css
34+
@$(call E, cp: $@)
35+
$(Q)cp -a $< $@ 2> /dev/null
36+
3337
DOCS += doc/rust.html
34-
doc/rust.html: rust.md doc/version_info.html doc/rust.css
38+
doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css
3539
@$(call E, pandoc: $@)
3640
$(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
3741
"$(CFG_PANDOC)" \
@@ -40,6 +44,7 @@ doc/rust.html: rust.md doc/version_info.html doc/rust.css
4044
--number-sections \
4145
--from=markdown --to=html \
4246
--css=rust.css \
47+
--css=manual.css \
4348
--include-before-body=doc/version_info.html \
4449
--output=$@
4550
endif

trunk/src/libcore/uint-template.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
179179
f: fn(v: &[u8]) -> U) -> U {
180180

181181
#[inline(always)]
182-
pure fn digit(n: T) -> u8 {
182+
fn digit(n: T) -> u8 {
183183
if n <= 9u as T {
184184
n as u8 + '0' as u8
185185
} else if n <= 15u as T {
@@ -195,27 +195,35 @@ pub pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
195195
// Worst case: 64-bit number, binary-radix, with
196196
// a leading negative sign = 65 bytes.
197197
let buf : [mut u8 * 65] = [mut 0u8, ..65];
198-
let len = buf.len();
199198

200-
let mut i = len;
201-
let mut n = num;
202-
let radix = radix as T;
203-
loop {
204-
i -= 1u;
205-
assert 0u < i && i < len;
206-
buf[i] = digit(n % radix);
207-
n /= radix;
208-
if n == 0 as T { break; }
209-
}
210-
211-
assert 0u < i && i < len;
212-
213-
if neg {
214-
i -= 1u;
215-
buf[i] = '-' as u8;
199+
// FIXME (#2649): post-snapshot, you can do this without the raw
200+
// pointers and unsafe bits, and the codegen will prove it's all
201+
// in-bounds, no extra cost.
202+
203+
unsafe {
204+
do vec::as_imm_buf(buf) |p, len| {
205+
let mp = p as *mut u8;
206+
let mut i = len;
207+
let mut n = num;
208+
let radix = radix as T;
209+
loop {
210+
i -= 1u;
211+
assert 0u < i && i < len;
212+
*ptr::mut_offset(mp, i) = digit(n % radix);
213+
n /= radix;
214+
if n == 0 as T { break; }
215+
}
216+
217+
assert 0u < i && i < len;
218+
219+
if neg {
220+
i -= 1u;
221+
*ptr::mut_offset(mp, i) = '-' as u8;
222+
}
223+
224+
vec::raw::buf_as_slice(ptr::offset(p, i), len - i, f)
225+
}
216226
}
217-
218-
f(vec::view(buf, i, len))
219227
}
220228

221229
/// Convert to a string

0 commit comments

Comments
 (0)