Skip to content

Commit 9659b3e

Browse files
committed
---
yaml --- r: 125803 b: refs/heads/try c: 826b835 h: refs/heads/master i: 125801: b8ee334 125799: 9c33a74 v: v3
1 parent f78b24e commit 9659b3e

File tree

379 files changed

+9330
-3005
lines changed

Some content is hidden

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

379 files changed

+9330
-3005
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: f2fa55903e378368ed9173560f03a0ef16e371c2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 9fc8394d3bce22ab483f98842434c84c396212ae
5-
refs/heads/try: 4a00d4e676d3333db77db6f08d5570b0d500b9cc
5+
refs/heads/try: 826b8358134f909f0b8aeb4c1d67a3fdda50b4b0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
216216
$(findstring tidy,$(MAKECMDGOALS))),)
217217
CFG_INFO := $(info cfg: including test rules)
218218
include $(CFG_SRC_DIR)mk/tests.mk
219+
include $(CFG_SRC_DIR)mk/grammar.mk
219220
endif
220221

221222
# Performance and benchmarking

branches/try/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ probe CFG_VALGRIND valgrind
493493
probe CFG_PERF perf
494494
probe CFG_ISCC iscc
495495
probe CFG_LLNEXTGEN LLnextgen
496+
probe CFG_JAVAC javac
497+
probe CFG_ANTLR4 antlr4
498+
probe CFG_GRUN grun
496499
probe CFG_PANDOC pandoc
497500
probe CFG_PDFLATEX pdflatex
498501
probe CFG_XELATEX xelatex

branches/try/man/rustc.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ AST nodes and blocks with IDs), or flowgraph=<nodeid> (graphviz
6868
formatted flowgraph for node)
6969
.TP
7070
\fB\-\-dep-info\fR [FILENAME]
71-
Output dependency info to <filename> after compiling, in o format suitable
71+
Output dependency info to <filename> after compiling, in a format suitable
7272
for use by Makefiles.
7373
.TP
7474
\fB\-\-sysroot\fR PATH

branches/try/mk/docs.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DOCS := index intro tutorial guide guide-ffi guide-macros guide-lifetimes \
3030
guide-tasks guide-container guide-pointers guide-testing \
3131
guide-runtime complement-bugreport \
3232
complement-lang-faq complement-design-faq complement-project-faq rust \
33-
rustdoc guide-unsafe
33+
rustdoc guide-unsafe guide-strings
3434

3535
PDF_DOCS := tutorial rust
3636

@@ -112,8 +112,8 @@ HTML_DEPS += doc/version_info.html
112112
doc/version_info.html: $(D)/version_info.html.template $(MKFILE_DEPS) \
113113
$(wildcard $(D)/*.*) | doc/
114114
@$(call E, version-info: $@)
115-
$(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
116-
$(CFG_VER_HASH) | head -c 8)/;\
115+
$(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(\
116+
CFG_SHORT_VER_HASH)/;\
117117
s/STAMP/$(CFG_VER_HASH)/;" $< >$@
118118

119119
GENERATED += doc/version.tex doc/version_info.html

branches/try/mk/grammar.mk

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
BG = $(CFG_BUILD_DIR)/grammar/
12+
SG = $(S)src/grammar/
13+
B = $(CFG_BUILD_DIR)/$(CFG_BUILD)/stage2/
14+
L = $(B)lib/rustlib/$(CFG_BUILD)/lib
15+
LD = $(CFG_BUILD)/stage2/lib/rustlib/$(CFG_BUILD)/lib/
16+
RUSTC = $(B)bin/rustc
17+
18+
# Run the reference lexer against libsyntax and compare the tokens and spans.
19+
# If "// ignore-lexer-test" is present in the file, it will be ignored.
20+
#
21+
# $(1) is the file to test.
22+
define LEXER_TEST
23+
grep "// ignore-lexer-test" $(1) ; \
24+
if [ $$? -eq 1 ]; then \
25+
CLASSPATH=$(B)grammar $(CFG_GRUN) RustLexer tokens -tokens < $(1) \
26+
| $(B)grammar/verify $(1) ; \
27+
fi
28+
endef
29+
30+
$(BG):
31+
$(Q)mkdir -p $(BG)
32+
33+
$(BG)RustLexer.class: $(SG)RustLexer.g4
34+
$(Q)$(CFG_ANTLR4) -o $(B)grammar $(SG)RustLexer.g4
35+
$(Q)$(CFG_JAVAC) -d $(BG) $(BG)RustLexer.java
36+
37+
$(BG)verify: $(SG)verify.rs rustc-stage2-H-$(CFG_BUILD) $(LD)stamp.regex_macros $(LD)stamp.rustc
38+
$(Q)$(RUSTC) -O --out-dir $(BG) -L $(L) $(SG)verify.rs
39+
40+
check-lexer: $(BG) $(BG)RustLexer.class $(BG)verify
41+
ifdef CFG_JAVAC
42+
ifdef CFG_ANTLR4
43+
ifdef CFG_GRUN
44+
$(info Verifying libsyntax against the reference lexer ...)
45+
$(Q)$(SG)check.sh $(S) "$(BG)" \
46+
"$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens"
47+
else
48+
$(info grun not available, skipping lexer test...)
49+
endif
50+
else
51+
$(info antlr4 not available, skipping lexer test...)
52+
endif
53+
else
54+
$(info javac not available, skipping lexer test...)
55+
endif

branches/try/mk/main.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT))),)
4646
ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
4747
CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
4848
CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
49-
CFG_VERSION += ($(CFG_VER_HASH) $(CFG_VER_DATE))
49+
CFG_SHORT_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse --short=9 HEAD)
50+
CFG_VERSION += ($(CFG_SHORT_VER_HASH) $(CFG_VER_DATE))
5051
endif
5152
endif
5253

branches/try/mk/tests.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
192192
# NOTE: Remove after reprogramming windows bots
193193
check-fast: check-lite
194194

195+
check-syntax: check-lexer
196+
195197
.PHONY: cleantmptestlogs cleantestlibs
196198

197199
cleantmptestlogs:

branches/try/src/doc/complement-lang-faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ You may also be interested in browsing [GitHub's Rust][github-rust] page.
3131

3232
## Does it run on Windows?
3333

34-
Yes. All development happens in lock-step on all 3 target platforms. Using MinGW, not Cygwin. Note that the windows implementation currently has some limitations: in particular 64-bit build is [not fully supported yet][win64], and all executables created by rustc [depends on libgcc DLL at runtime][libgcc].
34+
Yes. All development happens in lock-step on all 3 target platforms. Using MinGW, not Cygwin. Note that the windows implementation currently has some limitations: in particular 64-bit build is [not fully supported yet][win64], and all executables created by rustc [depend on libgcc DLL at runtime][libgcc].
3535

3636
[win64]: https://github.com/rust-lang/rust/issues/1237
3737
[libgcc]: https://github.com/rust-lang/rust/issues/11782
@@ -68,7 +68,7 @@ Cleanup through RAII-style destructors is more likely to work than in catch bloc
6868

6969
## Why aren't modules type-parametric?
7070

71-
We want to maintain the option to parametrize at runtime. We may make eventually change this limitation, but initially this is how type parameters were implemented.
71+
We want to maintain the option to parametrize at runtime. We may eventually change this limitation, but initially this is how type parameters were implemented.
7272

7373
## Why aren't values type-parametric? Why only items?
7474

branches/try/src/doc/guide-lifetimes.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Now we can call `compute_distance()`:
6767
# let on_the_stack : Point = Point{x: 3.0, y: 4.0};
6868
# let on_the_heap : Box<Point> = box Point{x: 7.0, y: 9.0};
6969
# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
70-
compute_distance(&on_the_stack, on_the_heap);
70+
compute_distance(&on_the_stack, &*on_the_heap);
7171
~~~
7272

7373
Here, the `&` operator takes the address of the variable
@@ -77,10 +77,9 @@ value. We also call this _borrowing_ the local variable
7777
`on_the_stack`, because we have created an alias: that is, another
7878
name for the same data.
7979

80-
In the case of `on_the_heap`, however, no explicit action is necessary.
81-
The compiler will automatically convert a box point to a reference like &point.
82-
This is another form of borrowing; in this case, the contents of the owned box
83-
are being lent out.
80+
Likewise, in the case of `owned_box`,
81+
the `&` operator is used in conjunction with the `*` operator
82+
to take a reference to the contents of the box.
8483

8584
Whenever a caller lends data to a callee, there are some limitations on what
8685
the caller can do with the original. For example, if the contents of a

branches/try/src/doc/guide-pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn main() {
279279
let origin = &Point { x: 0.0, y: 0.0 };
280280
let p1 = box Point { x: 5.0, y: 3.0 };
281281

282-
println!("{}", compute_distance(origin, p1));
282+
println!("{}", compute_distance(origin, &*p1));
283283
}
284284
~~~
285285

branches/try/src/doc/guide-strings.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
% The Strings Guide
2+
3+
Strings are an important concept to master in any programming language. If you
4+
come from a managed language background, you may be surprised at the complexity
5+
of string handling in a systems programming language. Efficient access and
6+
allocation of memory for a dynamically sized structure involves a lot of
7+
details. Luckily, Rust has lots of tools to help us here.
8+
9+
A **string** is a sequence of unicode scalar values encoded as a stream of
10+
UTF-8 bytes. All strings are guaranteed to be validly-encoded UTF-8 sequences.
11+
Additionally, strings are not null-terminated and can contain null bytes.
12+
13+
Rust has two main types of strings: `&str` and `String`.
14+
15+
# &str
16+
17+
The first kind is a `&str`. This is pronounced a 'string slice.' String literals
18+
are of the type `&str`:
19+
20+
```{rust}
21+
let string = "Hello there.";
22+
```
23+
24+
Like any Rust type, string slices have an associated lifetime. A string literal
25+
is a `&'static str`. A string slice can be written without an explicit
26+
lifetime in many cases, such as in function arguments. In these cases the
27+
lifetime will be inferred:
28+
29+
```{rust}
30+
fn takes_slice(slice: &str) {
31+
println!("Got: {}", slice);
32+
}
33+
```
34+
35+
Like vector slices, string slices are simply a pointer plus a length. This
36+
means that they're a 'view' into an already-allocated string, such as a
37+
`&'static str` or a `String`.
38+
39+
# String
40+
41+
A `String` is a heap-allocated string. This string is growable, and is also
42+
guaranteed to be UTF-8.
43+
44+
```{rust}
45+
let mut s = "Hello".to_string();
46+
println!("{}", s);
47+
48+
s.push_str(", world.");
49+
println!("{}", s);
50+
```
51+
52+
You can coerce a `String` into a `&str` with the `as_slice()` method:
53+
54+
```{rust}
55+
fn takes_slice(slice: &str) {
56+
println!("Got: {}", slice);
57+
}
58+
59+
fn main() {
60+
let s = "Hello".to_string();
61+
takes_slice(s.as_slice());
62+
}
63+
```
64+
65+
You can also get a `&str` from a stack-allocated array of bytes:
66+
67+
```{rust}
68+
use std::str;
69+
70+
let x: &[u8] = &[b'a', b'b'];
71+
let stack_str: &str = str::from_utf8(x).unwrap();
72+
```
73+
74+
# Best Practices
75+
76+
## `String` vs. `&str`
77+
78+
In general, you should prefer `String` when you need ownership, and `&str` when
79+
you just need to borrow a string. This is very similar to using `Vec<T>` vs. `&[T]`,
80+
and `T` vs `&T` in general.
81+
82+
This means starting off with this:
83+
84+
```{rust,ignore}
85+
fn foo(s: &str) {
86+
```
87+
88+
and only moving to this:
89+
90+
```{rust,ignore}
91+
fn foo(s: String) {
92+
```
93+
94+
If you have good reason. It's not polite to hold on to ownership you don't
95+
need, and it can make your lifetimes more complex. Furthermore, you can pass
96+
either kind of string into `foo` by using `.as_slice()` on any `String` you
97+
need to pass in, so the `&str` version is more flexible.
98+
99+
## Comparisons
100+
101+
To compare a String to a constant string, prefer `as_slice()`...
102+
103+
```{rust}
104+
fn compare(string: String) {
105+
if string.as_slice() == "Hello" {
106+
println!("yes");
107+
}
108+
}
109+
```
110+
111+
... over `to_string()`:
112+
113+
```{rust}
114+
fn compare(string: String) {
115+
if string == "Hello".to_string() {
116+
println!("yes");
117+
}
118+
}
119+
```
120+
121+
Converting a `String` to a `&str` is cheap, but converting the `&str` to a
122+
`String` involves an allocation.
123+
124+
# Other Documentation
125+
126+
* [the `&str` API documentation](/std/str/index.html)
127+
* [the `String` API documentation](std/string/index.html)

0 commit comments

Comments
 (0)