Skip to content

Commit 90c071a

Browse files
committed
---
yaml --- r: 153524 b: refs/heads/try2 c: 4418664 h: refs/heads/master v: v3
1 parent 32ad516 commit 90c071a

File tree

233 files changed

+5301
-909
lines changed

Some content is hidden

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

233 files changed

+5301
-909
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 99bd9265d98b74283ee2fa7fa45782e83e5bb79c
8+
refs/heads/try2: 441866417764cb0ad32bce50ebda83deec525997
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ define SREQ_CMDS
377377
ifeq ($$(OSTYPE_$(3)),apple-darwin)
378378
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
379379
else
380-
ifeq ($$(CFG_WINDOWSY_$(2)),1)
380+
ifeq ($$(CFG_WINDOWSY_$(3)),1)
381381
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
382382
else
383383
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH

branches/try2/src/compiletest/compiletest.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::io::fs;
3030
use std::from_str::FromStr;
3131
use getopts::{optopt, optflag, reqopt};
3232
use common::Config;
33-
use common::{Pretty, DebugInfoGdb, Codegen};
33+
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
3434
use util::logv;
3535
use regex::Regex;
3636

@@ -89,9 +89,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
8989
optflag("h", "help", "show this message"));
9090

9191
assert!(!args.is_empty());
92-
let argv0 = (*args.get(0)).clone();
92+
let argv0 = args[0].clone();
9393
let args_ = args.tail();
94-
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
94+
if args[1].as_slice() == "-h" || args[1].as_slice() == "--help" {
9595
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
9696
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
9797
println!("");
@@ -116,7 +116,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
116116
}
117117

118118
let filter = if !matches.free.is_empty() {
119-
let s = matches.free.get(0).as_slice();
119+
let s = matches.free[0].as_slice();
120120
match regex::Regex::new(s) {
121121
Ok(re) => Some(re),
122122
Err(e) => {
@@ -241,6 +241,16 @@ pub fn run_tests(config: &Config) {
241241
os::setenv("RUST_TEST_TASKS","1");
242242
}
243243

244+
match config.mode {
245+
DebugInfoLldb => {
246+
// Some older versions of LLDB seem to have problems with multiple
247+
// instances running in parallel, so only run one test task at a
248+
// time.
249+
os::setenv("RUST_TEST_TASKS", "1");
250+
}
251+
_ => { /* proceed */ }
252+
}
253+
244254
let opts = test_opts(config);
245255
let tests = make_tests(config);
246256
// sadly osx needs some file descriptor limits raised for running tests in

branches/try2/src/compiletest/runtest.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
167167
let proc_res = print_source(config,
168168
props,
169169
testfile,
170-
(*srcs.get(round)).to_string(),
170+
srcs[round].to_string(),
171171
"normal");
172172

173173
if !proc_res.status.success() {
@@ -187,9 +187,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
187187
let s = File::open(&filepath).read_to_end().unwrap();
188188
String::from_utf8(s).unwrap()
189189
}
190-
None => { (*srcs.get(srcs.len() - 2u)).clone() }
190+
None => { srcs[srcs.len() - 2u].clone() }
191191
};
192-
let mut actual = (*srcs.get(srcs.len() - 1u)).clone();
192+
let mut actual = srcs[srcs.len() - 1u].clone();
193193

194194
if props.pp_exact.is_some() {
195195
// Now we have to care about line endings
@@ -209,7 +209,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
209209
if props.no_pretty_expanded { return }
210210

211211
// additionally, run `--pretty expanded` and try to build it.
212-
let proc_res = print_source(config, props, testfile, (*srcs.get(round)).clone(), "expanded");
212+
let proc_res = print_source(config, props, testfile, srcs[round].clone(), "expanded");
213213
if !proc_res.status.success() {
214214
fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
215215
}
@@ -536,6 +536,16 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
536536
// We don't want to hang when calling `quit` while the process is still running
537537
let mut script_str = String::from_str("settings set auto-confirm true\n");
538538

539+
// Make LLDB emit its version, so we have it documented in the test output
540+
script_str.push_str("version\n");
541+
542+
// Switch LLDB into "Rust mode"
543+
script_str.push_str("command script import ./src/etc/lldb_rust_formatters.py\n");
544+
script_str.push_str("type summary add --no-value ");
545+
script_str.push_str("--python-function lldb_rust_formatters.print_val ");
546+
script_str.push_str("-x \".*\" --category Rust\n");
547+
script_str.push_str("type category enable Rust\n");
548+
539549
// Set breakpoints on every line that contains the string "#break"
540550
for line in breakpoint_lines.iter() {
541551
script_str.push_str(format!("breakpoint set --line {}\n",
@@ -692,7 +702,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
692702
let mut rest = line.trim();
693703
let mut first = true;
694704
let mut failed = false;
695-
for frag in check_fragments.get(i).iter() {
705+
for frag in check_fragments[i].iter() {
696706
let found = if first {
697707
if rest.starts_with(frag.as_slice()) {
698708
Some(0)
@@ -742,7 +752,7 @@ fn check_error_patterns(props: &TestProps,
742752
}
743753

744754
let mut next_err_idx = 0u;
745-
let mut next_err_pat = props.error_patterns.get(next_err_idx);
755+
let mut next_err_pat = &props.error_patterns[next_err_idx];
746756
let mut done = false;
747757
let output_to_check = if props.check_stdout {
748758
format!("{}{}", proc_res.stdout, proc_res.stderr)
@@ -751,14 +761,14 @@ fn check_error_patterns(props: &TestProps,
751761
};
752762
for line in output_to_check.as_slice().lines() {
753763
if line.contains(next_err_pat.as_slice()) {
754-
debug!("found error pattern {}", *next_err_pat);
764+
debug!("found error pattern {}", next_err_pat);
755765
next_err_idx += 1u;
756766
if next_err_idx == props.error_patterns.len() {
757767
debug!("found all error patterns");
758768
done = true;
759769
break;
760770
}
761-
next_err_pat = props.error_patterns.get(next_err_idx);
771+
next_err_pat = &props.error_patterns[next_err_idx];
762772
}
763773
}
764774
if done { return; }
@@ -837,13 +847,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
837847
for line in proc_res.stderr.as_slice().lines() {
838848
let mut was_expected = false;
839849
for (i, ee) in expected_errors.iter().enumerate() {
840-
if !*found_flags.get(i) {
850+
if !found_flags[i] {
841851
debug!("prefix={} ee.kind={} ee.msg={} line={}",
842-
prefixes.get(i).as_slice(),
852+
prefixes[i].as_slice(),
843853
ee.kind,
844854
ee.msg,
845855
line);
846-
if prefix_matches(line, prefixes.get(i).as_slice()) &&
856+
if prefix_matches(line, prefixes[i].as_slice()) &&
847857
line.contains(ee.kind.as_slice()) &&
848858
line.contains(ee.msg.as_slice()) {
849859
*found_flags.get_mut(i) = true;
@@ -867,7 +877,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
867877

868878
for (i, &flag) in found_flags.iter().enumerate() {
869879
if !flag {
870-
let ee = expected_errors.get(i);
880+
let ee = &expected_errors[i];
871881
fatal_proc_rec(format!("expected {} on line {} not found: {}",
872882
ee.kind, ee.line, ee.msg).as_slice(),
873883
proc_res);

branches/try2/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/try2/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/try2/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

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

0 commit comments

Comments
 (0)